-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomer7.sh
More file actions
393 lines (327 loc) · 12.9 KB
/
homer7.sh
File metadata and controls
393 lines (327 loc) · 12.9 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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/bin/bash
# Single touch install Homer7.7 with DB on the box.
# Support for Ubuntu 20.04/22.04 as well as Debian 10, 11 & 12
# You need to be root to run this.
sudo apt-get install -y libluajit-5.1-common libluajit-5.1-dev lsb-release wget curl git
[[ "$TRACE" ]] && { set -x; set -o functrace; }
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
logfile="/tmp/$(basename $0).$$.log"
exec > >(tee -ia $logfile)
exec 2> >(tee -ia $logfile >&2)
trap 'exit 1' TERM
my_pid=$$
# HOMER Options, defaults
# Change here for external DB and select no for postgres
DB_USER="homer_user"
DB_PASS=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64 | sed 's/[=\+//]//g')
DB_HOST="localhost"
LISTEN_PORT="9060"
CHRONOGRAF_LISTEN_PORT="8888"
INSTALL_INFLUXDB=""
OS=`uname -s`
HOME_DIR=$HOME
CURRENT_DIR=`pwd`
ARCH=`uname -m`
#### NO CHANGES BELOW THIS LINE!
VERSION=7.7
SETUP_ENTRYPOINT=""
OS=""
DISTRO=""
DISTRO_VERSION=""
######################################################################
#
# Start of function definitions
#
######################################################################
is_root_user() {
# Function to check that the effective user id of the user running
# the script is indeed that of the root user (0)
if [[ $EUID != 0 ]]; then
return 1
fi
return 0
}
have_commands() {
# Function to check if we can find the command(s) passed to us
# in the systems PATH
local cmd_list="$1"
local -a not_found=()
for cmd in $cmd_list; do
command -v $cmd >/dev/null 2>&1 || not_found+=("$cmd")
done
if [[ ${#not_found[@]} == 0 ]]; then
# All commands found
return 0
else
# Something not found
return 1
fi
}
locate_cmd() {
# Function to return the full path to the cammnd passed to us
# Make sure it exists on the system first or else this exits
# the script execution
local cmd="$1"
local valid_cmd=""
# valid_cmd=$(hash -t $cmd 2>/dev/null)
valid_cmd=$(command -v $cmd 2>/dev/null)
if [[ ! -z "$valid_cmd" ]]; then
echo "$valid_cmd"
else
echo "HALT: Please install package for command '$cmd'"
/bin/kill -s TERM $my_pid
fi
return 0
}
is_supported_os() {
# Function to see if the OS is a supported type, the 1st
# parameter passed should be the OS type to check. The bash
# shell has a built in variable "OSTYPE" which should be
# sufficient for a start
local os_type=$1
case "$os_type" in
linux* ) OS="Linux"
minimal_command_list="lsb_release wget curl git"
if ! have_commands "$minimal_command_list"; then
echo "ERROR: You need the following minimal set of commands installed:"
echo ""
echo " $minimal_command_list"
echo ""
exit 1
fi
detect_linux_distribution # Supported OS, Check if supported distro.
return ;;
* ) return 1 ;; # Unsupported OS
esac
}
detect_linux_distribution() {
# Function to see if a specific linux distribution is supported by this script
# If it is supported then the global variable SETUP_ENTRYPOINT is set to the
# function to be executed for the system setup
local cmd_lsb_release=$(locate_cmd "lsb_release")
local distro_name=$($cmd_lsb_release -si)
local distro_version=$($cmd_lsb_release -sr)
DISTRO="$distro_name"
DISTRO_VERSION="$distro_version"
case "$distro_name" in
Ubuntu ) case "$distro_version" in
20.04* | 22.04* ) SETUP_ENTRYPOINT="setup_debian"
return 0 ;; # Suported Distribution
* ) return 1 ;; # Unsupported Distribution
esac
;;
Debian ) case "$distro_version" in
10* | 11* | 12* ) SETUP_ENTRYPOINT="setup_debian"
return 0 ;; # Suported Distribution
* ) return 1 ;; # Unsupported Distribution
esac
;;
* ) return 1 ;; # Unsupported Distribution
esac
}
check_status() {
# Function to check and do something with the return code of some command
local return_code="$1"
if [[ $return_code != 0 ]]; then
echo "HALT: Return code of command was '$return_code', aborting."
echo "Please check the log above and correct the issue."
exit 1
fi
}
banner_start() {
# This is the banner displayed at the start of script execution
clear;
echo "**************************************************************"
echo " "
echo " ,;;;;;, HOMER SIP CAPTURE (http://sipcapture.org) "
echo " ;;;;;;;;;. Single-Node Auto-Installer (beta $VERSION)"
echo " ;;;;;;;;;;;;; "
echo " ;;;; ;;; ;;;; <--------------- INVITE --------------- "
echo " ;;;; ;;; ;;;; --------------- 200 OK ---------------> "
echo " ;;;; ... ;;;; "
echo " ;;;; ;;;; WARNING: This installer is intended for "
echo " ;;;; ;;; ;;;; dedicated/vanilla OS setups without any "
echo " ,;;; ;;; ;;;; customization and with default settings "
echo " ;;;;;;;;;;;;; "
echo " :;;;;;;;;;; THIS SCRIPT IS PROVIDED AS-IS, USE AT "
echo " ^;;;;;;;^ YOUR *OWN* RISK, REVIEW LICENSE & DOCS "
echo " "
echo "**************************************************************"
echo;
}
banner_end() {
# This is the banner displayed at the end of script execution
local cmd_ip=$(locate_cmd "ip")
local cmd_head=$(locate_cmd "head")
local cmd_awk=$(locate_cmd "awk")
local my_primary_ip=$($cmd_ip route get 8.8.8.8 | $cmd_head -1 | grep -Po '(\d+\.){3}\d+' | tail -n1)
echo "*************************************************************"
echo " ,;;;;, "
echo " ;;;;;;;;. Congratulations! HOMER has been installed!"
echo " ;;;;;;;;;;;; "
echo " ;;;; ;; ;;;; <--------------- INVITE --------------- "
echo " ;;;; ;; ;;;; --------------- 200 OK ---------------> "
echo " ;;;; .. ;;;; "
echo " ;;;; ;;;; Your system should be now ready to rock!"
echo " ;;;; ;; ;;;; Please verify/complete the configuration "
echo " ,;;; ;; ;;;; files generated by the installer below. "
echo " ;;;;;;;;;;;; "
echo " :;;;;;;;;; THIS SCRIPT IS PROVIDED AS-IS, USE AT "
echo " ;;;;;;;; YOUR *OWN* RISK, REVIEW LICENSE & DOCS "
echo " "
echo "*************************************************************"
echo
echo " * Configuration Files:"
echo " '/usr/local/homer/etc/webapp_config.json'"
echo " '/etc/heplify-server.toml'"
echo
echo " * Start/stop HOMER Application Server:"
echo " 'systemctl start|stop homer-app'"
echo
echo " * Start/stop HOMER SIP Capture Server:"
echo " 'systemctl start|stop heplify-server'"
echo
echo " * Start/stop HOMER SIP Capture Agent:"
echo " 'systemctl start|stop heplify'"
echo
echo " * Access HOMER UI:"
echo " http://$my_primary_ip:443"
echo " [default: admin/sipcapture]"
echo
echo " * Send HEP/EEP Encapsulated Packets to:"
echo " hep://$my_primary_ip:$LISTEN_PORT"
echo
echo " * Prometheus Metrics URL:"
echo " http://$my_primary_ip:9096/metrics"
echo
if [[ "$INSTALL_INFLUXDB" =~ y|yes|Y|Yes|YES ]] ; then
echo " * Access InfluxDB UI:"
echo " http://$my_primary_ip:$CHRONOGRAF_LISTEN_PORT"
echo
fi
echo
echo "**************************************************************"
echo
echo " IMPORTANT: Do not forget to send Homer node some traffic! ;) "
echo " For our capture agents, visit http://github.com/sipcapture "
echo " For more help and information visit: http://sipcapture.org "
echo
echo "**************************************************************"
echo " Installer Log saved to: $logfile "
echo
}
start_app() {
# This is the main app
banner_start
if ! is_root_user; then
echo "ERROR: You must be the root user. Exiting..." 2>&1
echo 2>&1
exit 1
fi
if ! is_supported_os "$OSTYPE"; then
echo "ERROR:"
echo "Sorry, this Installer does not support your OS yet!"
echo "Please follow instructions in the HOW-TO for manual installation & setup"
echo "available at http://sipcapture.org"
echo
exit 1
else
unalias cp 2>/dev/null
$SETUP_ENTRYPOINT
banner_end
fi
exit 0
}
create_postgres_user_database(){
cwd=$(pwd)
cd /tmp
sudo -u postgres psql -c "CREATE DATABASE homer_config;"
sudo -u postgres psql -c "CREATE DATABASE homer_data;"
sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '$DB_PASS';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE homer_config to homer_user;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE homer_data to homer_user;"
cd $cwd
}
install_homer(){
local cmd_curl=$(locate_cmd "curl")
local cmd_sed=$(locate_cmd "sed")
echo "Installing Homer-App"
if [ -f /etc/debian_version ]; then
local cmd_apt_get=$(locate_cmd "apt-get")
$cmd_curl -s https://packagecloud.io/install/repositories/qxip/sipcapture/script.deb.sh | sudo bash
$cmd_sed -i -e "s/jammy/focal/g" /etc/apt/sources.list.d/qxip_sipcapture.list
$cmd_apt_get update
$cmd_apt_get install homer-app heplify-server -y
fi
$cmd_sed -i -e "s/homer_user/$DB_USER/g" /usr/local/homer/etc/webapp_config.json
$cmd_sed -i -e "s/homer_password/$DB_PASS/g" /usr/local/homer/etc/webapp_config.json
$cmd_sed -i "s/9080/443/g" /usr/local/homer/etc/webapp_config.json
local cmd_homerapp=$(locate_cmd "homer-app")
$cmd_homerapp -create-table-db-config
$cmd_homerapp -populate-table-db-config
$cmd_sed -i -e "s/DBUser\s*=\s*\"postgres\"/DBUser = \"$DB_USER\"/g" /etc/heplify-server.toml
$cmd_sed -i -e "s/DBPass\s*=\s*\"\"/DBPass = \"$DB_PASS\"/g" /etc/heplify-server.toml
$cmd_sed -i -e "s/PromAddr\s*=\s*\"\"/PromAddr = \"0.0.0.0:9096\"/g" /etc/heplify-server.toml
sudo systemctl enable homer-app
sudo systemctl restart homer-app
sudo systemctl status homer-app
sudo systemctl enable heplify-server
sudo systemctl restart heplify-server
sudo systemctl status heplify-server
}
# DB setup
setup_influxdb(){
if [ -f /etc/debian_version ]; then
echo "DEBIAN Platform detected!"
sudo apt-get install -y apt-transport-https
wget -q https://repos.influxdata.com/influxdata-archive_compat.key
echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c influxdata-archive_compat.key' | sha256sum -c && cat influxdata-archive_compat.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list
echo "Installing TICK stack ..."
sudo apt-get update && sudo apt-get install influxdb kapacitor chronograf telegraf -y
yes | cp $CURRENT_DIR/telegraf.conf /etc/telegraf/telegraf.conf
sudo systemctl restart influxdb
sudo systemctl restart kapacitor
sudo systemctl restart chronograf
sudo systemctl enable influxdb
sudo systemctl enable kapacitor
sudo systemctl enable chronograf
sudo systemctl enable telegraf
sudo systemctl restart telegraf
echo "done!"
fi
}
# Debian/Ubuntu install latest postgresql from apt
setup_debian() {
local base_pkg_list="software-properties-common make cmake gcc g++ dirmngr sudo python3-dev net-tools"
local cmd_apt_get=$(locate_cmd "apt-get")
local cmd_wget=$(locate_cmd "wget")
local cmd_apt_key=$(locate_cmd "apt-key")
local cmd_service=$(locate_cmd "systemctl")
local cmd_curl=$(locate_cmd "curl")
local cmd_wget=$(locate_cmd "wget")
$cmd_apt_get update && $cmd_apt_get upgrade -y
$cmd_apt_get install -y postgresql postgresql-contrib
$cmd_service daemon-reload
$cmd_service enable postgresql
$cmd_service restart postgresql
create_postgres_user_database
install_homer
printf "Would you like to install influxdb and chronograf? [y/N]: "
read INSTALL_INFLUXDB
case "$INSTALL_INFLUXDB" in
"y"|"yes"|"Y"|"Yes"|"YES") setup_influxdb;;
*) echo "...... [ Exiting ]"; echo;;
esac
}
######################################################################
#
# End of function definitions
#
######################################################################
######################################################################
#
# Start of main script
#
######################################################################
[[ "$0" == "$BASH_SOURCE" ]] && start_app