forked from ExodusMovement/exodus-linux-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exodus-installer.sh
executable file
·250 lines (204 loc) · 6.08 KB
/
exodus-installer.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env bash
#
# Open source, released under the MIT license (see LICENSE file).
#
# https://www.gnu.org/software/bash/manual/bash.html
#
# Link this file so that `-eden` appears in the name, and the Eden version
# will be installed.
#
# Global variables
#
INSTALLER_VERSION=1.61.0
PROCESSOR="x64"
#
# Check for eden suffix in name of script. If detected, download the Eden version instead.
#
if [[ $0 =~ .*-eden.* ]]; then
EDEN_DOWNLOAD_INFIX=-eden
EDEN_BIN_SUFFIX=Eden
fi
if [ $EUID -ne 0 ]; then
SUDO=sudo
fi
# Generate a base file name, with eden infix, processor and version.
#
exodus_filename() {
echo 'exodus'${EDEN_DOWNLOAD_INFIX}'-linux-'${PROCESSOR}'-'$1'.zip'
}
# Generate the download URL
# This can change, so we have to make sure this is "up to date"
#
exodus_download_url() {
echo 'https://exodusbin.azureedge.net/releases/exodus-linux-x64-1.61.0.zip'$1
}
# Generate the download target on disk
#
exodus_download_target() {
mkdir -p $HOME/Downloads
echo $HOME'/Downloads/'$1
}
# Download the Exodus payload from the server, but only
# download if we don't have it on disk already (-c option)
#
exodus_download() {
wget -v -c -O $2 $1
}
# Download and check the exodus package to verify
# SHA hash
exodus_verify_hashes() {
#
# If JP's key doesn't exist...
if ! gpg --list-public-keys --with-colons --fixed-list-mode --with-fingerprint | grep -q '^fpr:::::::::12408650E2192FEBE4E7024C9D959455325B781A:$'
then
jpKey='https://keybase.io/jprichardson/pgp_keys.asc?fingerprint=12408650e2192febe4e7024c9d959455325b781a'
# ...Import JP Richardson's Public Key
curl -s $jpKey | gpg --import -q
if ! [ $? -eq 0 ]; then
return 1
fi
fi
local HASHES=`exodus_download_url hashes-exodus${EDEN_DOWNLOAD_INFIX}-$1.txt`
curl -s $HASHES | gpg --verify
if ! [ $? -eq 0 ]; then
return 1
fi
from_hash=`curl -s $HASHES | grep linux | perl -lane 'print $F[0]'`
to_hash=`sha256sum $2 | perl -lane 'print $F[0]'`
test "$from_hash" == "$to_hash"
return $?
}
# Install the exodus package to the /opt folder
#
exodus_install() {
if [ "$SUDO" != "" ]; then
echo "Running commands with SUDO..."
fi
# extract files & create link
$SUDO unzip -d /opt/ $1
$SUDO mv /opt/Exodus${EDEN_BIN_SUFFIX}-linux-* /opt/exodus${EDEN_DOWNLOAD_INFIX}
$SUDO ln -s -f /opt/exodus${EDEN_DOWNLOAD_INFIX}/Exodus${EDEN_BIN_SUFFIX} /usr/bin/Exodus${EDEN_BIN_SUFFIX}
# register exodus://
$SUDO update-desktop-database > /dev/null 2>&1
# update icons
$SUDO gtk-update-icon-cache /usr/share/icons/hicolor -f > /dev/null 2>&1
}
# Check to see if Exodus is installed
#
exodus_is_installed() {
which Exodus${EDEN_BIN_SUFFIX} > /dev/null 2>&1
}
# Uninstall the application completely
#
exodus_uninstall() {
if [ "$SUDO" != "" ]; then
echo "Running commands with SUDO..."
fi
# remove app files
$SUDO rm -f /usr/bin/Exodus${EDEN_BIN_SUFFIX}
$SUDO rm -rf /opt/exodus${EDEN_DOWNLOAD_INFIX}
$SUDO rm -f /usr/share/applications/Exodus${EDEN_BIN_SUFFIX}.desktop
$SUDO find /usr/share/icons/hicolor/ -type f -name *Exodus.png -delete
# drop exodus://
$SUDO update-desktop-database > /dev/null 2>&1
# update icons
$SUDO gtk-update-icon-cache /usr/share/icons/hicolor -f > /dev/null 2>&1
}
# Do the actual installation procedure, calling the above functions when needed.
#
# This function detects the command line arguments and verifies they are correct.
# Then each case is run according to the arguments. What this does is:
#
# 1) download the version specified from Exodus' servers (if version specified
# otherwise, use supplied filename)
# 2) check the integrity of the archive
# 3) check for root privileges (use sudo)
# 4) install the app
#
# Or, we can uninstall the app from the harddrive (root privs needed)
#
# Or, we can check to see if Exodus is installed.
#
exodus_installer() {
if [ $# -lt 1 ]; then
$0 --help
return 0
fi
local COMMAND
COMMAND=$1
shift
case $COMMAND in
'help' | '--help' )
cat << EOF
Exodus installer v$INSTALLER_VERSION
Usage:
$0 --help Print this message
$0 install <version|file> Install Exodus from file or download and install <version>
$0 check Check that Exodus is installed and print installed version
$0 uninstall Remove Exodus
Example:
$0 install ~/Downloads/exodus_linux_1.4.0.zip Install Exodus 1.4.0 from file
$0 install 1.4.0 Download and install Exodus 1.4.0
EOF
;;
'install' | 'i' )
if [ $# -ne 1 ]; then
>&2 $0 --help
return 127
fi
if exodus_is_installed; then
>&2 echo 'Exodus'${EDEN_BIN_SUFFIX}' already installed.'
return 1
fi
local EXODUS_PKG
if [[ $# -eq 1 && -f $1 ]]; then
EXODUS_PKG=$1
else
local EXODUS_FILENAME=`exodus_filename $1`
EXODUS_PKG=`exodus_download_target ${EXODUS_FILENAME}`
local EXODUS_URL=`exodus_download_url ${EXODUS_FILENAME}`
exodus_download $EXODUS_URL $EXODUS_PKG
if [ $? -ne 0 ]; then
return 1
fi
fi
if ! exodus_verify_hashes $1 $EXODUS_PKG; then
echo "$EXODUS_PKG has failed the hashing checksum! Aborting installation!"
return 1
fi
if ! unzip -t $EXODUS_PKG > /dev/null; then
echo "$EXODUS_PKG failed the SHA check, and is a corrupt file! Please remove and redownload!"
return 1
fi
exodus_install $EXODUS_PKG
return $?
;;
'check' )
if [ $# -ne 0 ]; then
>&2 $0 --help
return 127
fi
exodus_is_installed
if [ $? -eq 1 ]; then
echo 'Exodus'${EDEN_BIN_SUFFIX}' is not installed.'
else
echo 'Exodus'${EDEN_BIN_SUFFIX}' is installed. Version: '`Exodus${EDEN_BIN_SUFFIX} --version`
fi
;;
'uninstall' )
if [ $# -ne 0 ]; then
>&2 $0 --help
return 127
fi
exodus_uninstall
return $?
;;
* )
>&2 $0 --help
return 127
;;
esac
}
# pass arguments to main function
#
exodus_installer $@