-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·517 lines (498 loc) · 20.1 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
#!/bin/bash
set -e
# print a red error message
function red {
echo -e "\x1B[31m✗ $*\x1B[0m" >&2
}
# print a yellow massage
function yellow {
echo -e "\x1B[33m! $*\x1B[0m" >&2
}
# print a grean message
function green {
echo -e "\x1B[32m✓ $*\x1B[0m" >&2
}
# check if bash is exists
if [ -z "${BASH_VERSION}" ]; then
red "Bash is required to interpret this script."
exit 1
fi
# check what operating system is running
function get_os {
case "$OSTYPE" in
*"linux"*)
case "$(uname -a)" in
*"microsoft"*)
readonly export os="windows"
;;
*)
readonly export os="linux"
;;
esac
;;
*"darwin"*)
readonly export os="mac"
;;
*"msys"* | *"win32"*)
readonly export os="windows"
;;
*)
red "Your operating system isn't supported by this script."
exit 1
;;
esac
green "$os operating system detected."
}
# check what processor is running
function get_processor {
case $(uname -a) in
*"x86_64"* | *"amd64"*)
readonly export processor="64-bit"
;;
*"x32"* | "x86" | *"i386"* | *"i486"* | *"i586"* | *"i686"*)
readonly export processor="32-bit"
;;
*"arm64"* | *"aarch64"*)
readonly export processor="M1"
;;
*)
red "Your processor isn't supported by this script."
exit 1
;;
esac
green "$processor procesoor detected."
}
# check what package manager is running
function get_package_manager {
if [[ "$os" == "linux" ]] || [[ "$os" == "windows" ]]; then
declare -Ag osInfo;
osInfo[/etc/alpine-release]=apk
osInfo[/etc/debian_version]=apt-get
osInfo[/etc/redhat-release]=yum
osInfo[/etc/gentoo-release]=emerge
osInfo[/etc/arch-release]=pacman
osInfo[/etc/SuSE-release]=zypper
osInfo[/etc/zypp]=zypper
for f in ${!osInfo[@]}; do
if [[ -f $f ]] || [[ -d $f ]];then
readonly export package_manager="${osInfo[$f]}"
break
fi
done
if [[ "$package_manager" == "" ]]; then
red "Your package manager isn't supported by this script."
exit 1
fi
elif [[ "$os" == "mac" ]]; then
if brew --version > /dev/null 2>&1; then
readonly export package_manager="brew"
elif ports --version > /dev/null 2>&1; then
readonly export package_manager="port"
else
return 0
fi
fi
green "$package_manager package manager detected detected"
}
# update and upgrade packages
function update_upgrade_packages {
yellow "You need \`sudo\` access to update packages!"
if [[ "$package_manager" == "apk" ]]; then
sudo apk update -q
sudo apk upgrade -q
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get update -qq
sudo apt-get upgrade -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum check-update -q
sudo yum update -q
elif [[ "$package_manager" == "emerge" ]]; then
sudo emaint --auto sync --quiet
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -Syu -q
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper refresh -q
sudo zypper update -q
elif [[ "$package_manager" == "brew" ]]; then
brew update
brew upgrade
elif [[ "$package_manager" == "port" ]]; then
sudo port selfupdate
sudo port upgrade outdated
fi
readonly export updated=true
}
# check if bc is installed
function check_bc {
if ! bc --version > /dev/null 2>&1; then
if [[ "$updated" != true ]]; then
update_upgrade_packages
fi
yellow "The script needs \`bc\` to be able to continue!"
if [[ "$package_manager" == "apk" ]]; then
sudo apk install bc -q
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install bc -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install bc -q
elif [[ "$package_manager" == "emerge" ]]; then
sudo emerge bc -q
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -S bc -q
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper install bc -q
elif [[ "$package_manager" == "brew" ]]; then
brew isntall bc
elif [[ "$package_manager" == "port" ]]; then
sudo port install bc
fi
green "Bc installed successfully."
fi
}
# check if wget or curl is installed
function check_curl_or_wget {
if curl --version > /dev/null 2>&1; then
readonly export utility="curl"
elif wget --version > /dev/null 2>&1; then
readonly export utility="wget"
else
if [[ "$updated" != true ]]; then
update_upgrade_packages
fi
yellow "The script needs \`wget\` or \`curl\` to be able to continue!"
trap "red Operation aborted.; exit 1" SIGINT
while true; do
echo -e "- Press \x1B[1mC\x1B[0m to install \x1B[1mcURL\x1B[0m"
echo -e "- Press \x1B[1mW\x1B[0m to install \x1B[1mWget\x1B[0m"
echo -e "- Press \x1B[1mControl-C\x1B[0m to cancel installation"
echo -n "[C/W] "
read -rsn1 answer
if [[ "${answer,,}" == "C" ]]; then
echo -e "\x1B[1mInstalling cURL\x1B[0m!"
readonly export utility="curl"
break
elif [[ "${answer,,}" == "w" ]]; then
echo -e "\x1B[1mInstalling Wget\x1B[0m!"
readonly export utility="wget"
break
else
red "Unknown option, try again."
fi
done
if [[ "$package_manager" == "apk" ]]; then
sudo apk add --no-cache "$utility" -q
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install "$utility" -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install "$utility" -q
elif [[ "$package_manager" == "emerge" ]]; then
sudo emerge "$utility" -q
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -S "$utility" -q
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper install "$utility" -q
elif [[ "$package_manager" == "brew" ]]; then
brew install "$utility"
elif [[ "$package_manager" == "port" ]]; then
sudo port install "$utility"
else
echo -e "You need to install \x1B[1mHomebrew\x1B[0m or \x1B[1mPorts\x1B[0m to continue"
ask_user "B" "Brew" "P" "Port"
trap "red Operation aborted.; exit 1" SIGINT
while true; do
echo -e "- Press \x1B[1mB\x1B[0m to install \x1B[1mBrew\x1B[0m"
echo -e "- Press \x1B[1mP\x1B[0m to install \x1B[1mPort\x1B[0m"
echo -e "- Press \x1B[1mControl-C\x1B[0m to cancel installation"
echo -n "[B/P] "
read -rsn1 answer
if [[ "${answer,,}" == "b" ]]; then
echo -e "\x1B[1mInstalling Brew\x1B[0m!"
readonly export package_manager="brew"
break
elif [[ "${answer,,}" == "p" ]]; then
echo -e "\x1B[1mInstalling port\x1B[0m!"
readonly export package_manager="port"
break
else
red "Unknown option, try again."
fi
done
if [[ "$package_manager" == "brew" ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install "$utility"
elif [[ "$package_manager" == "port" ]]; then
red "Installing MacPorts currently not supported"
exit 1
# mac_version=`sw_vers -productVersion`
# if [[ "$mac_version" -ge "10.10" ]]; then
# if ! xcode-select -p > /dev/null 2>&1; then
# echo -e "\x1B[31mNo Xcode found...\x1B[0m"
# echo -e "You need to install \x1B[1mXcode\x1B[0m to continue..."
# echo "Do you want to install Xcode? [Y/n] "
# trap "cntl_c" SIGINT
# function cntl_c {
# echo -e "\x1b[2mCancelled by user\x1B[0m"
# exit 1
# }
# while true; do
# echo -e "- Press \x1B[1mY\x1B[0m to install \x1B[1mXcode\x1B[0m"
# echo -e "- Press \x1B[1mN\x1B[0m to cancel installatin"
# echo -e "- Press \x1B[1mControl-C\x1B[0m to cancel installation"
# echo -n "[Y/n] "
# read -rsn1 answer
# if [[ "${answer,,}" == "y" ]]; then
# echo -e "\x1B[1mInstalling Xcode\x1B[0m"
# xcode-select --install
# sudo xcodebuild -license
# break
# elif [[ "${answer,,}" == "n" ]]; then
# cntl_c
# else
# echo -e "\x1B[31mUnknown option, try again\x1B[0m"
# fi
# done
# fi
# else
# echo -e "\x1B[31mUnsupported Mac OS version...\x1B[0m"
# exit 1
# fi
# donwload_requiments
fi
fi
green "$utility installed successfully."
fi
}
# check if cut is installed
function check_cut {
if ! cut --version > /dev/null 2>&1; then
if [[ "$updated" != true ]]; then
update_upgrade_packages
fi
yellow "The script needs \`cut\` to be able to continue!"
if [[ "$package_manager" == "apk" ]]; then
sudo apk install cut -q
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install cut -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install cut -q
elif [[ "$package_manager" == "emerge" ]]; then
sudo emerge cut -q
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -S cut -q
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper install cut -q
elif [[ "$package_manager" == "brew" ]]; then
brew isntall cut
elif [[ "$package_manager" == "port" ]]; then
sudo port install cut
fi
green "Cut installed successfully."
fi
}
# check if grep is installed
function check_grep {
if ! grep --version > /dev/null 2>&1; then
if [[ "$updated" != true ]]; then
update_upgrade_packages
fi
yellow "The script needs \`grep\` to be able to continue!"
if [[ "$package_manager" == "apk" ]]; then
sudo apk install grep -q
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install grep -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install grep -q
elif [[ "$package_manager" == "emerge" ]]; then
sudo emerge grep -q
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -S grep -q
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper install grep -q
elif [[ "$package_manager" == "brew" ]]; then
brew isntall grep
elif [[ "$package_manager" == "port" ]]; then
sudo port install grep
fi
green "Grep installed successfully."
fi
}
# check if zip installed
function check_tar {
if ! tar --version > /dev/null 2>&1; then
if [[ "$updated" != true ]]; then
update_upgrade_packages
fi
yellow "The script needs \`tar\` to be able to continue!"
if [[ "$package_manager" == "apk" ]]; then
sudo apk install tar -q
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install tar -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install tar -q
elif [[ "$package_manager" == "emerge" ]]; then
sudo emerge tar -q
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -S tar -q
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper install tar -q
elif [[ "$package_manager" == "brew" ]]; then
brew isntall tar
elif [[ "$package_manager" == "port" ]]; then
sudo port install tar
fi
green "Tar installed successfully."
fi
}
# check if zip installed
function check_zip {
if ! zip --version > /dev/null 2>&1; then
if [[ "$updated" != true ]]; then
update_upgrade_packages
fi
yellow "The script needs \`zip\` to be able to continue!"
if [[ "$package_manager" == "apk" ]]; then
sudo apk install zip -q
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install zip -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install zip -q
elif [[ "$package_manager" == "emerge" ]]; then
sudo emerge zip -q
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -S zip -q
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper install zip -q
elif [[ "$package_manager" == "brew" ]]; then
brew isntall zip
elif [[ "$package_manager" == "port" ]]; then
sudo port install zip
fi
green "Zip installed successfully."
fi
}
# install chromedriver
function chrome_driver_install {
if [[ "$os" == "linux" ]]; then
if google-chrome --version > /dev/null 2>&1; then
chrome_local_version=$(google-chrome --version | cut -d " " -f 3)
elif chromium-browser --version > /dev/null 2>&1; then
chrome_local_version=$(chromium-browser --version | cut -d " " -f 2)
# debian requests chromium, not chromium-browser as terminal command input
elif chromium --version > /dev/null 2>&1; then
chrome_local_version=$(chromium --version | cut -d " " -f 2)
fi
elif [[ "$os" == "mac" ]]; then
if /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version > /dev/null 2>&1; then
chrome_local_version=$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version | cut -d " " -f 3)
elif /Applications/Chromium.app/Contents/MacOS/Chromium --version > /dev/null 2>&1; then
chrome_local_version=$(/Applications/Chromium.app/Contents/MacOS/Chromium --version | cut -d " " -f 2)
fi
elif [[ "$os" == "windows" ]]; then
if [[ "$processor" == "64-bit" ]]; then
chrome_path="/mnt/c/Program Files/Google/Chrome/Application"
elif [[ "$processor" == "32-bit" ]]; then
chrome_path="/mnt/c/Program Files (x86)/Google/Chrome/Application"
fi
if [[ -d "$chrome_path" ]]; then
chrome_local_version=`ls "$chrome_path" | head -1`
fi
fi
if [[ "$chrome_local_version" == "" ]] && [[ "$os" != "windows" ]]; then
yellow "You don't have Chrome nor Chromium installed, so the script won't download the driver for you."
return 0
elif [[ "$chrome_local_version" == "" ]] && [[ "$os" == "windows" ]]; then
yellow "You don't have Chrome installed, so the script won't download the driver for you."
return 0
fi
latest_chrome_version=`curl -fsSL https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$(echo $chrome_local_version | cut -d "." -f 1)`
if [[ $os == "linux" ]]; then
if [[ $processor == "64-bit" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$latest_chrome_version/chromedriver_linux64.zip"
elif [[ $processor == "32-bit" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$latest_chrome_version/chromedriver_linux32.zip"
fi
elif [[ $os == "mac" ]]; then
if [[ $processor == "64-bit" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$latest_chrome_version/chromedriver_mac64.zip"
elif [[ $processor == "32-bit" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$latest_chrome_version/chromedriver_mac32.zip"
elif [[ $processor == "M1" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$latest_chrome_version/chromedriver_mac64_m1.zip"
fi
elif [[ $os == "windows" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$latest_chrome_version/chromedriver_win32.zip"
fi
if curl -fsSL -o chromedriver.zip "$chrome_url" > /dev/null 2>&1; then
unzip -qq -o chromedriver.zip -d "drivers"
rm chromedriver.zip
green "Chrome driver installed successfully."
else
red "Your device architecture does not support chrome driver version $latest_chrome_version"
fi
}
# install geckodriver
function firefox_driver_install {
driver_file_name=$(echo "$os$processor" | sed 's/windows/win/' | sed 's/-bit//' | sed 's/mac64/mac/' | sed 's/macM1/macos-aarch64/')
if [[ "$os" == "linux" ]]; then
if firefox --version > /dev/null 2>&1; then
firefox_local_version=$(firefox --version | cut -d " " -f 3 | cut -d "." -f 1)
fi
elif [[ "$os" == "mac" ]]; then
if /Applications/Firefox.app/Contents/MacOS/firefox -v > /dev/null 2>&1; then
firefox_local_version=$(/Applications/Firefox.app/Contents/MacOS/firefox -v | cut -d " " -f 3 | cut -d "." -f 1)
fi
elif [[ "$os" == "windows" ]]; then
readonly current_path=`pwd`
if [[ "$processor" == "64-bit" ]]; then
firefox_path="/mnt/c/Program Files/Mozilla Firefox"
elif [[ "$processor" == "32-bit" ]]; then
firefox_path="/mnt/c/Program Files (x86)/Mozilla Firefox"
fi
if [[ -d "$firefox_path" ]]; then
cd "$firefox_path"
firefox_local_version="$(cmd.exe /c "firefox -v | more" | cut -d " " -f 3 | cut -d "." -f 1 | tr -d '\r')"
cd "$current_path"
fi
fi
if [[ "$firefox_local_version" == "" ]]; then
yellow "You don't have Firefox broswer, so the script won't download the driver for you."
return 0
fi
geckodriver_versions=$(curl -fsSL https://api.github.com/repos/mozilla/geckodriver/releases | grep 'browser_download_url' | sed 's/ "browser_download_url": "//' | sed 's/"//' | grep "$driver_file_name")
if [[ "$geckodriver_versions" == "" ]]; then
red "Your device architecture does not support firefox driver"
fi
if [ $firefox_local_version -gt 90 ]; then
firefox_url=$(echo $geckodriver_versions | cut -d " " -f 1)
elif [ $firefox_local_version -gt 79 ]; then
firefox_url=$(echo $geckodriver_versions | cut -d " " -f 2)
elif [ $firefox_local_version -ge 62 ]; then
firefox_url=$(echo $geckodriver_versions | cut -d " " -f 9)
else
red "Your Firefox version in not supported, so the script won't download the driver for you."
return 0
fi
mkdir -p drivers
if [[ "$os" == "linux" ]] || [[ $os == "mac" ]]; then
curl -fsSL -o geckodriver.tar.gz "$firefox_url"
tar -xzf geckodriver.tar.gz -C drivers
rm geckodriver.tar.gz
elif [[ "$os" == "windows" ]]; then
curl -fsSL -o geckodriver.zip "$firefox_url"
unzip -qq -o geckodriver.zip -d drivers
rm geckodriver.zip
fi
green "Firefox driver installed successfully."
}
function main {
get_os
get_processor
get_package_manager
check_bc
check_curl_or_wget
check_zip
check_tar
chrome_driver_install
firefox_driver_install
}
main