Files
chromebrew/install.sh
Ed Reel bea635c81b Update ruby from 2.5.1 to 2.5.3
Add pre-built binaries

Add gcc7 dependency to install.sh

Add EDITOR section and improve comments in install.sh
2018-12-20 16:19:01 -06:00

227 lines
8.8 KiB
Bash
Executable File

#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.'
exit 1;
fi
case "$architecture" in
"i686"|"x86_64"|"armv7l"|"aarch64")
;;
*)
echo 'Your device is not supported by Chromebrew yet.'
exit 1;;
esac
# This will allow things to work without sudo
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
done
# prepare url and sha256
# install only gcc7, ruby, libiconv, git and libssh2 (order matters)
urls=()
sha256s=()
case "$architecture" in
"aarch64")
urls+=('https://dl.bintray.com/chromebrew/chromebrew/gcc7-7.3.0-3-chromeos-armv7l.tar.xz')
sha256s+=('c9dd2a2b2d195f0f2021dc673d6317e46b5dfaef582f496b4cea1f3c5c2c17ad')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/ruby-2.5.3-chromeos-armv7l.tar.xz')
sha256s+=('5e485a0320b298e1f5c4ff50d98c6fe6d06ad9a38d9119d580a8b469418e1e6a')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/libiconv-1.15-chromeos-armv7l.tar.xz')
sha256s+=('047163a67f3ea9e143b465087d5ea4a3d17b963c8ad3579bc27a21934d4a17ab')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/git-2.20.1-chromeos-armv7l.tar.xz')
sha256s+=('149a43937a9be2a8af9ebc1ab9b14fb90ff361acf1c9641959fa1c6731f842a7')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/libssh2-1.8.0-chromeos-armv7l.tar.xz')
sha256s+=('6fa84296583273dd9e749a2c54cb1cf688a7dab032e2528de5944a4d9777f037')
;;
"armv7l")
if ! type "xz" > /dev/null; then
urls+=('https://github.com/snailium/chrome-cross/releases/download/v1.8.1/xz-5.2.3-chromeos-armv7l.tar.gz')
sha256s+=('4dc9f086ee7613ab0145ec0ed5ac804c80c620c92f515cb62bae8d3c508cbfe7')
fi
urls+=('https://dl.bintray.com/chromebrew/chromebrew/gcc7-7.3.0-3-chromeos-armv7l.tar.xz')
sha256s+=('c9dd2a2b2d195f0f2021dc673d6317e46b5dfaef582f496b4cea1f3c5c2c17ad')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/ruby-2.5.3-chromeos-armv7l.tar.xz')
sha256s+=('5e485a0320b298e1f5c4ff50d98c6fe6d06ad9a38d9119d580a8b469418e1e6a')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/libiconv-1.15-chromeos-armv7l.tar.xz')
sha256s+=('047163a67f3ea9e143b465087d5ea4a3d17b963c8ad3579bc27a21934d4a17ab')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/git-2.20.1-chromeos-armv7l.tar.xz')
sha256s+=('149a43937a9be2a8af9ebc1ab9b14fb90ff361acf1c9641959fa1c6731f842a7')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/libssh2-1.8.0-chromeos-armv7l.tar.xz')
sha256s+=('6fa84296583273dd9e749a2c54cb1cf688a7dab032e2528de5944a4d9777f037')
;;
"i686")
urls+=('https://dl.bintray.com/chromebrew/chromebrew/gcc7-7.3.0-3-chromeos-i686.tar.xz')
sha256s+=('4202ea5e9d703d39c522e5f1d7145b8d682a0380baf53b98309b94816408e0b6')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/ruby-2.5.3-chromeos-i686.tar.xz')
sha256s+=('6f4a5b96c31ef5ee4f09ac15da4c7a4a9d838ed5233038136ead1e155d17f342')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/libiconv-1.15-chromeos-i686.tar.xz')
sha256s+=('28de005b59407d5343775296814e10272c53aedd860e0208f396cc873045c095')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/git-2.20.1-chromeos-i686.tar.xz')
sha256s+=('c1dc78e8f51c3ccba54fc6791b05e40002d85eeb7c1b011b0f456e53a64f9fa5')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/libssh2-1.8.0-chromeos-i686.tar.xz')
sha256s+=('771b2d30a49dd691db8456f773da404753d368f3c31d03c682c552ea0b5eb65e')
;;
"x86_64")
urls+=('https://dl.bintray.com/chromebrew/chromebrew/gcc7-7.3.0-3-chromeos-x86_64.tar.xz')
sha256s+=('992fa6556e3c4b45ae548b0ce64e1c5cafaffd109fe9aba5d857c6c569e5b33e')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/ruby-2.5.3-chromeos-x86_64.tar.xz')
sha256s+=('352b78fc883cf8936136991fda9ca5d49e90b2951626158d6af8ef4b58d67f97')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/libiconv-1.15-chromeos-x86_64.tar.xz')
sha256s+=('8689ee2b4acc0440df6eec9eb0fb19aa8393b68bd64517cbca65d98041a2c7cc')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/git-2.20.1-chromeos-x86_64.tar.xz')
sha256s+=('316842c20bf24202c794eb9c21e46d14bb95069d3667dc5d32e5058bdcdebd89')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/libssh2-1.8.0-chromeos-x86_64.tar.xz')
sha256s+=('6e026450389021c6267a9cc79b8722d15f48e2f8d812d5212501f686b4368e3c')
;;
esac
# functions to maintain packages
function download_check () {
cd $CREW_BREW_DIR
#download
echo "Downloading $1..."
curl -C - -# -L --ssl $2 -o "$3"
#verify
echo "Verifying $1..."
echo $4 $3 | sha256sum -c -
case $? in
0) ;;
*)
echo "Verification failed, something may be wrong with the $1 download."
exit 1;;
esac
}
function extract_install () {
cd $CREW_BREW_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
}
function update_device_json () {
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'"/'
elif grep '^ }$' device.json > /dev/null; then
echo "Adding new $1 information to device.json..."
sed -i device.json -e '/^ }$/s/$/,\
{\
"name": "'$1'",\
"version": "'$2'"\
}/'
else
echo "Adding new $1 information to device.json..."
sed -i device.json -e '/^ "installed_packages": \[$/s/$/\
{\
"name": "'$1'",\
"version": "'$2'"\
}/'
fi
}
# create the device.json file if it doesn't exist
cd $CREW_CONFIG_PATH
if [ ! -f device.json ]; then
echo "Creating new device.json..."
echo '{' > device.json
echo ' "architecture": "'$architecture'",' >> 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.*$//'`
# extract string between first '-' and "-chromeos"
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
# prepare sparse checkout .rb packages directory and do it
cd $CREW_LIB_PATH
rm -rf .git
git init
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
# install a base set of essential packages
yes | crew install buildessential less most
echo
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 "Alternatively, you could use most. Why settle for less, right?"
echo "echo \"export PAGER=$CREW_PREFIX/bin/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
echo "Chromebrew installed successfully and package lists updated."