on master help sign in
utils/filtron.sh: add script to install filtron middleware (apache)
af2f58fMarkus Heiser
utils/filtron.sh+84−14
@@ -13,11 +13,8 @@ FILTRON_ETC="/etc/filtron"
13
13
14FILTRON_RULES="$FILTRON_ETC/rules.json"
14FILTRON_RULES="$FILTRON_ETC/rules.json"
15
15
16−# shellcheck disable=SC2034
17FILTRON_API="127.0.0.1:4005"
16FILTRON_API="127.0.0.1:4005"
18−# shellcheck disable=SC2034
19FILTRON_LISTEN="127.0.0.1:4004"
17FILTRON_LISTEN="127.0.0.1:4004"
20−# shellcheck disable=SC2034
21FILTRON_TARGET="127.0.0.1:8888"
18FILTRON_TARGET="127.0.0.1:8888"
22
19
23SERVICE_NAME="filtron"
20SERVICE_NAME="filtron"
@@ -32,6 +29,8 @@ GO_ENV="${SERVICE_HOME}/.go_env"
32GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
29GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
33GO_TAR=$(basename "$GO_PKG_URL")
30GO_TAR=$(basename "$GO_PKG_URL")
34
31
32+APACHE_SITE="searx.conf"
33+
35# shellcheck disable=SC2034
34# shellcheck disable=SC2034
36CONFIG_FILES=(
35CONFIG_FILES=(
37 "${FILTRON_RULES}"
36 "${FILTRON_RULES}"
@@ -39,7 +38,7 @@ CONFIG_FILES=(
39)
38)
40
39
41# ----------------------------------------------------------------------------
40# ----------------------------------------------------------------------------
42−usage(){
41+usage() {
43# ----------------------------------------------------------------------------
42# ----------------------------------------------------------------------------
44
43
45 # shellcheck disable=SC1117
44 # shellcheck disable=SC1117
@@ -73,7 +72,7 @@ EOF
73 [ ! -z ${1+x} ] && echo -e "$1"
72 [ ! -z ${1+x} ] && echo -e "$1"
74}
73}
75
74
76−main(){
75+main() {
77 rst_title "$SERVICE_NAME" part
76 rst_title "$SERVICE_NAME" part
78
77
79 local _usage="ERROR: unknown or missing $1 command $2"
78 local _usage="ERROR: unknown or missing $1 command $2"
@@ -140,6 +139,10 @@ install_all() {
140 wait_key
139 wait_key
141 install_service
140 install_service
142 wait_key
141 wait_key
142+ if apache_is_installed; then
143+ install_apache_site
144+ wait_key
145+ fi
143}
146}
144
147
145remove_all() {
148remove_all() {
@@ -151,10 +154,22 @@ remove_all() {
151 wait_key
154 wait_key
152}
155}
153
156
157+filtron_is_available() {
158+ curl --insecure "http://${FILTRON_LISTEN}" &>/dev/null
159+}
160+
161+api_is_available() {
162+ curl --insecure "http://${FILTRON_API}" &>/dev/null
163+}
164+
165+target_is_available() {
166+ curl --insecure "http://${FILTRON_TARGET}" &>/dev/null
167+}
168+
154install_service() {
169install_service() {
155 rst_title "Install System-D Unit ${SERVICE_NAME}.service" section
170 rst_title "Install System-D Unit ${SERVICE_NAME}.service" section
156 echo
171 echo
157− install_template ${SERVICE_SYSTEMD_UNIT} root root 644
172+ install_template "${SERVICE_SYSTEMD_UNIT}" root root 644
158 wait_key
173 wait_key
159 activate_service
174 activate_service
160}
175}
@@ -167,19 +182,19 @@ remove_service() {
167 rm "${SERVICE_SYSTEMD_UNIT}" 2>&1 | prefix_stdout
182 rm "${SERVICE_SYSTEMD_UNIT}" 2>&1 | prefix_stdout
168}
183}
169
184
170−activate_service () {
185+activate_service() {
171 rst_title "Activate $SERVICE_NAME (service)" section
186 rst_title "Activate $SERVICE_NAME (service)" section
172 echo
187 echo
173− tee_stderr <<EOF | bash 2>&1 | prefix_stdout
188+ tee_stderr <<EOF | bash 2>&1
174systemctl enable $SERVICE_NAME.service
189systemctl enable $SERVICE_NAME.service
175systemctl restart $SERVICE_NAME.service
190systemctl restart $SERVICE_NAME.service
176EOF
191EOF
177− tee_stderr <<EOF | bash 2>&1 | prefix_stdout
192+ tee_stderr <<EOF | bash 2>&1
178systemctl status $SERVICE_NAME.service
193systemctl status $SERVICE_NAME.service
179EOF
194EOF
180}
195}
181
196
182−deactivate_service () {
197+deactivate_service() {
183 rst_title "De-Activate $SERVICE_NAME (service)" section
198 rst_title "De-Activate $SERVICE_NAME (service)" section
184 echo
199 echo
185 tee_stderr <<EOF | bash 2>&1 | prefix_stdout
200 tee_stderr <<EOF | bash 2>&1 | prefix_stdout
@@ -188,6 +203,10 @@ systemctl disable $SERVICE_NAME.service
188EOF
203EOF
189}
204}
190
205
206+user_is_available() {
207+ sudo -i -u "$SERVICE_USER" echo \$HOME &>/dev/null
208+}
209+
191assert_user() {
210assert_user() {
192 rst_title "user $SERVICE_USER" section
211 rst_title "user $SERVICE_USER" section
193 echo
212 echo
@@ -228,7 +247,11 @@ interactive_shell(){
228
247
229_service_prefix=" |$SERVICE_USER| "
248_service_prefix=" |$SERVICE_USER| "
230
249
250+go_is_available() {
251+ sudo -i -u "$SERVICE_USER" which go &>/dev/null
252+}
253+
231−install_go(){
254+install_go() {
232 rst_title "Install Go in user's HOME" section
255 rst_title "Install Go in user's HOME" section
233
256
234 rst_para "download and install go binary .."
257 rst_para "download and install go binary .."
@@ -248,6 +271,10 @@ which go >/dev/null && go version && echo "congratulations -- Go installation O
248EOF
271EOF
249}
272}
250
273
274+filtron_is_installed() {
275+ [[ -f $SERVICE_HOME/go-apps/bin/filtron ]]
276+}
277+
251install_filtron() {
278install_filtron() {
252 rst_title "Install filtron in user's ~/go-apps" section
279 rst_title "Install filtron in user's ~/go-apps" section
253 echo
280 echo
@@ -265,12 +292,48 @@ go get -v -u github.com/asciimoo/filtron
265EOF
292EOF
266}
293}
267
294
268−show_service () {
295+show_service() {
269 rst_title "service status & log"
296 rst_title "service status & log"
270 echo
297 echo
271− systemctl status filtron.service
298+
299+ apache_is_installed && info_msg "Apache is installed."
300+
301+ if user_is_available; then
302+ info_msg "service account $SERVICE_USER available."
303+ else
304+ err_msg "service account $SERVICE_USER not available!"
305+ fi
306+ if go_is_available; then
307+ info_msg "~$SERVICE_USER: go is installed"
308+ else
309+ err_msg "~$SERVICE_USER: go is not installed"
310+ fi
311+ if filtron_is_installed; then
312+ info_msg "~$SERVICE_USER: filtron app is installed"
313+ else
314+ err_msg "~$SERVICE_USER: filtron app is not installed!"
315+ fi
316+ if api_is_available; then
317+ info_msg "API available at: http://${FILTRON_API}"
318+ else
319+ err_msg "API not available at: http://${FILTRON_API}"
320+ fi
321+ if filtron_is_available; then
322+ info_msg "Filtron listening on: http://${FILTRON_LISTEN}"
323+ else
324+ err_msg "Filtron does not listening on: http://${FILTRON_LISTEN}"
325+ fi
326+ if target_is_available; then
327+ info_msg "Filtron's target is available at: http://${FILTRON_TARGET}"
328+ else
329+ err_msg "Filtron's target is not available at: http://${FILTRON_TARGET}"
330+ fi
331+
332+ wait_key
272 echo
333 echo
334+ systemctl --no-pager -l status filtron.service
335+ echo
273− read -r -s -n1 -t 5 -p "// use CTRL-C to stop monitoring the log"
336+ read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
274 echo
337 echo
275 while true; do
338 while true; do
276 trap break 2
339 trap break 2
@@ -279,6 +342,13 @@ show_service () {
279 return 0
342 return 0
280}
343}
281
344
345+install_apache_site() {
346+ rst_title "Install Apache site $APACHE_SITE" section
347+ echo
348+ err_msg "not yet implemented (${APACHE_SITE})"; return 42
349+ # apache_install_site "${APACHE_SITE}"
350+}
351+
282# ----------------------------------------------------------------------------
352# ----------------------------------------------------------------------------
283main "$@"
353main "$@"
284# ----------------------------------------------------------------------------
354# ----------------------------------------------------------------------------
utils/lib.sh+53
@@ -359,6 +359,59 @@ install_template() {
359 done
359 done
360}
360}
361
361
362+# Apache
363+# ------
364+
365+# FIXME: Arch Linux & RHEL should be added
366+
367+if [[ -z "${APACHE_SITES_AVAILABE}" ]]; then
368+ APACHE_SITES_AVAILABE="/etc/apache2/sites-available"
369+fi
370+
371+apache_is_installed() {
372+ (command -v apachectl \
373+ && command -v a2ensite \
374+ && command -v a2dissite ) &>/dev/null
375+}
376+
377+apache_reload() {
378+
379+ info_msg "reload apache .."
380+ echo
381+ sudo -H apachectl configtest
382+ sudo -H service apache2 force-reload
383+}
384+
385+apache_install_site() {
386+
387+ # usage: apache_install_site [--no-eval] <mysite.conf>
388+
389+ local no_eval=""
390+ local CONF="$1"
391+
392+ if [[ "$1" == "--no-eval" ]]; then
393+ no_eval=$1; shift
394+ fi
395+
396+ # shellcheck disable=SC2086
397+ install_template $no_eval "${APACHE_SITES_AVAILABE}/${CONF}" root root 644
398+
399+ apache_enable_site "${CONF}"
400+ apache_reload
401+ info_msg "installed apache site: ${CONF}"
402+}
403+
404+apache_enable_site() {
405+ info_msg "enable apache site $1 .."
406+ sudo -H a2ensite -q "$1"
407+ apache_reload
408+}
409+
410+apache_dissable_site() {
411+ info_msg "disable apache site $1 .."
412+ sudo -H a2dissite -q "$1"
413+ apache_reload
414+}
362
415
363# uWSGI
416# uWSGI
364# -----
417# -----
utils/searx.sh+17−5
@@ -15,7 +15,6 @@ SERVICE_USER="${SERVICE_NAME}"
15SERVICE_GROUP="${SERVICE_USER}"
15SERVICE_GROUP="${SERVICE_USER}"
16SERVICE_HOME="/home/${SERVICE_USER}"
16SERVICE_HOME="/home/${SERVICE_USER}"
17
17
18−# shellcheck disable=SC2034
19SEARX_URL="127.0.0.1:8888"
18SEARX_URL="127.0.0.1:8888"
20
19
21SEARX_GIT_URL="https://github.com/asciimoo/searx.git"
20SEARX_GIT_URL="https://github.com/asciimoo/searx.git"
@@ -34,6 +33,8 @@ SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
34SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(uname -n)}"
33SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(uname -n)}"
35SEARX_UWSGI_APP="searx.ini"
34SEARX_UWSGI_APP="searx.ini"
36
35
36+APACHE_SITE="searx.conf"
37+
37# shellcheck disable=SC2034
38# shellcheck disable=SC2034
38CONFIG_FILES=(
39CONFIG_FILES=(
39 "${uWSGI_SETUP}/apps-available/${SEARX_UWSGI_APP}"
40 "${uWSGI_SETUP}/apps-available/${SEARX_UWSGI_APP}"
@@ -175,9 +176,12 @@ install_all() {
175 err_msg "URL http://$SEARX_URL not available, check searx & uwsgi setup!"
176 err_msg "URL http://$SEARX_URL not available, check searx & uwsgi setup!"
176 fi
177 fi
177 wait_key
178 wait_key
179+ if apache_is_installed; then
180+ install_apache_site
181+ wait_key
182+ fi
178
183
179 # ToDo ...
184 # ToDo ...
180− # install_apache_site
181 # test_public_searx
185 # test_public_searx
182 # info_msg "searX --> https://${SEARX_APACHE_DOMAIN}${SEARX_APACHE_URL}"
186 # info_msg "searX --> https://${SEARX_APACHE_DOMAIN}${SEARX_APACHE_URL}"
183
187
@@ -428,11 +432,12 @@ EOF
428 uWSGI_restart
432 uWSGI_restart
429}
433}
430
434
431−
432show_service() {
435show_service() {
433 rst_title "service status & log"
436 rst_title "service status & log"
434 echo
437 echo
435
438
439+ apache_is_installed && info_msg "Apache is installed."
440+
436 if user_is_available; then
441 if user_is_available; then
437 info_msg "service account $SERVICE_USER available."
442 info_msg "service account $SERVICE_USER available."
438 else
443 else
@@ -468,9 +473,9 @@ show_service() {
468 enable_debug
473 enable_debug
469 _debug_on=1
474 _debug_on=1
470 fi
475 fi
471− wait_key
472 echo
476 echo
473− systemctl status uwsgi.service
477+ systemctl --no-pager -l status uwsgi.service
478+ echo
474 read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
479 read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
475 echo
480 echo
476 while true; do
481 while true; do
@@ -485,6 +490,13 @@ show_service() {
485 return 0
490 return 0
486}
491}
487
492
493+install_apache_site() {
494+ rst_title "Install Apache site $APACHE_SITE" section
495+ echo
496+ err_msg "not yet implemented (${APACHE_SITE})"; return 42
497+ # apache_install_site "${APACHE_SITE}"
498+}
499+
488# ----------------------------------------------------------------------------
500# ----------------------------------------------------------------------------
489main "$@"
501main "$@"
490# ----------------------------------------------------------------------------
502# ----------------------------------------------------------------------------