-
Notifications
You must be signed in to change notification settings - Fork 34
/
install-chromedriver.sh
210 lines (191 loc) · 6.11 KB
/
install-chromedriver.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
#!/bin/bash
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
# determine_chrome_version
if uname -a | grep Darwin >/dev/null 2>&1; then
echo "System detected as MacOS"
if [ -f "/usr/local/bin/google-chrome-stable" ]; then
CHROME_VERSION="$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version)"
else
CHROME_VERSION="$(/Applications/Google\ Chrome\ Beta.app/Contents/MacOS/Google\ Chrome\ Beta --version)"
fi
PLATFORM=mac64
elif grep Alpine /etc/issue >/dev/null 2>&1; then
apk update >/dev/null 2>&1 &&
apk add --no-cache chromium-chromedriver >/dev/null
# verify version
echo "$(chromedriver --version) has been installed to $(command -v chromedriver)"
exit 0
else
CHROME_VERSION="$(google-chrome --version)"
PLATFORM=linux64
fi
CHROME_VERSION_STRING="$(echo "$CHROME_VERSION" | sed 's/.*Google Chrome //' | sed 's/.*Chromium //')"
# shellcheck disable=SC2001
CHROME_VERSION_MAJOR="$(echo "$CHROME_VERSION_STRING" | sed "s/\..*//" )"
echo "Chrome version major is $CHROME_VERSION_MAJOR"
# print Chrome version
echo "Installed version of Google Chrome is $CHROME_VERSION_STRING"
# determine chromedriver release
CHROMEDRIVER_RELEASE="${CHROME_VERSION_STRING%%.*}"
CHROME_RELEASE="${CHROMEDRIVER_RELEASE}"
if [[ $CHROME_RELEASE -lt 70 ]]; then
# https://sites.google.com/a/chromium.org/chromedriver/downloads
# https://chromedriver.storage.googleapis.com/2.40/notes.txt
case $CHROME_RELEASE in
69)
CHROMEDRIVER_VERSION="2.44"
;;
68)
CHROMEDRIVER_VERSION="2.42"
;;
67)
CHROMEDRIVER_VERSION="2.41"
;;
66)
CHROMEDRIVER_VERSION="2.40"
;;
65)
CHROMEDRIVER_VERSION="2.38"
;;
64)
CHROMEDRIVER_VERSION="2.37"
;;
63)
CHROMEDRIVER_VERSION="2.36"
;;
62)
CHROMEDRIVER_VERSION="2.35"
;;
61)
CHROMEDRIVER_VERSION="2.34"
;;
60)
CHROMEDRIVER_VERSION="2.33"
;;
59)
CHROMEDRIVER_VERSION="2.32"
;;
58)
CHROMEDRIVER_VERSION="2.31"
;;
57)
CHROMEDRIVER_VERSION="2.29"
;;
56)
CHROMEDRIVER_VERSION="2.29"
;;
55)
CHROMEDRIVER_VERSION="2.28"
;;
54)
CHROMEDRIVER_VERSION="2.27"
;;
53)
CHROMEDRIVER_VERSION="2.26"
;;
52)
CHROMEDRIVER_VERSION="2.24"
;;
51)
CHROMEDRIVER_VERSION="2.23"
;;
50)
CHROMEDRIVER_VERSION="2.22"
;;
49)
CHROMEDRIVER_VERSION="2.22"
;;
48)
CHROMEDRIVER_VERSION="2.21"
;;
47)
CHROMEDRIVER_VERSION="2.21"
;;
46)
CHROMEDRIVER_VERSION="2.21"
;;
45)
CHROMEDRIVER_VERSION="2.20"
;;
44)
CHROMEDRIVER_VERSION="2.20"
;;
43)
CHROMEDRIVER_VERSION="2.20"
;;
*)
echo "Sorry, Google Chrome/Chromium version 43 or newer is required to use ChromeDriver"
exit 1
;;
esac
elif [[ $CHROME_RELEASE -lt 115 ]]; then
CHROMEDRIVER_VERSION=$(curl --silent --show-error --location --fail --retry 3 \
"https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROMEDRIVER_RELEASE")
else
# shellcheck disable=SC2001
CHROMEDRIVER_VERSION=$(echo $CHROME_VERSION | sed 's/[^0-9.]//g')
fi
# installation check
if command -v chromedriver >/dev/null 2>&1; then
if chromedriver --version | grep "$CHROMEDRIVER_VERSION" >/dev/null 2>&1; then
echo "ChromeDriver $CHROMEDRIVER_VERSION is already installed"
exit 0
else
echo "A different version of ChromeDriver is installed ($(chromedriver --version)); removing it"
$SUDO rm -f "$(command -v chromedriver)"
fi
fi
# download chromedriver
if [[ $CHROME_RELEASE -lt 115 ]]; then
curl --silent --show-error --location --fail --retry 3 \
--output chromedriver_$PLATFORM.zip \
"http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_$PLATFORM.zip"
else
MATCHING_CHROMEDRIVER_URL_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROMEDRIVER_VERSION/linux64/chromedriver-linux64.zip')
echo $MATCHING_CHROMEDRIVER_URL_RESPONSE
if [[ $MATCHING_CHROMEDRIVER_URL_RESPONSE == 404 ]]; then
echo "Matching Chrome Driver Version 404'd, falling back to first matching major version."
CHROMEDRIVER_VERSION=$( curl https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone.json | jq ".milestones.\"$CHROME_VERSION_MAJOR\".version" | sed 's/\"//g')
echo "New ChromeDriver version to be installed: $CHROMEDRIVER_VERSION"
fi
echo "$CHROMEDRIVER_VERSION will be installed"
if [[ $PLATFORM == "linux64" ]]; then
PLATFORM="linux64"
curl --silent --show-error --location --fail --retry 3 \
--output chromedriver_$PLATFORM.zip \
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROMEDRIVER_VERSION/linux64/chromedriver-linux64.zip"
elif [[ $PLATFORM == "mac64" ]]; then
PLATFORM="mac-x64"
curl --silent --show-error --location --fail --retry 3 \
--output chromedriver_$PLATFORM.zip \
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROMEDRIVER_VERSION/mac-x64/chromedriver-mac-x64.zip"
else
PLATFORM="win64"
curl --silent --show-error --location --fail --retry 3 \
--output chromedriver_$PLATFORM.zip \
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROMEDRIVER_VERSION/win64/chromedriver-win64.zip"
fi
fi
# setup chromedriver installation
if command -v yum >/dev/null 2>&1; then
yum install -y unzip >/dev/null 2>&1
fi
unzip "chromedriver_$PLATFORM.zip" >/dev/null 2>&1
rm -rf "chromedriver_$PLATFORM.zip"
if [[ $CHROME_RELEASE -gt 114 ]]; then
mv "chromedriver-$PLATFORM" chromedriver
$SUDO mv chromedriver/chromedriver "$ORB_PARAM_DRIVER_INSTALL_DIR"
rm -rf "chromedriver"
else
$SUDO mv chromedriver "$ORB_PARAM_DRIVER_INSTALL_DIR"
fi
$SUDO chmod +x "$ORB_PARAM_DRIVER_INSTALL_DIR/chromedriver"
# test/verify version
if chromedriver --version | grep "$CHROMEDRIVER_VERSION" >/dev/null 2>&1; then
echo "$(chromedriver --version) has been installed to $(command -v chromedriver)"
readonly base_dir="${CIRCLE_WORKING_DIRECTORY/\~/$HOME}"
rm -f "${base_dir}/LICENSE.chromedriver"
else
echo "Something went wrong; ChromeDriver could not be installed"
exit 1
fi