forked from chromebrew/chromebrew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·194 lines (175 loc) · 6.69 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#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 ruby, git and libssh2
urls=()
sha256s=()
case "$architecture" in
"aarch64")
urls+=('https://dl.bintray.com/chromebrew/chromebrew-cross/ruby-2.4.1-chromeos-armv7l.tar.xz')
sha256s+=('6c0ef23447d4591739dc00fa9b021a4d83291acbc37330e659d257efed474caf')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/git-2.14.1-1-chromeos-armv7l.tar.xz')
sha256s+=('8548a8273beeb7956fed40e5db078d624b3d0f9c7b5897980b31aaba5d0837b8')
urls+=('https://dl.bintray.com/chromebrew/chromebrew-cross/libssh2-1.8.0-chromeos-armv7l.tar.xz')
sha256s+=('94662756e545c73d76c37b2b83dd9852ebe71f4a17fc80d85db0fbaef72d4ca3')
;;
"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-cross/ruby-2.4.1-chromeos-armv7l.tar.xz')
sha256s+=('6c0ef23447d4591739dc00fa9b021a4d83291acbc37330e659d257efed474caf')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/git-2.14.1-1-chromeos-armv7l.tar.xz')
sha256s+=('8548a8273beeb7956fed40e5db078d624b3d0f9c7b5897980b31aaba5d0837b8')
urls+=('https://dl.bintray.com/chromebrew/chromebrew-cross/libssh2-1.8.0-chromeos-armv7l.tar.xz')
sha256s+=('94662756e545c73d76c37b2b83dd9852ebe71f4a17fc80d85db0fbaef72d4ca3')
;;
"i686")
urls+=('https://dl.bintray.com/chromebrew/chromebrew-cross/ruby-2.4.1-chromeos-i686.tar.xz')
sha256s+=('851a40ca3860eadfe21a1b77422f8769497a73fd1f275d370e3874948ddb64bd')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/git-2.14.1-1-chromeos-i686.tar.xz')
sha256s+=('11c1979b55f8ce623ceee18e78b3177c7038d6909bcbba717bda9fc8e9a6d3f2')
urls+=('https://dl.bintray.com/chromebrew/chromebrew-cross/libssh2-1.8.0-chromeos-i686.tar.xz')
sha256s+=('7d6086f80abd3905a82bd34ffd2b811658c1eaf9ac0e63ad73df39d4ce7c3d9d')
;;
"x86_64")
urls+=('https://dl.bintray.com/chromebrew/chromebrew-cross/ruby-2.4.1-chromeos-x86_64.tar.xz')
sha256s+=('fb15f0d6b8d02acf525ae5efe59fc7b9bc19908123c47d39559bc6e86fe1d655')
urls+=('https://dl.bintray.com/chromebrew/chromebrew/git-2.14.1-1-chromeos-x86_64.tar.xz')
sha256s+=('5950f17a8016f39002e3e25d9c2bd015bb82e5b253285ae144a18a0f8c8fb2f6')
urls+=('https://dl.bintray.com/chromebrew/chromebrew-cross/libssh2-1.8.0-chromeos-x86_64.tar.xz')
sha256s+=('a5ebeb68c8e04e6587621a09cc43d0a3d7baf0cdb4dd945fd22253a6e0a11846')
;;
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
tar -xf $2
echo "Installing $1 (this may take a while)..."
tar cf - ./usr/* | (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
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)
rm -f $CREW_PREFIX/bin/cc
ln -s $CREW_PREFIX/bin/gcc $CREW_PREFIX/bin/cc
#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
crew install buildessential
crew install less
echo
echo "You will have 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 "Chromebrew installed successfully and package lists updated."