-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
install.sh
311 lines (270 loc) · 7.08 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/usr/bin/env bash
set -e
architecture() {
case `uname -m` in
x86_64)
echo x86_64
;;
i686 | i386)
echo i686
;;
#Probably expand out more options for arm and aarch64
armv7*)
echo arm32
;;
aarch64)
echo arm64
;;
*)
error "unknown architecture detected"
;;
esac
}
get_os() {
case `uname -s` in
Linux)
case `uname -o` in
Android)
echo Android
;;
GNU/Linux)
echo Linux
;;
esac
;;
MINGW* | MSYS* | CYGWIN*)
echo Windows
;;
Darwin)
echo Darwin
;;
esac
}
system() {
case $(get_os) in
Linux)
echo linux
;;
Android)
echo android
;;
Darwin)
echo apple
;;
Windows)
echo pc-windows-msvc
;;
*)
error "machine os type is not supported"
;;
esac
}
get_latest_version() {
curl -L --silent "https://api.github.com/repos/foundpatterns/torchbear/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
get_url() {
local arch=$(architecture)
local os=$(system)
#Maybe instead of getting the latest version, we could get the latest stable release instead to reduce the chance of
#exposed bugs being sent to users
local version=$(get_latest_version)
#TODO: Use github api to get the uri for the download instead.
echo "https://github.com/foundpatterns/torchbear/releases/download/${version}/torchbear-${version}-${arch}-${os}-stable.zip"
}
download_and_extract() {
if [ ! -d $1 ]; then
error "Path or directory does not exist."
fi
if [ -x "$(command -v curl)" ]; then
curl -L $(get_url) -o temp.zip
unzip -o temp.zip -d $1
rm temp.zip
else
error "Curl is not installed. Please install curl. If curl is installed, check your path and try again"
fi
}
update_installer() {
local installer_path=$0
local remote_hash=$(curl https://git.io/fpcV6 -sSfL | sha512sum | cut -d " " -f 1)
local local_hash=$(sha512sum $0 | cut -d " " -f 1)
if [ "$remote_hash" == "$local_hash" ]; then
error "Installer is up to date"
else
if [ -w "$0" ]; then
curl https://git.io/fpcV6 -sSfL > $installer_path
local new_hash=$(sha512sum $0 | cut -d " " -f 1)
if [ "$remote_hash" == "$new_hash" ]; then
echo "Installer has been updated"
else
echo "Cannot update installer"
fi
else
error "Cannot update installer; check permissiosns and try again."
fi
fi
}
install_machu_picchu () {
URL="https://github.com/foundpatterns/mp-installer/archive/master.zip"
TEMP=temp.zip
DIR=.mp-installer
if [ -x "$(command -v curl)" ]; then
echo Downloading Mary Poppins
curl -L $URL -o $TEMP
echo Installing Mary Poppins
mkdir $DIR
unzip -q -o temp.zip -d $DIR
rm $TEMP
cd $DIR/mp-installer-master
case $(get_os) in
Linux | Darwin ) torchbear;;
* ) torchbear;;
esac
STATUS=$?
cd ../..
rm -rf $DIR
else
error "Curl is not installed. Please install curl. If curl is installed, check your path and try again"
fi
if [ $STATUS = "0" ]; then
echo Mary Poppins installed succesfully
else
error Mary Poppins install was unsuccesfull
fi
mp refresh
}
install_path() {
case $(get_os) in
Linux | Darwin)
echo "/usr/local/bin"
;;
Android)
echo "/data/data/com.termux/files/usr/bin"
;;
Windows)
if [ -d "$CMDER_ROOT" ]; then
echo "$CMDER_ROOT/bin"
else
error Cmder is required to run this installer.
fi
;;
*)
error "System is not supported at this time"
;;
esac
}
torchbear_path() {
case $(get_os) in
Linux | Darwin | Android)
echo "$(install_path)/torchbear"
;;
Windows)
echo "$(install_path)/torchbear.exe"
;;
esac
}
uninstall_torchup() {
FILE=$(install_path)/torchup
if [ -f $FILE ]; then
rm $FILE
fi
}
uninstall_torchbear() {
if [ -f "$(torchbear_path)" ]; then
echo Uninstalling Jazz.
rm $(torchbear_path)
if [ -f "$(torchbear_path)" ]; then
error Jazz could not be uninstalled.
else
echo Jazz is now uninstalled.
fi
if [ -f $(install_path)/jazz ]; then
rm $(install_path)/jazz
fi
uninstall_torchup
else
error Jazz is not installed.
fi
}
uninstall_mp() {
if [ -f "$(install_path)/mp" ]; then
echo Uninstalling Mary Poppins.
rm $(install_path)/mp
rm -rf $(install_path)/machu-pichu
if [ -f "$(install_path)/mp" ]; then
error Mary Poppins could not be uninstalled.
else
echo Mary Poppins is now uninstalled.
fi
else
error Mary Poppins is not installed.
fi
}
install_torchup() {
URL=https://raw.githubusercontent.com/foundpatterns/torchbear/master/install.sh
curl -L $URL -o $1/torchup
chmod +x $1/torchup
echo Torchup has been installed
}
install_torchbear() {
if [ -f "$(torchbear_path)" ]; then
local curr_version=($(echo $($(torchbear_path) -V)))
local repo_version=$(get_latest_version)
if [ "${curr_version[1]}" == "$repo_version" ]; then
error "Jazz is up to date."
fi
echo "New version of available"
echo "Current Version: ${curr_version[1]}"
echo "Latest Version: $repo_version"
fi
echo Downloading Jazz
DIR=$(install_path)
download_and_extract $DIR
if [ -f $DIR/jazz ]; then
rm $DIR/jazz
fi
ln -Ts $DIR/torchbear $DIR/jazz
if [ -f "$(torchbear_path)" ]; then
local version=($(echo $($(torchbear_path) -V)))
echo Jazz ${version[1]} has been installed.
fi
install_torchup $DIR
}
install_mp() {
if [ -f "$(torchbear_path)" ]; then
# Only install mp if not detected
# TODO: Check for updates for mp
if [ ! -x "$(command -v mp)" ]; then
install_machu_picchu
fi
else
error Jazz is not installed.
fi
}
error() { echo "$*" 1>&2 ; exit 1; }
case $1 in
"--install-torchbear")
install_torchbear
;;
"--install-mp")
install_mp
;;
"--uninstall")
uninstall_torchbear
uninstall_mp
;;
"--uninstall-torchbear")
uninstall_torchbear
;;
"--uninstall-mp")
uninstall_mp
;;
"--update")
update_installer
;;
* )
install_torchbear
install_mp
;;
esac