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
OWNER="skycocker"
REPO="chromebrew"
BRANCH="master"
URL="https://raw.githubusercontent.com/$OWNER/$REPO/$BRANCH"
CREW_PREFIX=${CREW_PREFIX:-/usr/local}
CREW_LIB_PATH=$CREW_PREFIX/lib/crew/
CREW_CONFIG_PATH=$CREW_PREFIX/etc/crew/
CREW_BREW_DIR=$CREW_PREFIX/tmp/crew/
CREW_DEST_DIR=$CREW_BREW_DIR/dest
CREW_PACKAGES_PATH=$CREW_LIB_PATH/packages
architecture=$(uname -m)
if [ $EUID -eq 0 ]; then
echo 'Chromebrew should not be run as root.'
URL="https://raw.githubusercontent.com/${OWNER}/${REPO}/${BRANCH}"
CREW_PREFIX="${CREW_PREFIX:-/usr/local}"
CREW_LIB_PATH="${CREW_PREFIX}/lib/crew/"
CREW_CONFIG_PATH="${CREW_PREFIX}/etc/crew/"
CREW_BREW_DIR="${CREW_PREFIX}/tmp/crew/"
CREW_DEST_DIR="${CREW_BREW_DIR}/dest"
CREW_PACKAGES_PATH="${CREW_LIB_PATH}/packages"
ARCH="$(uname -m)"
if [ "${EUID}" == "0" ]; then
echo 'Chromebrew should not be installed or run as root.'
exit 1;
fi
case "$architecture" in
case "${ARCH}" in
"i686"|"x86_64"|"armv7l"|"aarch64")
LIB_SUFFIX=
[ "${ARCH}" == "x86_64" ] && LIB_SUFFIX='64'
;;
*)
echo 'Your device is not supported by Chromebrew yet.'
......@@ -26,18 +33,20 @@ case "$architecture" in
esac
# 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
for dir in $CREW_LIB_PATH $CREW_CONFIG_PATH $CREW_CONFIG_PATH/meta $CREW_BREW_DIR $CREW_DEST_DIR $CREW_PACKAGES_PATH; do
mkdir -p $dir
for dir in "${CREW_CONFIG_PATH}/meta" "${CREW_DEST_DIR}" "${CREW_PACKAGES_PATH}"; do
if [ ! -d "${dir}" ]; then
mkdir -p "${dir}"
fi
done
# prepare url and sha256
# install only gcc7, ruby, libiconv, git and libssh2 (order matters)
urls=()
sha256s=()
case "$architecture" in
case "${ARCH}" in
"aarch64")
urls+=('https://dl.bintray.com/chromebrew/chromebrew/gcc7-7.3.0-3-chromeos-armv7l.tar.xz')
sha256s+=('c9dd2a2b2d195f0f2021dc673d6317e46b5dfaef582f496b4cea1f3c5c2c17ad')
......@@ -94,133 +103,128 @@ esac
# functions to maintain packages
function download_check () {
cd $CREW_BREW_DIR
cd "${CREW_BREW_DIR}"
#download
echo "Downloading $1..."
curl --progress-bar -C - -# -L --ssl $2 -o "$3"
echo "Downloading ${1}..."
curl --progress-bar -C - -L --ssl "${2}" -o "${3}"
#verify
echo "Verifying $1..."
echo $4 $3 | sha256sum -c -
case $? in
echo "Verifying ${1}..."
echo "${4}" "${3}" | sha256sum -c -
case "${?}" in
0) ;;
*)
echo "Verification failed, something may be wrong with the $1 download."
echo "Verification failed, something may be wrong with the download."
exit 1;;
esac
}
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
echo "Extracting $1 (this may take a while)..."
rm -rf ./usr ./home
tar -xf $2
echo "Installing $1 (this may take a while)..."
if [ -d "${CREW_BREW_DIR}/home" ]; then
tar cf - ./usr/* ./home/* | (cd /; tar xp --keep-directory-symlink -f -)
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
echo "Extracting ${1} (this may take a while)..."
tar xpf ../"${2}"
echo "Installing ${1} (this may take a while)..."
tar cpf - ./*/* | (cd /; tar xp --keep-directory-symlink -f -)
mv ./dlist "${CREW_CONFIG_PATH}/meta/${1}.directorylist"
mv ./filelist "${CREW_CONFIG_PATH}/meta/${1}.filelist"
}
function update_device_json () {
cd $CREW_CONFIG_PATH
cd "${CREW_CONFIG_PATH}"
if grep '"name": "'$1'"' device.json > /dev/null; then
echo "Updating version number of existing $1 information in device.json..."
sed -i device.json -e '/"name": "'$1'"/N;//s/"version": ".*"/"version": "'$2'"/'
if grep '"name": "'"${1}"'"' device.json > /dev/null; then
echo "Updating version number of ${1} in device.json..."
sed -i device.json -e '/"name": "'"${1}"'"/N;//s/"version": ".*"/"version": "'"${2}"'"/'
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/$/,\
{\
"name": "'$1'",\
"version": "'$2'"\
"name": "'"${1}"'",\
"version": "'"${2}"'"\
}/'
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/$/\
{\
"name": "'$1'",\
"version": "'$2'"\
"name": "'"${1}"'",\
"version": "'"${2}"'"\
}/'
fi
}
# create the device.json file if it doesn't exist
cd $CREW_CONFIG_PATH
cd "${CREW_CONFIG_PATH}"
if [ ! -f device.json ]; then
echo "Creating new device.json..."
echo '{' > device.json
echo ' "architecture": "'$architecture'",' >> device.json
echo ' "architecture": "'"${ARCH}"'",' >> device.json
echo ' "installed_packages": [' >> device.json
echo ' ]' >> device.json
echo '}' >> device.json
fi
# extract, install and register packages
for i in `seq 0 $((${#urls[@]} - 1))`; do
url=${urls[$i]}
sha256=${sha256s[$i]}
tarfile=`basename $url`
name=${tarfile%%-*} # extract string before first '-'
rest=${tarfile#*-} # extract string after first '-'
version=`echo $rest | sed -e 's/-chromeos.*$//'`
for i in $(seq 0 $((${#urls[@]} - 1))); do
url="${urls["${i}"]}"
sha256="${sha256s["${i}"]}"
tarfile="$(basename ${url})"
name="${tarfile%%-*}" # extract string before first '-'
rest="${tarfile#*-}" # extract string after first '-'
version="$(echo ${rest} | sed -e 's/-chromeos.*$//')"
# extract string between first '-' and "-chromeos"
download_check $name $url $tarfile $sha256
extract_install $name $tarfile
update_device_json $name $version
download_check "${name}" "${url}" "${tarfile}" "${sha256}"
extract_install "${name}" "${tarfile}"
update_device_json "${name}" "${version}"
done
# download, prepare and install chromebrew
cd $CREW_LIB_PATH
rm -rf crew lib packages
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
# create symlink to 'crew' in ${CREW_PREFIX}/bin/
rm -f "${CREW_PREFIX}/bin/crew"
ln -s "../lib/crew/crew" "${CREW_PREFIX}/bin/"
# prepare sparse checkout .rb packages directory and do it
cd $CREW_LIB_PATH
cd "${CREW_LIB_PATH}"
rm -rf .git
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
echo packages >> .git/info/sparse-checkout
echo lib >> .git/info/sparse-checkout
echo crew >> .git/info/sparse-checkout
git fetch origin master
git reset --hard origin/master
git fetch origin "${BRANCH}"
git reset --hard origin/"${BRANCH}"
# install a base set of essential packages
yes | crew install buildessential less most
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 "echo \"export PAGER=$CREW_PREFIX/bin/less\" >> ~/.bashrc && . ~/.bashrc"
echo "echo \"export PAGER='less'\" >> ~/.bashrc && . ~/.bashrc"
echo
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 "You may wish to set the default EDITOR. The current EDITOR is '$EDITOR'."
echo "For example, to set vim as the default editor, execute the following:"
echo "echo \"export EDITOR=$CREW_PREFIX/bin/vim\" >> ~/.bashrc && . ~/.bashrc"
echo "To install the vim editor, run 'crew install vim'"
echo "You may wish to set the EDITOR environment variable."
echo "For example, to set 'vim' as the default editor, execute the following:"
echo "echo \"export EDITOR='vim'\" >> ~/.bashrc && . ~/.bashrc"
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 "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