-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·173 lines (123 loc) · 3.51 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
#!/bin/bash
#variables
VERSION="1.0.3"
SOURCE=$(dirname ${BASH_SOURCE[0]})
TEMPLATES="$SOURCE/templates";
SHOW_HELP=false
INSTALL_CUBE=true
DEFAULT_NODE_PREFIX="/usr"
NODE_PREFIX=$DEFAULT_NODE_PREFIX
DEFAULT_COLLECTOR_CONFIG="$SOURCE/config/collector-config.js"
COLLECTOR_CONFIG=$DEFAULT_COLLECTOR_CONFIG
DEFAULT_EVALUATOR_CONFIG="$SOURCE/config/evaluator-config.js"
EVALUATOR_CONFIG=$DEFAULT_EVALUATOR_CONFIG
#parse options
for i in "$@"
do
case $i in
-h|--help)
SHOW_HELP=true
;;
-n|--no-cube)
INSTALL_CUBE=false
;;
-p=*|--node-prefix=*)
NODE_PREFIX="${i#*=}"
;;
-c=*|--collector-config=*)
COLLECTOR_CONFIG="${i#*=}"
;;
-e=*|--evaluator-config=*)
EVALUATOR_CONFIG="${i#*=}"
;;
esac
done
# display help
if [ "$SHOW_HELP" = true ]; then
cat << EOF
Cube-daemons installer v${VERSION} by Luciano Mammino
https://github.com/lmammino/cube-daemons
Usage:
sudo ./installer.sh [-h|--help] [-n|--no-cube] [-p|--node-prefix=PREFIX] [-c|--collector-config=COLLECTOR_CONFIG] [-e|--evaluator-config=EVALUATOR_CONFIG]
options:
-h|--help Display this help
-n|--no-cube Avoid installing cube (useful if you already installed it)
-p|--node-prefix=VALUE specify a custom node prefix (default "${DEFAULT_NODE_PREFIX}")
-c|--collector-config=VALUE specify a custom config file for the collector (default "${DEFAULT_COLLECTOR_CONFIG}")
-e|--evaluator-config=VALUE specify a custom config file for the evaluator (default "${DEFAULT_EVALUATOR_CONFIG}")
EOF
exit 0;
fi
# Banner
cat << EOF
_
___ _ _| |__ ___
/ __| | | | _ \ / _ \
| (__| |_| | |_) | __/
\___|\__,_|_.__/ \___|
Cube-daemons installer v${VERSION} by Luciano Mammino
https://github.com/lmammino/cube-daemons
EOF
#should be run as sudo
if [ "$UID" -ne 0 ]; then
echo "WARNING: it seems that the installer has not be run as root. It may not work as intended."
fi
#install cube
if [ "$INSTALL_CUBE" = true ]; then
cat << EOF
---------------
Installing cube
---------------
EOF
npm install --global lmammino/cube
fi
#create cube user and group
cat << EOF
------------------
Creating cube user
------------------
EOF
useradd -r -s /bin/false cube
#create cube run dir (for pid files)
cat << EOF
-----------------------------
Creating /var/run/cube folder
-----------------------------
EOF
mkdir -p /var/run/cube
#copying configuration
if [ "$INSTALL_CUBE" = true ]; then
cat << EOF
--------------------
Copying config files
--------------------
EOF
mv $NODE_PREFIX/lib/node_modules/cube/bin/collector-config.js $NODE_PREFIX/lib/node_modules/cube/bin/collector-config.js.original
mv $NODE_PREFIX/lib/node_modules/cube/bin/evaluator-config.js $NODE_PREFIX/lib/node_modules/cube/bin/evaluator-config.js.original
cp $COLLECTOR_CONFIG $NODE_PREFIX/lib/node_modules/cube/bin/collector-config.js
cp $EVALUATOR_CONFIG $NODE_PREFIX/lib/node_modules/cube/bin/evaluator-config.js
fi
#copying scripts
cat << EOF
--------------------------
Copying start/stop scripts
--------------------------
EOF
sed -e "s;%NODE_PREFIX%;$NODE_PREFIX;g" $TEMPLATES/cube-collector > /etc/init.d/cube-collector
sed -e "s;%NODE_PREFIX%;$NODE_PREFIX;g" $TEMPLATES/cube-evaluator > /etc/init.d/cube-evaluator
chmod +x /etc/init.d/cube-collector /etc/init.d/cube-evaluator
update-rc.d cube-collector defaults
update-rc.d cube-evaluator defaults
#running daemons
cat << EOF
---------------
Running daemons
---------------
EOF
/etc/init.d/cube-collector start
/etc/init.d/cube-evaluator start
# Exit
cat << EOF
Done.
EOF
exit 0