-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·99 lines (78 loc) · 2.68 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
#!/usr/bin/env bash
install() {
# dependencies
for gem in "${gems[@]}"; do
is_gem_installed $gem || sudo gem install $gem
done
[ -d "$CONF_DIR" ] || sudo mkdir "$CONF_DIR"
[ -d "$SCHEMAS_DIR" ] || sudo mkdir "$SCHEMAS_DIR"
[ -d "$INSTALL_DIR" ] || mkdir "$INSTALL_DIR"
src_conf="$(realpath "share/etc/$CONF_FILE")"
src_exec="$(realpath src/server/cli/provision-engine-server)"
if [[ $setup_mode == "copy" ]]; then
# config
[ -f "$CONF_PATH" ] || sudo cp "$src_conf" "$CONF_PATH"
for file in $SCHEMAS; do
[ -f "$CONF_DIR/${file}" ] || sudo cp "$(realpath "share/schemas/${file}")" "$SCHEMAS_DIR"
done
# executable
[ -f "$EXEC_PATH" ] || sudo cp "$src_exec" "$EXEC_PATH"
# libraries
for file in $MODULES; do
[ -f "$INSTALL_DIR/${file}" ] || cp "$(realpath "src/server/${file}")" "${INSTALL_DIR}"
done
elif [[ $setup_mode == "symlink" ]]; then
# config
[ -L "$CONF_PATH" ] || [ -f "$CONF_PATH" ] || sudo ln -s "$src_conf" "$CONF_PATH"
for file in $SCHEMAS; do
[ -L "$SCHEMAS_DIR/${file}" ] || sudo ln -s "$(realpath "share/schemas/${file}")" "$SCHEMAS_DIR"
done
# executable
[ -L "$EXEC_PATH" ] || sudo ln -s "$src_exec" "$EXEC_PATH"
# libraries
for file in $MODULES; do
[ -L "$INSTALL_DIR/${file}" ] || ln -s "$(realpath "src/server/${file}")" "${INSTALL_DIR}"
done
fi
}
postinstall() {
echo "provision engine installed at ${INSTALL_DIR}"
echo "run engine with ${EXEC_PATH} start/stop"
}
clean() {
if [[ $setup_mode == "purge" ]]; then
[ -d $CONF_DIR ] && sudo rm -r $CONF_DIR
[ -d "$SCHEMAS_DIR" ] && sudo rm -rf "$SCHEMAS_DIR"
for gem in "${gems[@]}"; do
remove_orphan_gem "$gem"
done
else
echo "${CONF_DIR} will not be deleted as part of the cleanup process"
echo "The ruby gems: $(printf "%s " "${gems[@]}") are required by the provision engine"
fi
[ -f "$EXEC_PATH" ] || [ -L "$EXEC_PATH" ] && sudo rm $EXEC_PATH
[ -d "$INSTALL_DIR" ] && rm -rf "$INSTALL_DIR"
}
is_gem_installed() {
sudo gem list -i "$1" >/dev/null 2>&1
}
remove_orphan_gem() {
sudo gem uninstall -a --abort-on-dependent "$1" >/dev/null 2>&1
}
CONF_DIR="/etc/provision-engine"
CONF_FILE="engine.conf"
CONF_PATH="${CONF_DIR}/${CONF_FILE}"
SCHEMAS_DIR="/etc/provision-engine/schemas"
SCHEMAS="serverless_runtime.json error.json config.json"
EXEC_FILE="provision-engine-server"
EXEC_PATH="/usr/local/bin/${EXEC_FILE}"
INSTALL_DIR="/opt/provision-engine"
MODULES="client.rb configuration.rb log.rb server.rb runtime.rb error.rb function.rb"
gems=("opennebula" "sinatra -v 3.1.0" "logger -v 1.6.0" "json-schema -v 4.1.1") # check requires on server.rb
action="${1:-"install"}"
setup_mode="${2:-"symlink"}"
if [ "$action" = "clean" ]; then
clean
else
install && postinstall
fi