-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·355 lines (334 loc) · 13.2 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
#!/bin/bash
set -u
function abort() {
echo -e "\x1B[31m✗ $@\x1B[0m" >&2
exit 1
}
function bad() {
echo -e "\x1B[31m✗ $@\x1B[0m" >&2
}
function good() {
echo -e "\x1B[32m✓ $@\x1B[0m" >&2
}
if [ -z "${BASH_VERSION}" ]; then
abort "Bash is required to interpret this script."
fi
# check what OS is running
function get_os {
case "$OSTYPE" in
*"linux"*)
case "$(uname -a)" in
*"microsoft"*)
readonly os="windows"
;;
*)
readonly os="linux"
;;
esac
;;
*"darwin"*)
readonly os="mac"
;;
*"msys"* | *"win32"*)
readonly os="windows"
;;
*)
abort "Your operating system isn't supported by this script."
;;
esac
good "$os operating system detected."
}
# check what CPU is running
function get_cpu {
case $(uname -a) in
*"x86_64"* | *"amd64"*)
readonly cpu="64-bit"
;;
*"x32"* | *"x86_32" | *"i386"* | *"i686"*)
readonly cpu="32-bit"
;;
*"arm64"* | *"aarch64"*)
readonly cpu="M1"
;;
*)
abort "Your CPU isn't supported by this script."
;;
esac
good "$cpu CPU 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 package_manager="${osInfo[$f]}"
break
fi
done
if [[ "$package_manager" == "" ]]; then
abort "Your package manager isn't supported by this script."
fi
elif [[ "$os" == "mac" ]]; then
if brew --version > /dev/null 2>&1; then
readonly package_manager="brew"
elif ports --version > /dev/null 2>&1; then
readonly package_manager="port"
fi
fi
good "$package_manager package manager detected detected"
}
function update_upgrade_packages {
if [[ "$package_manager" == "apk" ]]; then
sudo apk update -qq
sudo apk upgrade -qq
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 -qq
sudo yum update -qq
elif [[ "$package_manager" == "emerge" ]]; then
sudo emaint sync -a
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -Syu -qq
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper refresh -qq
sudo zypper update -qq
elif [[ "$package_manager" == "brew" ]]; then
brew update
brew upgrade
elif [[ "$package_manager" == "port" ]]; then
sudo port selfupdate
sudo port upgrade outdated
fi
}
function check_br {
if ! bc --version > /dev/null 2>&1; then
if [[ "$package_manager" == "apk" ]]; then
sudo apk install bc -qq
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get bc -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install bc -qq
elif [[ "$package_manager" == "emerge" ]]; then
sudo emerge bc -qq
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -S bc -qq
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper install bc -qq
elif [[ "$package_manager" == "brew" ]]; then
brew isntall bc
elif [[ "$package_manager" == "port" ]]; then
sudo port install bc
fi
fi
}
function check_wget_or_curl {
if curl --version > /dev/null 2>&1; then
readonly utility="curl"
elif wget --version > /dev/null 2>&1; then
readonly utility="wget"
else
bad "No curl or wget found..."
ask_user "C" "cURL" "W" "Wget"
if [[ "$package_manager" == "apk" ]]; then
sudo apk add --no-cache "$utility" -qq
elif [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install "$utility" -qq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install "$utility" -qq
elif [[ "$package_manager" == "emerge" ]]; then
sudo emerge "$utility" -qq
elif [[ "$package_manager" == "pacman" ]]; then
sudo pacman -S "$utility" -qq
elif [[ "$package_manager" == "zypper" ]]; then
sudo zypper install "$utility" -qq
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"
if [[ "$package_manager" == "brew" ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
donwload_requiments
elif [[ "$package_manager" == "port" ]]; then
echo "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
fi
}
function ask_user {
trap "abort Operation aborted." SIGINT
while true; do
echo -e "- Press \x1B[1m${1}\x1B[0m to install \x1B[1m$2\x1B[0m"
echo -e "- Press \x1B[1m${3}\x1B[0m to install \x1B[1m$4\x1B[0m"
echo -e "- Press \x1B[1mControl-C\x1B[0m to cancel installation"
echo -n "[${1}/${3}] "
read -rsn1 answer
if [[ "${answer,,}" == "${1,,}" ]]; then
echo -e "\x1B[1mInstalling $2\x1B[0m"
readonly utility="${2,,}"
break
elif [[ "${answer,,}" == "${3,,}" ]]; then
echo -e "\x1B[1mInstalling $4\x1B[0m"
readonly utility="${4,,}"
break
else
bad "Unknown option, try again"
fi
done
}
function chrome_driver_install {
LEAST_CHROME_VERSION=`curl -fsSL https://chromedriver.storage.googleapis.com/LATEST_RELEASE`
if [[ $os == "linux" ]]; then
if [[ $cpu == "64-bit" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$LEAST_CHROME_VERSION/chromedriver_linux64.zip"
elif [[ $cpu == "32-bit" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$LEAST_CHROME_VERSION/chromedriver_linux32.zip"
fi
elif [[ $os == "macOS" ]]; then
if [[ $cpu == "64-bit" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$LEAST_CHROME_VERSION/chromedriver_mac64.zip"
elif [[ $cpu == "32-bit" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$LEAST_CHROME_VERSION/chromedriver_mac32.zip"
elif [[ $cpu == "M1" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$LEAST_CHROME_VERSION/chromedriver_mac64_m1.zip"
fi
elif [[ $os == "windows" ]]; then
chrome_url="https://chromedriver.storage.googleapis.com/$LEAST_CHROME_VERSION/chromedriver_win32.zip"
fi
if curl -fsSL -o chromedriver.zip "$chrome_url" > /dev/null 2>&1; then
unzip -qq chromedriver.zip
rm chromedriver.zip
good "Chrome driver installed successfully."
else
bad "Your device architecture does not support chrome driver version $LEAST_CHROME_VERSION"
fi
}
function firefox_driver_install {
if [[ "$os" == "linux" ]]; then
firefox_local_version=$(firefox --version | cut -d " " -f 3 | cut -d "." -f 1,2)
elif [[ "$os" == "mac" ]]; then
firefox_local_version=$(/Applications/Firefox.app/Contents/MacOS/firefox -v | cut -d " " -f 3 | cut -d "." -f 1,2)
elif [[ "$os" == "windows" ]]; then
readonly current_path=`pwd`
if [[ "$cpu" == "64-bit" ]]; then
cd /mnt/c/Program\ Files/Mozilla\ Firefox
elif [[ "$cpu" == "32-bit" ]]; then
cd /mnt/c/Program\ Files\ \(x86\)/Mozilla\ Firefox
fi
firefox_local_version="$(cmd.exe /c "firefox -v | more" | cut -d " " -f 3 | cut -d "." -f 1,2 | tr -d '\r')"
cd $current_path
fi
geckodriver_versions=$(curl -fsSL https://github.com/mozilla/geckodriver/tags | grep '<a href="/mozilla/geckodriver/releases/tag/' | sed 's/.*href="\/\(.*\)">.*/\1/')
if [ $(bc <<< "$firefox_local_version > 90.0") -eq 1 ]; then
firefox_url="https://github.com/$(echo $geckodriver_versions | cut -d " " -f 1)"
elif [ $(bc <<< "$firefox_local_version > 79.0") -eq 1 ]; then
firefox_url="https://github.com/$(echo $geckodriver_versions | cut -d " " -f 2)"
elif [ $(bc <<< "$firefox_local_version >= 62.0") -eq 1 ]; then
firefox_url="https://github.com/$(echo $geckodriver_versions | cut -d " " -f 9)"
else
bad "Your Firefox version is not supported"
return 1
fi
firefox_drivers=`curl -fsSL $firefox_url | grep 'data-skip-pjax' | sed 's/^.*href="\/\(.*\)".*$/\1/' | sed 's/" rel="//'`
for i in $firefox_drivers; do
if [[ "$i" == *"linux"* ]] && [[ "$os" == "linux" ]]; then
if [[ "$i" == *"64"* ]] && [[ "$cpu" == "64-bit" ]]; then
firefox_url="https://github.com/$i"
break
elif [[ "$i" == *"32"* ]] && [[ "$cpu" == "32-bit" ]]; then
firefox_url="https://github.com/$i"
break
fi
elif [[ "$i" == *"macos"* ]] && [[ "$os" == "mac" ]]; then
if [[ "$i" == *"aarch64"* ]] && [[ "$cpu" == "M1" ]]; then
firefox_url="https://github.com/$i"
break
elif [[ $cpu == "64-bit" ]]; then
firefox_url="https://github.com/$i"
break
fi
elif [[ "$i" == *"win"* ]] && [[ "$os" == "windows" ]]; then
if [[ "$i" == *"64"* ]] && [[ "$cpu" == "64-bit" ]]; then
firefox_url="https://github.com/$i"
break
elif [[ "$i" == *"32"* ]] && [[ "$cpu" == "32-bit" ]]; then
firefox_url="https://github.com/$i"
break
fi
fi
done
if [[ "$firefox_url" == "" ]]; then
bad "Your device architecture does not support firefox driver"
fi
if [[ "$os" == "linux" ]] || [[ $os == "macOS" ]]; then
curl -fsSL -o geckodriver.tar.gz "$firefox_url"
tar -xzf geckodriver.tar.gz
rm geckodriver.tar.gz
elif [[ "$os" == "windows" ]]; then
curl -fsSL -o geckodriver.zip "$firefox_url"
unzip -qq geckodriver.zip
rm geckodriver.zip
fi
good "Firefox driver installed successfully."
}
function main {
get_os
get_cpu
get_package_manager
update_upgrade_packages
check_br
check_wget_or_curl
chrome_driver_install
firefox_driver_install
# internet_explorer_driver_install https://www.selenium.dev/downloads/
# opera_driver_install https://github.com/operasoftware/operachromiumdriver/releases
# edge_driver_install https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
}
main