forked from jazzdotdev/jazz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
280 lines (254 loc) Β· 6.96 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
#!/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 --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
case $(get_os) in
Linux | Darwin )
sudo unzip -o temp.zip -d $1
;;
* )
unzip -o temp.zip -d $1
;;
esac
rm temp.zip
else
error "Curl is not installed. Please install curl. If curl is installed, check your path and try again"
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 Machu Picchu
curl -L $URL -o $TEMP
echo Installing Machu Picchu
mkdir $DIR
unzip -q -o temp.zip -d $DIR
rm $TEMP
cd $DIR/mp-installer-master
case $(get_os) in
Linux | Darwin ) sudo 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 Machu Picchu installed succesfully
else
error Machu Picchu install was unsuccesfull
fi
}
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_torchbear() {
if [ -f "$(torchbear_path)" ]; then
echo Uninstalling Torchbear.
case $(get_os) in
Linux | Darwin)
sudo rm $(torchbear_path)
;;
* )
rm $(torchbear_path)
;;
esac
if [ -f "$(torchbear_path)" ]; then
error Torchbear could not be uninstalled.
else
echo Torchbear is now uninstalled.
fi
else
error Torchbear is not installed.
fi
}
uninstall_mp() {
if [ -f "$(install_path)/mp" ]; then
echo Uninstalling machu picchu.
case $(get_os) in
Linux | Darwin)
sudo rm $(install_path)/mp
sudo rm -rf $(install_path)/machu-pichu
;;
* )
rm $(install_path)/mp
rm -rf $(install_path)/machu-pichu
;;
esac
if [ -f "$(install_path)/mp" ]; then
error Machu Picchu could not be uninstalled.
else
echo Machu Picchu is now uninstalled.
fi
else
error Machu Picchu is not installed.
fi
}
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 "Torchbear is up to date."
fi
echo "New version of available"
echo "Current Version: ${curr_version[1]}"
echo "Latest Version: $repo_version"
fi
echo Downloading torchbear
download_and_extract $(install_path)
if [ -f "$(torchbear_path)" ]; then
local version=($(echo $($(torchbear_path) -V)))
echo Torchbear ${version[1]} has been installed.
fi
}
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
echo "Now that you have Torchbear installed, would you like to install Machu Picchu package manager? You can use it to install more apps, safely and easily."
echo "To read more about it, check http://github.com/foundpatterns/machu-picchu. If you choose to install now, then running mp --help will show you what to do next with it"
read -t 10 -e -p "Do you want to install machu-picchu (Y/n)? " -i "Y" choice </dev/tty || choice="N"
case "$choice" in
y|Y )
install_machu_picchu
;;
n|N )
# Ignore
;;
* ) echo "Invalid option";;
esac
fi
else
error Torchbear 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-mp")
uninstall_mp
;;
* )
install_torchbear
install_mp
;;
esac