on master help sign in
utils/morty.sh: add script to install morty result proxy

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commita4437c47ac0bd22cd7f5aaa8e7895cdd8e93a317 authorMarkus Heiser <markus.heiser@darmarit.de> dateSun 2 Feb 2020, 18:14 (7 years ago) parent709ac51
7 files changed+506−49
utils/dot_config+11−3 utils/filtron.sh+25−18 utils/lib.sh+15−13 utils/morty.sh+382 utils/searx.sh+21−15 utils/templates/etc/apache2/sites-available/morty.conf+23 utils/templates/lib/systemd/system/morty.service+29
utils/dot_config+11−3
@@ -1,9 +1,17 @@
11# -*- coding: utf-8; mode: sh -*-
22# SPDX-License-Identifier: AGPL-3.0-or-later
33#
4−# environment used by utils scripts like filtron.sh or searx.sh
5−#
4+# This environment is used by ./utils scripts like filtron.sh or searx.sh. The
5+# default values are *most flexible* and *best maintained*, you normally not
6+# need to change them. Before you change any value here you have to uninstall
7+# any previous installation. It is recommended to backup your changes simply by
8+# adding them to you local brand (git branch).
69
7−# the public URL of the searx instance
10+# The public URL of the searx instance
811PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}"
912PUBLIC_HOST="${PUBLIC_HOST:-$(echo "$PUBLIC_URL" | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')}"
13+
14+# Run all services by one account, but be aware that removing discrete
15+# components might conflict! **experimental**
16+#
17+# SERVICE_USER=service_account42
utils/filtron.sh+25−18
@@ -24,9 +24,11 @@ FILTRON_LISTEN="127.0.0.1:4004"
2424FILTRON_TARGET="127.0.0.1:8888"
2525
2626SERVICE_NAME="filtron"
27−SERVICE_USER="${SERVICE_NAME}"
27+SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
2828SERVICE_HOME="/home/${SERVICE_USER}"
2929SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
30+# shellcheck disable=SC2034
31+SERVICE_GROUP="${SERVICE_USER}"
3032
3133# shellcheck disable=SC2034
3234SERVICE_GROUP="${SERVICE_USER}"
@@ -52,7 +54,7 @@ usage() {
5254 # shellcheck disable=SC1117
5355 cat <<EOF
5456
55−usage:
57+usage::
5658
5759 $(basename "$0") shell
5860 $(basename "$0") install [all|user]
@@ -64,12 +66,11 @@ usage:
6466 $(basename "$0") option [debug-on|debug-off]
6567 $(basename "$0") apache [install|remove]
6668
67−
6869shell
6970 start interactive shell from user ${SERVICE_USER}
7071install / remove
71− all: complete setup of filtron service
72− user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
72+ :all: complete setup of filtron service
73+ :user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
7374update filtron
7475 Update filtron installation of user ${SERVICE_USER}
7576activate service
@@ -80,12 +81,11 @@ inspect service
8081 show service status and log
8182option
8283 set one of the available options
83−apache
84− install: apache site with a reverse proxy (ProxyPass)
85− remove: apache site ${APACHE_FILTRON_SITE}
84+apache : ${PUBLIC_URL}
85+ :install: apache site with a reverse proxy (ProxyPass)
86+ :remove: apache site ${APACHE_FILTRON_SITE}
8687
87−If needed change the environment variable PUBLIC_URL of your WEB service in the
88−${DOT_CONFIG#"$REPO_ROOT/"} file:
88+If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
8989
9090 PUBLIC_URL : ${PUBLIC_URL}
9191 PUBLIC_HOST : ${PUBLIC_HOST}
@@ -203,8 +203,9 @@ remove_all() {
203203It goes without saying that this script can only be used to remove
204204installations that were installed with this script."
205205
206− systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
207− wait_key
206+ if ! systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then
207+ return 42
208+ fi
208209 drop_service_account "${SERVICE_USER}"
209210 rm -r "$FILTRON_ETC" 2>&1 | prefix_stdout
210211 if service_is_available "${PUBLIC_URL}"; then
@@ -231,7 +232,7 @@ export PATH=\$PATH:\$HOME/local/go/bin:\$GOPATH/bin
231232EOF
232233 echo "Environment $GO_ENV has been setup."
233234
234− tee_stderr <<EOF | sudo -i -u $SERVICE_USER
235+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER"
235236grep -qFs -- 'source $GO_ENV' ~/.profile || echo 'source $GO_ENV' >> ~/.profile
236237EOF
237238}
@@ -241,10 +242,12 @@ filtron_is_installed() {
241242 [[ -f $SERVICE_HOME/go-apps/bin/filtron ]]
242243}
243244
245+_svcpr=" |${SERVICE_USER}| "
246+
244247install_filtron() {
245248 rst_title "Install filtron in user's ~/go-apps" section
246249 echo
247− tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_service_prefix"
250+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr"
248251go get -v -u github.com/asciimoo/filtron
249252EOF
250253 install_template --no-eval "$FILTRON_RULES" root root 644
@@ -253,7 +256,7 @@ EOF
253256update_filtron() {
254257 rst_title "Update filtron" section
255258 echo
256− tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_service_prefix"
259+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr"
257260go get -v -u github.com/asciimoo/filtron
258261EOF
259262}
@@ -301,12 +304,14 @@ EOF
301304 err_msg "Filtron does not listening on: http://${FILTRON_LISTEN}"
302305 fi
303306
304− if ! service_is_available ""http://${FILTRON_TARGET}"" ; then
307+ if service_is_available ""http://${FILTRON_TARGET}"" ; then
305308 info_msg "Filtron's target is available at: http://${FILTRON_TARGET}"
306309 fi
307310
308311 if ! service_is_available "${PUBLIC_URL}"; then
309312 err_msg "Public service at ${PUBLIC_URL} is not available!"
313+ echo -e "${_Green}stop with [${_BCyan}CTRL-C${_Green}] or .."
314+ wait_key
310315 fi
311316
312317 local _debug_on
@@ -316,15 +321,17 @@ EOF
316321 fi
317322
318323 echo
319− systemctl --no-pager -l status filtron.service
324+ systemctl --no-pager -l status "${SERVICE_NAME}"
320325 echo
326+
327+ info_msg "public URL --> ${PUBLIC_URL}"
321328 # shellcheck disable=SC2059
322329 printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
323330 read -r -s -n1 -t 2
324331 echo
325332 while true; do
326333 trap break 2
327− journalctl -f -u filtron
334+ journalctl -f -u "${SERVICE_NAME}"
328335 done
329336
330337 if [[ $_debug_on == 1 ]]; then
utils/lib.sh+15−13
@@ -112,9 +112,9 @@ rst_title() {
112112 # usage: rst_title <header-text> [part|chapter|section]
113113
114114 case ${2-chapter} in
115− part) printf "\n${_BGreen}${1//?/=}\n$1\n${1//?/=}${_creset}\n";;
116− chapter) printf "\n${_BGreen}${1}\n${1//?/=}${_creset}\n";;
117− section) printf "\n${_BGreen}${1}\n${1//?/-}${_creset}\n";;
115+ part) printf "\n${_BGreen}${1//?/=}\n${_BCyan}${1}${_BGreen}\n${1//?/=}${_creset}\n";;
116+ chapter) printf "\n${_BCyan}${1}\n${_BGreen}${1//?/=}${_creset}\n";;
117+ section) printf "\n${_BCyan}${1}\n${_BGreen}${1//?/-}${_creset}\n";;
118118 *)
119119 err_msg "invalid argument '${2}' in line $(caller)"
120120 return 42
@@ -169,7 +169,9 @@ ask_yn() {
169169 local _t=$3
170170 [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
171171 [[ ! -z $_t ]] && _t="-t $_t"
172− case "${2}" in
172+ case "${FORCE_SELECTION:-${2}}" in
173+ Y) return ${EXIT_YES} ;;
174+ N) return ${EXIT_NO} ;;
173175 Yn)
174176 local exit_val=${EXIT_YES}
175177 local choice="[${_BGreen}YES${_creset}/no]"
@@ -229,7 +231,7 @@ tee_stderr () {
229231prefix_stdout () {
230232 # usage: <cmd> | prefix_stdout [prefix]
231233
232− local prefix=" | "
234+ local prefix="${_BYellow}-->|${_creset}"
233235
234236 if [[ ! -z $1 ]] ; then prefix="${_BYellow}$1${_creset}"; fi
235237
@@ -433,7 +435,7 @@ install_template() {
433435 ;;
434436 "interactiv shell")
435437 echo "// edit ${dst} to your needs"
436− echo "// exit with ${_BCyan}CTRL-D${_creset}"
438+ echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
437439 sudo -H -u "${owner}" -i
438440 $DIFF_CMD "${dst}" "${template_file}"
439441 echo
@@ -487,14 +489,14 @@ install_go() {
487489
488490 # usage: install_go "${GO_PKG_URL}" "${GO_TAR}" "${SERVICE_USER}"
489491
490− local _service_prefix=" |${3}| "
492+ local _svcpr=" |${3}| "
491493
492494 rst_title "Install Go in user's HOME" section
493495
494496 rst_para "download and install go binary .."
495497 cache_download "${1}" "${2}"
496498
497− tee_stderr 0.1 <<EOF | sudo -i -u "${3}" | prefix_stdout "$_service_prefix"
499+ tee_stderr 0.1 <<EOF | sudo -i -u "${3}" | prefix_stdout "$_svcpr"
498500echo \$PATH
499501echo \$GOPATH
500502mkdir -p \$HOME/local
@@ -533,7 +535,7 @@ interactive_shell(){
533535
534536 # usage: interactive_shell "${SERVICE_USER}"
535537
536− echo "// exit with ${_BCyan}CTRL-D${_creset}"
538+ echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
537539 sudo -H -u "${1}" -i
538540}
539541
@@ -558,8 +560,8 @@ systemd_remove_service() {
558560
559561 # usage: systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
560562
561− if ! ask_yn "Do you really want to deinstall ${1}?"; then
562− return
563+ if ! ask_yn "Do you really want to deinstall systemd unit ${1}?"; then
564+ return 42
563565 fi
564566 systemd_deactivate_service "${1}"
565567 rm "${2}" 2>&1 | prefix_stdout
@@ -845,14 +847,14 @@ git_clone() {
845847
846848 if [[ -d "${dest}" ]] ; then
847849 info_msg "already cloned: $dest"
848− tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " |$user| "
850+ tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " |$user| "
849851cd "${dest}"
850852git checkout -m -B "$branch" --track "$remote/$branch"
851853git pull --all
852854EOF
853855 else
854856 info_msg "clone into: $dest"
855− tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " |$user| "
857+ tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " |$user| "
856858mkdir -p "$(dirname "$dest")"
857859cd "$(dirname "$dest")"
858860git clone --branch "$branch" --origin "$remote" "$url" "$(basename "$dest")"
utils/morty.shnew file+382
@@ -0,0 +1,382 @@
1+#!/usr/bin/env bash
2+# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
3+# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+# shellcheck source=utils/lib.sh
6+source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
7+source_dot_config
8+
9+# ----------------------------------------------------------------------------
10+# config
11+# ----------------------------------------------------------------------------
12+
13+PUBLIC_URL_PATH_MORTY="/morty"
14+PUBLIC_URL_MORTY="$(dirname ${PUBLIC_URL})${PUBLIC_URL_PATH_MORTY}"
15+
16+MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}"
17+MORTY_TIMEOUT=5
18+
19+SERVICE_NAME="morty"
20+SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
21+SERVICE_HOME="/home/${SERVICE_USER}"
22+SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
23+# shellcheck disable=SC2034
24+SERVICE_GROUP="${SERVICE_USER}"
25+SERVICE_ENV_DEBUG=false
26+
27+GO_ENV="${SERVICE_HOME}/.go_env"
28+GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
29+GO_TAR=$(basename "$GO_PKG_URL")
30+
31+# shellcheck disable=SC2034
32+CONFIG_FILES=()
33+
34+# Apache Settings
35+
36+APACHE_MORTY_SITE="morty.conf"
37+
38+# ----------------------------------------------------------------------------
39+usage() {
40+# ----------------------------------------------------------------------------
41+
42+ # shellcheck disable=SC1117
43+ cat <<EOF
44+
45+usage::
46+
47+ $(basename "$0") shell
48+ $(basename "$0") install [all|user]
49+ $(basename "$0") update [morty]
50+ $(basename "$0") remove [all]
51+ $(basename "$0") activate [service]
52+ $(basename "$0") deactivate [service]
53+ $(basename "$0") inspect [service]
54+ $(basename "$0") option [debug-on|debug-off]
55+ $(basename "$0") apache [install|remove]
56+
57+shell
58+ start interactive shell from user ${SERVICE_USER}
59+install / remove
60+ all: complete setup of morty service
61+ user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
62+update morty
63+ Update morty installation of user ${SERVICE_USER}
64+activate service
65+ activate and start service daemon (systemd unit)
66+deactivate service
67+ stop and deactivate service daemon (systemd unit)
68+inspect service
69+ show service status and log
70+option
71+ set one of the available options
72+apache : ${PUBLIC_URL_MORTY}
73+ :install: apache site with a reverse proxy (ProxyPass)
74+ :remove: apache site ${APACHE_MORTY_SITE}
75+
76+If needed, set the environment variable MORTY_LISTEN in the
77+${DOT_CONFIG#"$REPO_ROOT/"} file::
78+
79+ MORTY_LISTEN : ${MORTY_LISTEN}
80+
81+To activate morty in searx, add result_proxy to your settings.yml::
82+
83+ result_proxy:
84+ url : ${PUBLIC_URL_MORTY}
85+
86+further read: https://asciimoo.github.io/searx/admin/morty.html
87+
88+EOF
89+ [ ! -z ${1+x} ] && echo -e "$1"
90+}
91+
92+main() {
93+ rst_title "$SERVICE_NAME" part
94+
95+ required_commands \
96+ dpkg apt-get install git wget curl \
97+ || exit
98+
99+ local _usage="ERROR: unknown or missing $1 command $2"
100+
101+ case $1 in
102+ --source-only) ;;
103+ -h|--help) usage; exit 0;;
104+
105+ shell)
106+ sudo_or_exit
107+ interactive_shell "${SERVICE_USER}"
108+ ;;
109+ inspect)
110+ case $2 in
111+ service)
112+ sudo_or_exit
113+ inspect_service
114+ ;;
115+ *) usage "$_usage"; exit 42;;
116+ esac ;;
117+ install)
118+ sudo_or_exit
119+ case $2 in
120+ all) install_all ;;
121+ user) assert_user ;;
122+ *) usage "$_usage"; exit 42;;
123+ esac ;;
124+ update)
125+ sudo_or_exit
126+ case $2 in
127+ morty) update_morty ;;
128+ *) usage "$_usage"; exit 42;;
129+ esac ;;
130+ remove)
131+ sudo_or_exit
132+ case $2 in
133+ all) remove_all;;
134+ user) drop_service_account "${SERVICE_USER}" ;;
135+ *) usage "$_usage"; exit 42;;
136+ esac ;;
137+ activate)
138+ sudo_or_exit
139+ case $2 in
140+ service) systemd_activate_service "${SERVICE_NAME}" ;;
141+ *) usage "$_usage"; exit 42;;
142+ esac ;;
143+ deactivate)
144+ sudo_or_exit
145+ case $2 in
146+ service) systemd_deactivate_service "${SERVICE_NAME}" ;;
147+ *) usage "$_usage"; exit 42;;
148+ esac ;;
149+ apache)
150+ sudo_or_exit
151+ case $2 in
152+ install) install_apache_site ;;
153+ remove) remove_apache_site ;;
154+ *) usage "$_usage"; exit 42;;
155+ esac ;;
156+ option)
157+ sudo_or_exit
158+ case $2 in
159+ debug-on) enable_debug ;;
160+ debug-off) disable_debug ;;
161+ *) usage "$_usage"; exit 42;;
162+ esac ;;
163+
164+ *) usage "ERROR: unknown or missing command $1"; exit 42;;
165+ esac
166+}
167+
168+install_all() {
169+ rst_title "Install $SERVICE_NAME (service)"
170+ assert_user
171+ wait_key
172+ install_go "${GO_PKG_URL}" "${GO_TAR}" "${SERVICE_USER}"
173+ wait_key
174+ install_morty
175+ wait_key
176+ systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
177+ wait_key
178+ echo
179+ if ! service_is_available "http://${MORTY_LISTEN}" ; then
180+ err_msg "Morty does not listening on: http://${MORTY_LISTEN}"
181+ fi
182+ if ask_yn "Do you want to inspect the installation?" Yn; then
183+ inspect_service
184+ fi
185+
186+}
187+
188+remove_all() {
189+ rst_title "De-Install $SERVICE_NAME (service)"
190+
191+ rst_para "\
192+It goes without saying that this script can only be used to remove
193+installations that were installed with this script."
194+
195+ if systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then
196+ drop_service_account "${SERVICE_USER}"
197+ fi
198+}
199+
200+assert_user() {
201+ rst_title "user $SERVICE_USER" section
202+ echo
203+ tee_stderr 1 <<EOF | bash | prefix_stdout
204+sudo -H adduser --shell /bin/bash --system --home $SERVICE_HOME \
205+ --disabled-password --group --gecos 'Morty' $SERVICE_USER
206+sudo -H usermod -a -G shadow $SERVICE_USER
207+groups $SERVICE_USER
208+EOF
209+ SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME)"
210+ export SERVICE_HOME
211+ echo "export SERVICE_HOME=$SERVICE_HOME"
212+
213+ cat > "$GO_ENV" <<EOF
214+export GOPATH=\$HOME/go-apps
215+export PATH=\$PATH:\$HOME/local/go/bin:\$GOPATH/bin
216+EOF
217+ echo "Environment $GO_ENV has been setup."
218+
219+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER"
220+grep -qFs -- 'source $GO_ENV' ~/.profile || echo 'source $GO_ENV' >> ~/.profile
221+EOF
222+}
223+
224+morty_is_installed() {
225+ [[ -f $SERVICE_HOME/go-apps/bin/morty ]]
226+}
227+
228+_svcpr=" |${SERVICE_USER}| "
229+
230+install_morty() {
231+ rst_title "Install morty in user's ~/go-apps" section
232+ echo
233+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr"
234+go get -v -u github.com/asciimoo/morty
235+EOF
236+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr"
237+cd \$GOPATH/src/github.com/asciimoo/morty
238+go test
239+go test -benchmem -bench .
240+EOF
241+}
242+
243+update_morty() {
244+ rst_title "Update morty" section
245+ echo
246+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr"
247+go get -v -u github.com/asciimoo/morty
248+EOF
249+ tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr"
250+cd \$GOPATH/src/github.com/asciimoo/morty
251+go test
252+go test -benchmem -bench .
253+EOF
254+}
255+
256+set_service_env_debug() {
257+
258+ # usage: set_service_env_debug [false|true]
259+
260+ local SERVICE_ENV_DEBUG="${1:-false}"
261+ if systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then
262+ systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
263+ fi
264+}
265+
266+inspect_service() {
267+
268+ rst_title "service status & log"
269+
270+ cat <<EOF
271+
272+sourced ${DOT_CONFIG#"$REPO_ROOT/"} :
273+
274+ MORTY_LISTEN : ${MORTY_LISTEN}
275+
276+EOF
277+
278+ if service_account_is_available "$SERVICE_USER"; then
279+ info_msg "service account $SERVICE_USER available."
280+ else
281+ err_msg "service account $SERVICE_USER not available!"
282+ fi
283+ if go_is_available "$SERVICE_USER"; then
284+ info_msg "~$SERVICE_USER: go is installed"
285+ else
286+ err_msg "~$SERVICE_USER: go is not installed"
287+ fi
288+ if morty_is_installed; then
289+ info_msg "~$SERVICE_USER: morty app is installed"
290+ else
291+ err_msg "~$SERVICE_USER: morty app is not installed!"
292+ fi
293+
294+ if ! service_is_available "http://${MORTY_LISTEN}" ; then
295+ err_msg "Morty does not listening on: http://${MORTY_LISTEN}"
296+ echo -e "${_Green}stop with [${_BCyan}CTRL-C${_Green}] or .."
297+ wait_key
298+ fi
299+
300+ local _debug_on
301+ if ask_yn "Enable filtron debug mode?"; then
302+ enable_debug
303+ _debug_on=1
304+ fi
305+
306+ echo
307+ systemctl --no-pager -l status "${SERVICE_NAME}"
308+ echo
309+
310+ # shellcheck disable=SC2059
311+ info_msg "morty URL --> http://${MORTY_LISTEN}"
312+ info_msg "public URL --> ${PUBLIC_URL_MORTY}"
313+ printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
314+ read -r -s -n1 -t 2
315+ echo
316+ while true; do
317+ trap break 2
318+ journalctl -f -u "${SERVICE_NAME}"
319+ done
320+
321+ if [[ $_debug_on == 1 ]]; then
322+ FORCE_SELECTION=Y disable_debug
323+ fi
324+ return 0
325+}
326+
327+
328+enable_debug() {
329+ warn_msg "Do not enable debug in production enviroments!!"
330+ info_msg "Enabling debug option needs to reinstall systemd service!"
331+ set_service_env_debug true
332+}
333+
334+disable_debug() {
335+ info_msg "Disabling debug option needs to reinstall systemd service!"
336+ set_service_env_debug false
337+}
338+
339+install_apache_site() {
340+
341+ rst_title "Install Apache site $APACHE_MORTY_SITE"
342+
343+ rst_para "\
344+This installs a reverse proxy (ProxyPass) into apache site (${APACHE_MORTY_SITE})"
345+
346+ ! apache_is_installed && err_msg "Apache is not installed."
347+
348+ if ! ask_yn "Do you really want to continue?"; then
349+ return
350+ fi
351+
352+ a2enmod headers
353+ a2enmod proxy
354+ a2enmod proxy_http
355+
356+ echo
357+ apache_install_site "${APACHE_MORTY_SITE}"
358+
359+ info_msg "testing public url .."
360+ if ! service_is_available "${PUBLIC_URL_MORTY}"; then
361+ err_msg "Public service at ${PUBLIC_URL_MORTY} is not available!"
362+ fi
363+}
364+
365+remove_apache_site() {
366+
367+ rst_title "Remove Apache site $APACHE_MORTY_SITE"
368+
369+ rst_para "\
370+This removes apache site ${APACHE_MORTY_SITE}."
371+
372+ ! apache_is_installed && err_msg "Apache is not installed."
373+
374+ if ! ask_yn "Do you really want to continue?"; then
375+ return
376+ fi
377+
378+ apache_remove_site "$APACHE_MORTY_SITE"
379+}
380+# ----------------------------------------------------------------------------
381+main "$@"
382+# ----------------------------------------------------------------------------
utils/searx.sh+21−15
@@ -17,10 +17,11 @@ SEARX_URL_PATH="${SEARX_URL_PATH:-$(echo "${PUBLIC_URL}" \
1717SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(echo "$PUBLIC_URL" \
1818| sed -e 's,^.*://\([^\:/]*\).*,\1,g') }"
1919
20−SERVICE_USER="searx"
20+SERVICE_NAME="searx"
21+SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
22+SERVICE_HOME="/home/${SERVICE_USER}"
2123# shellcheck disable=SC2034
2224SERVICE_GROUP="${SERVICE_USER}"
23−SERVICE_HOME="/home/${SERVICE_USER}"
2425
2526SEARX_INTERNAL_URL="127.0.0.1:8888"
2627SEARX_GIT_URL="https://github.com/asciimoo/searx.git"
@@ -65,7 +66,7 @@ usage() {
6566 # shellcheck disable=SC1117
6667 cat <<EOF
6768
68−usage:
69+usage::
6970
7071 $(basename "$0") shell
7172 $(basename "$0") install [all|user|pyenv|searx-src|apache]
@@ -80,10 +81,10 @@ usage:
8081shell
8182 start interactive shell from user ${SERVICE_USER}
8283install / remove
83− all: complete (de-) installation of searx service
84− user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
85− searx-src: clone $SEARX_GIT_URL
86− pyenv: create/remove virtualenv (python) in $SEARX_PYENV
84+ :all: complete (de-) installation of searx service
85+ :user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
86+ :searx-src: clone $SEARX_GIT_URL
87+ :pyenv: create/remove virtualenv (python) in $SEARX_PYENV
8788update searx
8889 Update searx installation of user ${SERVICE_USER}
8990activate service
@@ -95,11 +96,10 @@ inspect service
9596option
9697 set one of the available options
9798apache
98− install: apache site with the searx uwsgi app
99− remove: apache site ${APACHE_FILTRON_SITE}
99+ :install: apache site with the searx uwsgi app
100+ :remove: apache site ${APACHE_FILTRON_SITE}
100101
101−If needed change the environment variable PUBLIC_URL of your WEB service in the
102−${DOT_CONFIG#"$REPO_ROOT/"} file:
102+If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
103103
104104 PUBLIC_URL : ${PUBLIC_URL}
105105 PUBLIC_HOST : ${PUBLIC_HOST}
@@ -440,6 +440,7 @@ EOF
440440}
441441
442442enable_debug() {
443+ warn_msg "Do not enable debug in production enviroments!!"
443444 info_msg "try to enable debug mode ..."
444445 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
445446cd ${SEARX_SRC}
@@ -500,8 +501,10 @@ EOF
500501 uWSGI_app_available "$SEARX_UWSGI_APP" \
501502 || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
502503
503− if ! service_is_available "http://$SEARX_INTERNAL_URL"; then
504− err_msg "uWSGI app (service) at http://$SEARX_INTERNAL_URL is not available!"
504+ if ! service_is_available "http://${SEARX_INTERNAL_URL}"; then
505+ err_msg "uWSGI app (service) at http://${SEARX_INTERNAL_URL} is not available!"
506+ echo -e "${_Green}stop with [${_BCyan}CTRL-C${_Green}] or .."
507+ wait_key
505508 fi
506509
507510 if ! service_is_available "${PUBLIC_URL}"; then
@@ -514,15 +517,18 @@ EOF
514517 _debug_on=1
515518 fi
516519 echo
517− systemctl --no-pager -l status uwsgi.service
520+ systemctl --no-pager -l status "${SERVICE_NAME}"
518521 echo
522+
519523 # shellcheck disable=SC2059
524+ info_msg "public URL --> ${PUBLIC_URL}"
525+ info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
520526 printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
521527 read -r -s -n1 -t 2
522528 echo
523529 while true; do
524530 trap break 2
525− #journalctl -f -u uwsgi.service
531+ #journalctl -f -u "${SERVICE_NAME}"
526532 tail -f /var/log/uwsgi/app/searx.log
527533 done
528534
utils/templates/etc/apache2/sites-available/morty.confnew file+23
@@ -0,0 +1,23 @@
1+# -*- coding: utf-8; mode: apache -*-
2+
3+ProxyPreserveHost On
4+
5+<Location ${PUBLIC_URL_PATH_MORTY} >
6+
7+ Require all granted
8+ Order deny,allow
9+ Deny from all
10+ #Allow from fd00::/8 192.168.0.0/16 fe80::/10 127.0.0.0/8 ::1
11+ Allow from all
12+
13+ ProxyPass http://${MORTY_LISTEN}
14+ RequestHeader set X-Script-Name ${PUBLIC_URL_PATH_MORTY}
15+
16+ # In Apache it seems, that setting HTTP_HOST header direct here does have no
17+ # effect. I needed to set 'ProxyPreserveHost On' (see above). HTTP_HOST is
18+ # needed by searx to render correct *Search URL* in the *Link* box and
19+ # *saved preference*.
20+
21+ # RequestHeader set Host ${PUBLIC_URL_PATH_MORTY}
22+
23+</Location>
utils/templates/lib/systemd/system/morty.servicenew file+29
@@ -0,0 +1,29 @@
1+[Unit]
2+
3+Description=${SERVICE_NAME}
4+After=syslog.target
5+After=network.target
6+
7+[Service]
8+
9+Type=simple
10+User=${SERVICE_USER}
11+Group=${SERVICE_GROUP}
12+WorkingDirectory=${SERVICE_HOME}
13+ExecStart=${SERVICE_HOME}/go-apps/bin/morty -key '' -listen '${MORTY_LISTEN}' -timeout ${MORTY_TIMEOUT}
14+
15+Restart=always
16+Environment=USER=${SERVICE_USER} HOME=${SERVICE_HOME} DEBUG=${SERVICE_ENV_DEBUG}
17+
18+# Some distributions may not support these hardening directives. If you cannot
19+# start the service due to an unknown option, comment out the ones not supported
20+# by your version of systemd.
21+
22+ProtectSystem=full
23+PrivateDevices=yes
24+PrivateTmp=yes
25+NoNewPrivileges=true
26+
27+[Install]
28+
29+WantedBy=multi-user.target