@@ -11,6 +11,11 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
1111
1212FILTRON_ETC="/etc/filtron"
1313
14+FILTRON_RULES="$FILTRON_ETC/rules.json"
15+FILTRON_API="127.0.0.1:4005"
16+FILTRON_LISTEN="127.0.0.1:4004"
17+FILTRON_TARGET="127.0.0.1:8888"
18+
1419SERVICE_NAME="filtron"
1520SERVICE_USER="${SERVICE_NAME}"
1621SERVICE_HOME="/home/${SERVICE_USER}"
@@ -23,6 +28,11 @@ GO_ENV="${SERVICE_HOME}/.go_env"
2328GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
2429GO_TAR=$(basename "$GO_PKG_URL")
2530
31+CONFIG_FILES=(
32+ "${FILTRON_RULES}"
33+ "${SERVICE_SYSTEMD_UNIT}"
34+)
35+
2636# ----------------------------------------------------------------------------
2737usage(){
2838# ----------------------------------------------------------------------------
@@ -37,10 +47,16 @@ usage:
3747 $(basename "$0") remove [all]
3848 $(basename "$0") activate [server]
3949 $(basename "$0") deactivate [server]
40−
41−shell - start interactive shell with user ${SERVICE_USER}
42−install user - add service user '$SERVICE_USER' at $SERVICE_HOME
43−
50+ $(basename "$0") show [server]
51+
52+shell
53+ start interactive shell from user ${SERVICE_USER}
54+show server
55+ show server status and log
56+install / remove
57+ all - complete setup of filtron server
58+install user
59+ add service user '$SERVICE_USER' at $SERVICE_HOME
4460EOF
4561 [ ! -z ${1+x} ] && echo -e "$1"
4662}
@@ -58,6 +74,14 @@ main(){
5874 sudo_or_exit
5975 interactive_shell
6076 ;;
77+ show)
78+ case $2 in
79+ server)
80+ sudo_or_exit
81+ show_server
82+ ;;
83+ *) usage "$_usage"; exit 42;;
84+ esac ;;
6185 install)
6286 sudo_or_exit
6387 case $2 in
@@ -91,21 +115,27 @@ main(){
91115install_all() {
92116 rst_title "Install $SERVICE_NAME (service)"
93117 assert_user
118+ wait_key
94119 install_go
120+ wait_key
95121 install_filtron
122+ wait_key
96123 install_server
124+ wait_key
97125}
98126
99127remove_all() {
100128 rst_title "De-Install $SERVICE_NAME (service)"
101129 remove_server
130+ wait_key
102131 remove_user
103− rm -rf "$FILTRON_ETC"
132+ rm -r "$FILTRON_ETC" 2>&1 | prefix_stdout
104133 wait_key
105134}
106135
107136install_server() {
108− rst_title "Install System-D Unit ${SERVICE_NAME}.service ..." section
137+ rst_title "Install System-D Unit ${SERVICE_NAME}.service" section
138+ echo
109139 install_template ${SERVICE_SYSTEMD_UNIT} root root 644
110140 wait_key
111141 activate_server
@@ -116,12 +146,12 @@ remove_server() {
116146 return
117147 fi
118148 deactivate_server
119− rm "${SERVICE_SYSTEMD_UNIT}"
149+ rm "${SERVICE_SYSTEMD_UNIT}" 2>&1 | prefix_stdout
120150}
121151
122−
123152activate_server () {
124153 rst_title "Activate $SERVICE_NAME (service)" section
154+ echo
125155 tee_stderr <<EOF | bash 2>&1 | prefix_stdout
126156systemctl enable $SERVICE_NAME.service
127157systemctl restart $SERVICE_NAME.service
@@ -129,7 +159,6 @@ EOF
129159 tee_stderr <<EOF | bash 2>&1 | prefix_stdout
130160systemctl status $SERVICE_NAME.service
131161EOF
132− wait_key
133162}
134163
135164deactivate_server () {
@@ -139,7 +168,6 @@ deactivate_server () {
139168systemctl stop $SERVICE_NAME.service
140169systemctl disable $SERVICE_NAME.service
141170EOF
142− wait_key
143171}
144172
145173assert_user() {
@@ -168,18 +196,18 @@ EOF
168196remove_user() {
169197 rst_title "Drop $SERVICE_USER HOME" section
170198 if ask_yn "Do you really want to drop $SERVICE_USER home folder?"; then
171− userdel -r -f "$SERVICE_USER"
199+ userdel -r -f "$SERVICE_USER" 2>&1 | prefix_stdout
172200 else
173201 rst_para "Leave HOME folder $(du -sh "$SERVICE_HOME") unchanged."
174202 fi
175203}
176204
177205interactive_shell(){
178− echo "// exit with STRG-D"
206+ echo "// exit with CTRL-D"
179207 sudo -H -u ${SERVICE_USER} -i
180208}
181209
182−_service_prefix="$SERVICE_USER@$(hostname) -->| "
210+_service_prefix=" |$SERVICE_USER| "
183211
184212install_go(){
185213 rst_title "Install Go in user's HOME" section
@@ -199,14 +227,29 @@ EOF
199227! which go >/dev/null && echo "Go Installation not found in PATH!?!"
200228which go >/dev/null && go version && echo "congratulations -- Go installation OK :)"
201229EOF
202− wait_key
203230}
204231
205232install_filtron() {
206− tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" | prefix_stdout "$_service_prefix"
207−go get -v -u github.com/asciimoo/filtron 2>&1
233+ rst_title "Install filtron in user's ~/go-apps" section
234+ echo
235+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_service_prefix"
236+go get -v -u github.com/asciimoo/filtron
208237EOF
209− install_template "$FILTRON_ETC/rules.json" root root 644
238+ install_template --no-eval "$FILTRON_RULES" root root 644
239+}
240+
241+show_server () {
242+ rst_title "server status & log"
243+ echo
244+ systemctl status filtron.service
245+ echo
246+ read -s -n1 -t 5 -p "// use CTRL-C to stop monitoring the log"
247+ echo
248+ while true; do
249+ trap break 2
250+ journalctl -f -u filtron
251+ done
252+ return 0
210253}
211254
212255# ----------------------------------------------------------------------------