This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
install.sh
executable file
·308 lines (250 loc) · 7.38 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
#!/usr/bin/env sh
{ # this ensures the entire script is downloaded #
set -e
# Get the script directory
SCRIPT_SOURCE="${0}"
while [ -h "$SCRIPT_SOURCE" ]; do # resolve $SCRIPT_SOURCE until the file is no longer a symlink
SCRIPT_DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" && pwd )"
SCRIPT_SOURCE="$(readlink "$SCRIPT_SOURCE")"
[[ $SCRIPT_SOURCE != /* ]] && SCRIPT_SOURCE="$SCRIPT_DIR/$SCRIPT_SOURCE" # if $SCRIPT_SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" && pwd )"
# Check if stdout is a terminal...
if [ -t 1 ]; then
# See if it supports colors...
ncolors=$(tput colors)
if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
bold="$(tput bold)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput sgr0)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
fi
fi
# Assume pretty verbose output
VERBOSITY=3
# Define a bunch of pretty output helpers
output () {
lvl="$1"
fmt="$2"
text="$3"
if [ $VERBOSITY -ge $lvl ]; then
printf -- "$fmt" "$text"
fi
}
msg () {
output 1 "%s\n" "$1"
}
step () {
output 2 "--> %s\n" "$1"
}
substep () {
output 3 "--> %s" "$1"
}
substep_ok() {
output 3 "${green}OK${normal}\n" ""
}
substep_skip() {
output 3 "${yellow}OK${normal}\n" "$1"
}
die() {
printf "${red}FAIL${normal}"
printf "\n\n "
printf "$1"
printf "\n\n"
exit 1
}
python_version="python2.7"
quark_install_root="${HOME}/.quark"
installation_source=
install_from_dir () {
if [ -n "$installation_source" ]; then
echo "you can only install from one source at a time" >&2
exit 1
fi
installation_source="$1"
extra="$2"
note="$3"
if [ "$installation_source" == "-" ]; then
installation_source="${SCRIPT_DIR}"
fi
text="Installing from ${installation_source}"
if [ -n "$note" ]; then
text="Installing ${note} from ${installation_source}"
fi
msg "$text"
if [ -n "$extra" ]; then
download () {
piparg="${extra} ${installation_source}"
}
else
download () {
piparg="${installation_source}"
}
fi
}
while getopts ':d:e:t:qv' opt; do
case $opt in
d) install_from_dir "$OPTARG" "" ""
;;
e) install_from_dir "$OPTARG" "-e" "(in place)"
;;
t) quark_install_root="$OPTARG"
echo "Installing to ${quark_install_root}"
;;
:) echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
q) VERBOSITY=$(( $VERBOSITY - 1 ))
if [ $VERBOSITY -lt 0 ]; then VERBOSITY=0; fi
;;
v) VERBOSITY=$(( $VERBOSITY + 1 ))
;;
\?) echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ -z "$installation_source" ]; then
if [ -n "$1" ]; then
branch="$1"
url="https://github.com/datawire/quark/archive/${branch}.zip"
msg "Installing from ${url}"
download() {
msg "Downloading..."
work=$(mktemp -d ${TMPDIR:-/tmp}/quark-install.XXXXXXXX)
safename=$(echo "$branch" | tr '/' '-')
CURLVERBOSITY="-#"
if [ $VERBOSITY -lt 1 ]; then
CURLVERBOSITY="-s -S"
elif [ $VERBOSITY -gt 2 ]; then
CURLVERBOSITY=
fi
curl $CURLVERBOSITY -L ${url} > ${work}/quark-${safename}.zip
if unzip -q ${work}/quark-${safename}.zip -d ${work} >> ${work}/install.log 2>&1; then
if [ -d ${work}/quark-${safename} ]; then
piparg=${work}/quark-${safename}
else
# If your tag is "v1.0.133" the unzipped folder will be
# "quark-1.0.133", without the leading "v". Thanks,
# GitHub.
piparg=${work}/quark-$(echo "$safename" | tr -d 'v')
fi
else
die "Unable to download from ${url}\n check in ${work}/install.log for details."
fi
}
else
msg "Installing from PyPI"
download() {
piparg=datawire-quark
}
fi
fi
required_commands () {
for cmd in $*; do
substep "Checking for ${cmd}: "
loc=$(command -v ${cmd} || true)
if [ -n "${loc}" ]; then
substep_ok
else
die "Cannot find ${cmd}, please install and try again."
fi
done
}
is_quark_on_path() {
substep "Checking for quark on \$PATH: "
if command -v quark >/dev/null 2>&1 ; then
die "Quark is already available on the \$PATH, please (re)move to proceed."
else
substep_ok
fi
}
is_quarkc_importable() {
substep "Checking for 'quarkc' python module pollution: "
set +e
python -c "import quarkc" >/dev/null 2>&1
result=$?
set -e
if [ "$result" -eq 0 ]; then
die "Python module 'quarkc' is present, please remove to proceed."
else
substep_ok
fi
}
is_quark_installed () {
substep "Checking for old quark: "
if [ -e ${quark_install_root} ]; then
die "Install directory exists at '${quark_install_root}', please (re)move to proceed."
else
substep_ok
fi
}
step "Performing installation environment sanity checks..."
required_commands curl unzip fgrep python virtualenv
is_quarkc_importable
is_quark_on_path
is_quark_installed
download
step "Creating Datawire Quark installation directory..."
virtualenv -q --python ${python_version} ${quark_install_root}/venv
step "Installing Datawire Quark..."
. ${quark_install_root}/venv/bin/activate
pip --quiet install ${piparg}
deactivate
mkdir ${quark_install_root}/bin
mv ${quark_install_root}/venv/bin/quark* ${quark_install_root}/bin
conf="${quark_install_root}/config.sh"
cat > ${conf} <<EOF
export PATH=\${PATH}:${quark_install_root}/bin
EOF
step "Installed!"
msg
msg " Quark has been installed into '${quark_install_root}'. You may want to"
msg " add '${quark_install_root}/bin' to your PATH. You can do this by adding"
msg " '. ${conf}' to your .bashrc."
msg
if tty -s && [ $VERBOSITY -gt 0 ]; then
step "Configuring bash..."
# The || true here is a workaround for osx, apparently when you are
# piping to a shell, read will just fail
read -p "--> Type YES to modify ~/.bashrc: " answer || true
if [ -n "${answer}" ] && [ ${answer} == "YES" ]; then
substep "Modifying .bashrc: "
if [ -f ~/.bashrc ] && fgrep -q ${conf} ~/.bashrc; then
substep_skip "(already modified)"
else
cat >> ~/.bashrc <<EOF
# Add quark to the path
. ${conf}
EOF
substep_ok
fi
step "Configured!"
else
step "Opted out!"
fi
fi
if [ -n "${branch}" ] && [ "${branch}" != "master" ]; then
cloneargs=" -b ${branch}"
else
cloneargs=""
fi
msg
msg " Quark is now installed. You may want to run '. ${conf}'"
msg " in any existing shells."
msg
msg " To get started, try:"
msg
msg " git clone${cloneargs} [email protected]:datawire/quark.git"
msg " cd quark/examples"
msg
} # this ensures the entire script is downloaded #