Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·262 lines (252 loc) · 8.89 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·262 lines (252 loc) · 8.89 KB
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
#!/usr/bin/env bash
# DeepDive Installer
set -eu
: ${RELEASE:=v0.7.1} # the DeepDive release version to install
: ${PREFIX:=~/local} # the path to install deepdive
: ${INSTALLER_BRANCH:=${BRANCH:-v0.7.x}} # the branch from which the installer scripts should be downloaded
INSTALLER_HOME_URL=https://github.com/HazyResearch/deepdive/raw/"${INSTALLER_BRANCH}"/util/install
INSTALLER_HOME_DIR=$(dirname "$0")/install
# run the correct installer directly from GitHub if BRANCH is specified
[[ -z "${BRANCH:-}" || -n "${INSTALLER_REMOTE_EXEC:-}" ]] ||
INSTALLER_REMOTE_EXEC=true \
exec bash <(set -x; curl -fsSL "${INSTALLER_HOME_URL}.sh") "$@"
running_from_git=true; [[ -e "$INSTALLER_HOME_DIR"/../../.git ]] || running_from_git=false
has() { type "$@"; } &>/dev/null
error() {
if [ -t 1 ]; then
# on tty output, color errors in red
echo -ne '\033[31m'
echo "$@"
echo -ne '\033[0m'
else
echo "$@"
fi
false
} >&2
INSTALLER_TEMP_DIR=
init_INSTALLER_TEMP_DIR() {
# makes sure INSTALLER_TEMP_DIR points to a temporary directory
if ! [[ -d "$INSTALLER_TEMP_DIR" ]]; then
INSTALLER_TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}"/deepdive-installer.XXXXXXX)
trap "rm -rf $INSTALLER_TEMP_DIR" EXIT
fi
}
# common installers ###########################################################
# installs DeepDive's build dependencies
install__deepdive_build_deps() {
local deps=
deps=(
git
make
bzip2
unzip
jdk
)
error "Please make sure the following packages are available on your system: $(
printf '\n %s' "${deps[@]}")" ||
[[ ! -t 1 ]] || read -p "# Continue? " || true
}
# installs DeepDive's runtime dependencies
install__deepdive_runtime_deps() {
local deps=
deps=(
bash
coreutils
xargs
bc
gnuplot
jre
python
)
error "Please make sure the following packages are available on your system:$(
printf '\n %s' "${deps[@]}")" ||
[[ ! -t 1 ]] || read -p "# Continue? " || true
}
# fetches DeepDive source tree
install__deepdive_git_repo() {
$running_from_git ||
git clone --recursive --branch "$INSTALLER_BRANCH" https://github.com/HazyResearch/deepdive.git
}
# installs DeepDive from source by going through the full build
install_deepdive_from_source() {
# prepare fetching and building source
run_installer_for _deepdive_build_deps
# install DeepDive from source
if $running_from_git; then
cd "$INSTALLER_HOME_DIR"/../..
echo "# DeepDive source already at $PWD"
else
run_installer_for _deepdive_git_repo
cd deepdive
echo "# DeepDive source cloned at $PWD"
fi
make install PREFIX="$PREFIX"
# install runtime dependencies
run_installer_for _deepdive_runtime_deps
}
# installs DeepDive with a release binary
install_deepdive_from_release() {
# TODO allow overriding RELEASE interactively
local os=$(uname)
local tarball="deepdive-${RELEASE}-${os}.tar.gz"
local url="https://github.com/HazyResearch/deepdive/releases/download/${RELEASE}/$tarball"
(
# showing what is going on
set -x
rm -f "$tarball"
# download tarball
curl -fLRO "$url" || wget -N "$url"
# unpack tarball
mkdir -p "$PREFIX"
tar xzvf "$tarball" -C "$PREFIX"
) || return $?
echo
echo "DeepDive release $RELEASE has been installed at $PREFIX"
echo "Please add the following line to your ~/.bash_profile:"
echo " export PATH=\"$PREFIX/bin:\$PATH\""
}
# installs DeepDive with a release binary and runtime dependencies
install_deepdive() {
run_installer_for deepdive_from_release
run_installer_for _deepdive_runtime_deps
}
# installs DeepDive examples and tests
install_deepdive_examples_tests() {
local dest=deepdive-${RELEASE#v}
if [[ -s "$dest"/.downloaded ]]; then
echo "DeepDive examples and tests already downloaded at $(cd "$dest" && pwd)"
else
mkdir -p "$dest"
touch "$dest"/.downloaded
set -x
curl -fsSL https://github.com/HazyResearch/deepdive/archive/$RELEASE.tar.gz |
tar xvzf - -C . "$dest"/{examples,src/test/python,test,util/test}
date >"$dest"/.downloaded
fi
}
# runs tests against installed DeepDive
install_run_deepdive_tests() {
run_installer_for deepdive_examples_tests
set -x
PATH="$PREFIX/bin:$PATH" \
deepdive-${RELEASE#v}/test/test-installed.sh
}
################################################################################
# detect operating system
case $(uname) in
Linux)
if has apt-get && has debconf; then
# Ubuntu/Debian
os=Ubuntu
# TODO support other Linux distros
#elif [[ -e /etc/redhat-release ]]; then
# # CentOS/RedHat
# os=RedHat
else # unrecognized Linux distro
os=
# try to grab a Linux distro identifier
{
set -o pipefail
hint=$(lsb_release -i | cut -f2) ||
hint=$(head -1 /etc/redhat-release) ||
hint= # give up finding hint
} 2>/dev/null
error "WARNING: Unsupported GNU/Linux distribution${hint:+: $hint}"
fi
;;
Darwin)
# Mac OS X
os=Mac
;;
*)
# unsupported OS
os=
error "WARNING: Unsupported Operating System: $(uname)"
esac ||
error "To build and install DeepDive correctly on your system, see:" ||
error " http://deepdive.stanford.edu/doc/advanced/developer.html#build-test" ||
error "Beware that the following installer options may not work." ||
true
echo "### DeepDive installer${os:+ for $os}"
# load OS-specific install scripts located at install/install.*.sh
# each script defines bash functions whose names start with `install_`.
source_script() {
local script=$1
if $running_from_git && [[ -e "$INSTALLER_HOME_DIR/$script" ]]; then
source "$INSTALLER_HOME_DIR/$script"
else
# may be this script is run as a one-liner, get script from GitHub
#source <(set -x; curl -fsSL "$INSTALLER_HOME_URL/$script") "$@"
# XXX using a workaround since source with process substitution has problem in bash 3 (OS X default)
# See: https://bugzilla.altlinux.org/show_bug.cgi?id=7475
init_INSTALLER_TEMP_DIR
local script_path="$INSTALLER_TEMP_DIR/$script"
mkdir -p "$(dirname "$script_path")"
(set -x; curl -fsSL "$INSTALLER_HOME_URL/$script" >"$script_path")
source "$script_path" "$@"
fi
}
source_os_script() { source_script install."$os"."$1".sh; }
[[ -z "$os" ]] || source_script install."$os".sh
# run selected installers, either interactively or via command-line arguments
list_installer_names() {
local show_only=${1:-visible}
# find installer names from all defined install_* functions
declare -F | sed 's/^declare -f //; /^install_/!d; s/^install_//' |
# unless the first argument is 'all', hide installers whose name begins with underscore
case ${show_only:-visible} in
all) cat ;;
*) sed '/^_/d'
esac
}
run_installer_for() {
(
# XXX running this in a context where set -e (errexit) is ignored, e.g., in
# if, while, ||, or && command lists (except the last one) is problematic
# since the install_* functions will continue running even upon errors.
set +e; (set -e; false; true); local errexit_effective=$?; set -e
if [[ $errexit_effective -eq 0 ]]; then
read line file <<<$(caller)
error "INSTALLER INTERNAL ERROR: $file:$line: "'run_installer_for cannot be run in a context where `set -e` is ignored.'
return 1
fi
# run installer by name
local name=$1
local install_func="install_$name"
if type "$install_func" &>/dev/null; then
echo "## Starting installation for $name"
# isolate install function in a subshell
set +e; (set -e +u; "$install_func"); local c=$?; set -e
if [[ $c -eq 0 ]]; then
echo "## Finished installation for $name"
else
error "## Failed installation for $name" || true
return $c
fi
else
error "No such installer: $name"
fi
)
}
if [[ $# -eq 0 ]]; then
if [[ -t 0 ]]; then
# ask user what to install if input is a tty
PS3="# Select what to install (enter for all options, q to quit, or a number)? "
set +e # dont abort the select loop on installer error
select option in $(list_installer_names); do
[[ -n "$option" ]] || break
run_installer_for "$option"
done
else
# otherwise, show options
echo "Specify what to install as command-line arguments:"
list_installer_names all
# TODO show what each installer does
false
fi
else
# what to install specified via command line arguments
for name; do
run_installer_for "$name"
done
fi