-
Notifications
You must be signed in to change notification settings - Fork 3
/
bootstrap_chromedriver.sh
executable file
·145 lines (129 loc) · 3.84 KB
/
bootstrap_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
#!/usr/bin/env bash
# This is meant as a developer tool so that developers can easily install chromedriver to their system for
# testing locally. This can also be used inside automation scripts to install the chromedriver in a production
# environment.
# You can set CHROMEDRIVER_DIR in order to customize
# the output location of the installed binary, and CHROMEDRIVER_DIST to customize the appropriate
# driver distribution; distributions should be provided in the format "linux64", "mac64", "win32," etc.
# By default CHROMEDRIVER_DIR is assumed to be the virtualenv bin directory, and the distribution is assumed to be
# linux64.
#
# To install in your virtualenv on a mac (a developer use case):
# CHROMEDRIVER_DIST=mac64 ./bootstrap_chromedriver.sh
#
# To install in /usr/local/bin on linux (a VM/container use case):
# CHROMEDRIVER_DIR=/usr/local/bin CHROMEDRIVER_DIST=linux64 sudo ./bootstrap_chromedriver.sh
function print_help {
cat <<EOF
Use: bootstrap_chromedriver.sh [OPTIONS]
Installs the latest chromedriver instance from Google. If no options are provided,
it will be installed to your poetry environment ( if it is set up).
You can specify the destination with '-d', if that doesn't suit your needs.
Options:
--dest / -d The location to store the chromedriver binary.
If not provided, will be installed to the poetry
environment if exists. Otherwise, an error will be raised.
--dist mac64 / linux64 -- If not provided, will be derived from your
environment
-h, --help Show this message and exit
-g, --debug Show commands as they are executing
EOF
}
# Initialize some globals
dest=
dist=
DEBUG=
CHROMEDRIVER_VERSION=
function parse_args {
while (( $# ))
do
case $1 in
--dest|-d)
shift
dest="$1"
;;
--dist)
shift
dist="$1"
;;
--help|-h)
print_help
exit 0
;;
--debug|-g)
DEBUG=1
;;
*)
echo "Invalid Option: $1"
print_help
exit 1
;;
esac
shift
done
}
function configure_dest {
if [[ -z "${dest}" ]]
then
echo "No destination provided. Checking poetry status."
if ! type poetry > /dev/null
then
echo "No --dest provided, and no poetry installation detected."
return 1
fi
path=$(poetry env list --full-path | tail -n 1 | cut -f1 -d' ')
if [[ "$?" != "0" ]] || [[ -z "${path}" ]]
then
echo "No --dest provided, and no poetry environment exists."
return 1
fi
echo "Installing to poetry environment."
dest="${path}/bin"
fi
if ! [[ -d "${dest}" ]]
then
echo "Creating destination: ${dest}"
mkdir -p ${dest}
fi
}
function configure_dist {
if [[ -z "${dist}" ]]
then
if [[ "$(uname)" == "Darwin" ]]
then
dist=mac64
else
dist=linux64
fi
fi
}
function chromedriver_version {
if [[ -z "${CHROMEDRIVER_VERSION}" ]]
then
export CHROMEDRIVER_VERSION=$(curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
fi
echo "${CHROMEDRIVER_VERSION}"
}
function chromedriver_url {
local version="$(chromedriver_version)"
local filename="chromedriver_${dist}.zip"
echo "https://chromedriver.storage.googleapis.com/${version}/${filename}"
}
function install_chromedriver {
local dest_filename="${dest}/chromedriver"
local tmp_filename="/tmp/chromedriver.zip"
echo "Installing chromedriver $(chromedriver_version) for ${dist} to ${dest}"
curl -s "$(chromedriver_url)" > "${tmp_filename}"
if rm "${dest_filename}" > /dev/null
then
echo "Removed previous installation of chromedriver from destination"
fi
unzip "${tmp_filename}" -d "${dest}" > /dev/null
chmod 755 "${dest_filename}"
rm "${tmp_filename}"
}
set -e
parse_args $@
configure_dest
configure_dist
install_chromedriver