Commit e2540fc7 authored by James Larrowe's avatar James Larrowe Committed by Ed Reel

Update install.sh (#3088)

quote variables,
respect spaces in install names,
respect choice of branch,
fix logic,
suggest simpler user-friendly editor,
and exit on failure
parent be700f3f
#!/bin/bash
# exit on fail
set -e
#chromebrew directories #chromebrew directories
OWNER="skycocker" OWNER="skycocker"
REPO="chromebrew" REPO="chromebrew"
BRANCH="master" BRANCH="master"
URL="https://raw.githubusercontent.com/$OWNER/$REPO/$BRANCH" URL="https://raw.githubusercontent.com/${OWNER}/${REPO}/${BRANCH}"
CREW_PREFIX=${CREW_PREFIX:-/usr/local} CREW_PREFIX="${CREW_PREFIX:-/usr/local}"
CREW_LIB_PATH=$CREW_PREFIX/lib/crew/ CREW_LIB_PATH="${CREW_PREFIX}/lib/crew/"
CREW_CONFIG_PATH=$CREW_PREFIX/etc/crew/ CREW_CONFIG_PATH="${CREW_PREFIX}/etc/crew/"
CREW_BREW_DIR=$CREW_PREFIX/tmp/crew/ CREW_BREW_DIR="${CREW_PREFIX}/tmp/crew/"
CREW_DEST_DIR=$CREW_BREW_DIR/dest CREW_DEST_DIR="${CREW_BREW_DIR}/dest"
CREW_PACKAGES_PATH=$CREW_LIB_PATH/packages CREW_PACKAGES_PATH="${CREW_LIB_PATH}/packages"
architecture=$(uname -m) ARCH="$(uname -m)"
if [ $EUID -eq 0 ]; then if [ "${EUID}" == "0" ]; then
echo 'Chromebrew should not be run as root.' echo 'Chromebrew should not be installed or run as root.'
exit 1; exit 1;
fi fi
case "$architecture" in case "${ARCH}" in
"i686"|"x86_64"|"armv7l"|"aarch64") "i686"|"x86_64"|"armv7l"|"aarch64")
LIB_SUFFIX=
[ "${ARCH}" == "x86_64" ] && LIB_SUFFIX='64'
;; ;;
*) *)
echo 'Your device is not supported by Chromebrew yet.' echo 'Your device is not supported by Chromebrew yet.'
...@@ -26,18 +33,20 @@ case "$architecture" in ...@@ -26,18 +33,20 @@ case "$architecture" in
esac esac
# This will allow things to work without sudo # This will allow things to work without sudo
sudo chown -R `id -u`:`id -g` "${CREW_PREFIX}" sudo chown -R "$(id -u)":"$(id -g)" "${CREW_PREFIX}"
# prepare directories # prepare directories
for dir in $CREW_LIB_PATH $CREW_CONFIG_PATH $CREW_CONFIG_PATH/meta $CREW_BREW_DIR $CREW_DEST_DIR $CREW_PACKAGES_PATH; do for dir in "${CREW_CONFIG_PATH}/meta" "${CREW_DEST_DIR}" "${CREW_PACKAGES_PATH}"; do
mkdir -p $dir if [ ! -d "${dir}" ]; then
mkdir -p "${dir}"
fi
done done
# prepare url and sha256 # prepare url and sha256
# install only gcc7, ruby, libiconv, git and libssh2 (order matters) # install only gcc7, ruby, libiconv, git and libssh2 (order matters)
urls=() urls=()
sha256s=() sha256s=()
case "$architecture" in case "${ARCH}" in
"aarch64") "aarch64")
urls+=('https://dl.bintray.com/chromebrew/chromebrew/gcc7-7.3.0-3-chromeos-armv7l.tar.xz') urls+=('https://dl.bintray.com/chromebrew/chromebrew/gcc7-7.3.0-3-chromeos-armv7l.tar.xz')
sha256s+=('c9dd2a2b2d195f0f2021dc673d6317e46b5dfaef582f496b4cea1f3c5c2c17ad') sha256s+=('c9dd2a2b2d195f0f2021dc673d6317e46b5dfaef582f496b4cea1f3c5c2c17ad')
...@@ -94,133 +103,128 @@ esac ...@@ -94,133 +103,128 @@ esac
# functions to maintain packages # functions to maintain packages
function download_check () { function download_check () {
cd $CREW_BREW_DIR cd "${CREW_BREW_DIR}"
#download #download
echo "Downloading $1..." echo "Downloading ${1}..."
curl --progress-bar -C - -# -L --ssl $2 -o "$3" curl --progress-bar -C - -L --ssl "${2}" -o "${3}"
#verify #verify
echo "Verifying $1..." echo "Verifying ${1}..."
echo $4 $3 | sha256sum -c - echo "${4}" "${3}" | sha256sum -c -
case $? in case "${?}" in
0) ;; 0) ;;
*) *)
echo "Verification failed, something may be wrong with the $1 download." echo "Verification failed, something may be wrong with the download."
exit 1;; exit 1;;
esac esac
} }
function extract_install () { function extract_install () {
cd $CREW_BREW_DIR # Start with a clean slate
rm -rf "${CREW_DEST_DIR}"
mkdir "${CREW_DEST_DIR}"
cd "${CREW_DEST_DIR}"
#extract and install #extract and install
echo "Extracting $1 (this may take a while)..." echo "Extracting ${1} (this may take a while)..."
rm -rf ./usr ./home tar xpf ../"${2}"
tar -xf $2 echo "Installing ${1} (this may take a while)..."
echo "Installing $1 (this may take a while)..." tar cpf - ./*/* | (cd /; tar xp --keep-directory-symlink -f -)
if [ -d "${CREW_BREW_DIR}/home" ]; then mv ./dlist "${CREW_CONFIG_PATH}/meta/${1}.directorylist"
tar cf - ./usr/* ./home/* | (cd /; tar xp --keep-directory-symlink -f -) mv ./filelist "${CREW_CONFIG_PATH}/meta/${1}.filelist"
else
tar cf - ./usr/* | (cd /; tar xp --keep-directory-symlink -f -)
fi
mv ./dlist $CREW_CONFIG_PATH/meta/$1.directorylist
mv ./filelist $CREW_CONFIG_PATH/meta/$1.filelist
} }
function update_device_json () { function update_device_json () {
cd $CREW_CONFIG_PATH cd "${CREW_CONFIG_PATH}"
if grep '"name": "'$1'"' device.json > /dev/null; then if grep '"name": "'"${1}"'"' device.json > /dev/null; then
echo "Updating version number of existing $1 information in device.json..." echo "Updating version number of ${1} in device.json..."
sed -i device.json -e '/"name": "'$1'"/N;//s/"version": ".*"/"version": "'$2'"/' sed -i device.json -e '/"name": "'"${1}"'"/N;//s/"version": ".*"/"version": "'"${2}"'"/'
elif grep '^ }$' device.json > /dev/null; then elif grep '^ }$' device.json > /dev/null; then
echo "Adding new $1 information to device.json..." echo "Adding new information on ${1} to device.json..."
sed -i device.json -e '/^ }$/s/$/,\ sed -i device.json -e '/^ }$/s/$/,\
{\ {\
"name": "'$1'",\ "name": "'"${1}"'",\
"version": "'$2'"\ "version": "'"${2}"'"\
}/' }/'
else else
echo "Adding new $1 information to device.json..." echo "Adding new information on ${1} to device.json..."
sed -i device.json -e '/^ "installed_packages": \[$/s/$/\ sed -i device.json -e '/^ "installed_packages": \[$/s/$/\
{\ {\
"name": "'$1'",\ "name": "'"${1}"'",\
"version": "'$2'"\ "version": "'"${2}"'"\
}/' }/'
fi fi
} }
# create the device.json file if it doesn't exist # create the device.json file if it doesn't exist
cd $CREW_CONFIG_PATH cd "${CREW_CONFIG_PATH}"
if [ ! -f device.json ]; then if [ ! -f device.json ]; then
echo "Creating new device.json..." echo "Creating new device.json..."
echo '{' > device.json echo '{' > device.json
echo ' "architecture": "'$architecture'",' >> device.json echo ' "architecture": "'"${ARCH}"'",' >> device.json
echo ' "installed_packages": [' >> device.json echo ' "installed_packages": [' >> device.json
echo ' ]' >> device.json echo ' ]' >> device.json
echo '}' >> device.json echo '}' >> device.json
fi fi
# extract, install and register packages # extract, install and register packages
for i in `seq 0 $((${#urls[@]} - 1))`; do for i in $(seq 0 $((${#urls[@]} - 1))); do
url=${urls[$i]} url="${urls["${i}"]}"
sha256=${sha256s[$i]} sha256="${sha256s["${i}"]}"
tarfile=`basename $url` tarfile="$(basename ${url})"
name=${tarfile%%-*} # extract string before first '-' name="${tarfile%%-*}" # extract string before first '-'
rest=${tarfile#*-} # extract string after first '-' rest="${tarfile#*-}" # extract string after first '-'
version=`echo $rest | sed -e 's/-chromeos.*$//'` version="$(echo ${rest} | sed -e 's/-chromeos.*$//')"
# extract string between first '-' and "-chromeos" # extract string between first '-' and "-chromeos"
download_check $name $url $tarfile $sha256 download_check "${name}" "${url}" "${tarfile}" "${sha256}"
extract_install $name $tarfile extract_install "${name}" "${tarfile}"
update_device_json $name $version update_device_json "${name}" "${version}"
done done
# download, prepare and install chromebrew # create symlink to 'crew' in ${CREW_PREFIX}/bin/
cd $CREW_LIB_PATH rm -f "${CREW_PREFIX}/bin/crew"
rm -rf crew lib packages ln -s "../lib/crew/crew" "${CREW_PREFIX}/bin/"
curl -# -o crew $URL/crew
chmod +x crew
rm -f $CREW_PREFIX/bin/crew
ln -s `pwd`/crew $CREW_PREFIX/bin
#install crew library
mkdir -p $CREW_LIB_PATH/lib
cd $CREW_LIB_PATH/lib
curl -# -o package.rb $URL/lib/package.rb
curl -# -o package_helpers.rb $URL/lib/package_helpers.rb
# Making GCC act like CC (For some npm packages out there, only required for gcc)
#rm -f $CREW_PREFIX/bin/cc
#ln -s $CREW_PREFIX/bin/gcc $CREW_PREFIX/bin/cc
# package gcc7 has already made symbolic links for cc and gcc, no action required here
# prepare sparse checkout .rb packages directory and do it # prepare sparse checkout .rb packages directory and do it
cd $CREW_LIB_PATH cd "${CREW_LIB_PATH}"
rm -rf .git rm -rf .git
git init git init
git remote add -f origin https://github.com/$OWNER/$REPO.git git remote add -f origin "https://github.com/${OWNER}/${REPO}.git"
git config core.sparsecheckout true git config core.sparsecheckout true
echo packages >> .git/info/sparse-checkout echo packages >> .git/info/sparse-checkout
echo lib >> .git/info/sparse-checkout echo lib >> .git/info/sparse-checkout
echo crew >> .git/info/sparse-checkout echo crew >> .git/info/sparse-checkout
git fetch origin master git fetch origin "${BRANCH}"
git reset --hard origin/master git reset --hard origin/"${BRANCH}"
# install a base set of essential packages # install a base set of essential packages
yes | crew install buildessential less most yes | crew install buildessential less most
echo echo
if [[ "${CREW_PREFIX}" != "/usr/local" ]]; then
echo "Since you have installed Chromebrew in a directory other than '/usr/local',"
echo "you need to run these commands to complete your installation:"
echo "echo 'export CREW_PREFIX=${CREW_PREFIX}' >> ~/.bashrc"
echo "echo 'export PATH=\"\${CREW_PREFIX}/bin:\${CREW_PREFIX}/sbin:\${PATH}\"' >> ~/.bashrc"
echo "echo 'export LD_LIBRARY_PATH=${CREW_PREFIX}/lib${LIB_SUFFIX}' >> ~/.bashrc"
echo 'source ~/.bashrc'
echo
fi
echo "To set the default PAGER environment variable to be able to use less:" echo "To set the default PAGER environment variable to be able to use less:"
echo "echo \"export PAGER=$CREW_PREFIX/bin/less\" >> ~/.bashrc && . ~/.bashrc" echo "echo \"export PAGER='less'\" >> ~/.bashrc && . ~/.bashrc"
echo echo
echo "Alternatively, you could use most. Why settle for less, right?" echo "Alternatively, you could use most. Why settle for less, right?"
echo "echo \"export PAGER=$CREW_PREFIX/bin/most\" >> ~/.bashrc && . ~/.bashrc" echo "echo \"export PAGER='most'\" >> ~/.bashrc && . ~/.bashrc"
echo echo
echo "You may wish to set the default EDITOR. The current EDITOR is '$EDITOR'." echo "You may wish to set the EDITOR environment variable."
echo "For example, to set vim as the default editor, execute the following:" echo "For example, to set 'vim' as the default editor, execute the following:"
echo "echo \"export EDITOR=$CREW_PREFIX/bin/vim\" >> ~/.bashrc && . ~/.bashrc" echo "echo \"export EDITOR='vim'\" >> ~/.bashrc && . ~/.bashrc"
echo "To install the vim editor, run 'crew install vim'" echo "Nano is a simple text editor that is the default on Chrome OS,"
echo " and is recommended."
echo "To install 'nano', run 'crew install nano'."
echo "Or, to get an updated version of 'vim', run 'crew install vim'."
echo echo
echo "Chromebrew installed successfully and package lists updated." echo "Chromebrew installed successfully and package lists updated."
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment