@@ -1,19 +1,20 @@
11#!/usr/bin/env bash
22# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
33# SPDX-License-Identifier: AGPL-3.0-or-later
4−# shellcheck disable=SC2119
4+# shellcheck disable=SC2001
55
66# shellcheck source=utils/lib.sh
77source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
8+source_dot_config
89
910# ----------------------------------------------------------------------------
1011# config
1112# ----------------------------------------------------------------------------
1213
13−SEARX_PUBLIC_URL="${SEARX_PUBLIC_URL:-https://$(uname -n)/searx}"
14−SEARX_URL_PATH="${SEARX_URL_PATH:-$(echo "$SEARX_PUBLIC_URL" \
15−| sed -e 's,^.*://[^/]*\(/.*\),\1,g') }"
16−SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(echo "$SEARX_PUBLIC_URL" \
14+SEARX_URL_PATH="${SEARX_URL_PATH:-$(echo "${PUBLIC_URL}" \
15+| sed -e 's,^.*://[^/]*\(/.*\),\1,g')}"
16+[[ "${SEARX_URL_PATH}" == "${PUBLIC_URL}" ]] && SEARX_URL_PATH=/
17+SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(echo "$PUBLIC_URL" \
1718| sed -e 's,^.*://\([^\:/]*\).*,\1,g') }"
1819
1920SERVICE_USER="searx"
@@ -42,10 +43,10 @@ SEARX_APT_PACKAGES="\
4243# Apache Settings
4344
4445APACHE_APT_PACKAGES="\
45− apache2 libapache2-mod-uwsgi \
46+ libapache2-mod-uwsgi \
4647"
4748
48−SEARX_APACHE_SITE="searx.conf"
49+APACHE_SEARX_SITE="searx.conf"
4950
5051# shellcheck disable=SC2034
5152CONFIG_FILES=(
@@ -74,6 +75,7 @@ usage:
7475 $(basename "$0") deactivate [service]
7576 $(basename "$0") inspect [service]
7677 $(basename "$0") option [debug-on|debug-off]
78+ $(basename "$0") apache [install|remove]
7779
7880shell
7981 start interactive shell from user ${SERVICE_USER}
@@ -82,23 +84,25 @@ install / remove
8284 user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
8385 searx-src: clone $SEARX_GIT_URL
8486 pyenv: create/remove virtualenv (python) in $SEARX_PYENV
85− apache: install apache site for searx-uwsgi app
8687update searx
8788 Update searx installation of user ${SERVICE_USER}
88−activate
89+activate service
8990 activate and start service daemon (systemd unit)
9091deactivate service
9192 stop and deactivate service daemon (systemd unit)
9293inspect service
9394 run some small tests and inspect service's status and log
9495option
95− set one of te available options
96+ set one of the available options
97+apache
98+ install: apache site with the searx uwsgi app
99+ remove: apache site ${APACHE_FILTRON_SITE}
96100
97−Use environment SEARX_PUBLIC_URL to set public URL of your WEB-Server:
101+If needed change the environment variable PUBLIC_URL of your WEB service in the
102+${DOT_CONFIG#"$REPO_ROOT/"} file:
98103
99− SEARX_PUBLIC_URL : ${SEARX_PUBLIC_URL}
100− SEARX_URL_PATH : ${SEARX_URL_PATH}
101− SEARX_INSTANCE_NAME : ${SEARX_INSTANCE_NAME}
104+ PUBLIC_URL : ${PUBLIC_URL}
105+ SEARX_INSTANCE_NAME : ${SEARX_INSTANCE_NAME}
102106
103107EOF
104108 [ ! -z ${1+x} ] && echo -e "$1"
@@ -107,6 +111,10 @@ EOF
107111main() {
108112 rst_title "$SEARX_INSTANCE_NAME" part
109113
114+ required_commands \
115+ dpkg systemctl apt-get install git wget curl \
116+ || exit
117+
110118 local _usage="ERROR: unknown or missing $1 command $2"
111119
112120 case $1 in
@@ -132,7 +140,6 @@ main() {
132140 user) assert_user ;;
133141 pyenv) create_pyenv ;;
134142 searx-src) clone_searx ;;
135− apache) install_apache_site ;;
136143 *) usage "$_usage"; exit 42;;
137144 esac ;;
138145 update)
@@ -154,13 +161,13 @@ main() {
154161 sudo_or_exit
155162 case $2 in
156163 service)
157− activate_service; uWSGI_restart ;;
164+ activate_service ;;
158165 *) usage "$_usage"; exit 42;;
159166 esac ;;
160167 deactivate)
161168 sudo_or_exit
162169 case $2 in
163− service) deactivate_service; uWSGI_restart ;;
170+ service) deactivate_service ;;
164171 *) usage "$_usage"; exit 42;;
165172 esac ;;
166173 option)
@@ -170,6 +177,14 @@ main() {
170177 debug-off) echo; disable_debug ;;
171178 *) usage "$_usage"; exit 42;;
172179 esac ;;
180+ apache)
181+ sudo_or_exit
182+ case $2 in
183+ install) install_apache_site ;;
184+ remove) remove_apache_site ;;
185+ *) usage "$_usage"; exit 42;;
186+ esac ;;
187+
173188 *) usage "ERROR: unknown or missing command $1"; exit 42;;
174189 esac
175190}
@@ -191,9 +206,7 @@ install_all() {
191206 test_local_searx
192207 wait_key
193208 install_searx_uwsgi
194− if service_is_available "http://$SEARX_INTERNAL_URL" &>/dev/null; then
195− info_msg "URL http://$SEARX_INTERNAL_URL is available."
196− else
209+ if ! service_is_available "http://$SEARX_INTERNAL_URL"; then
197210 err_msg "URL http://$SEARX_INTERNAL_URL not available, check searx & uwsgi setup!"
198211 fi
199212 if ask_yn "Do you want to inspect the installation?" Yn; then
@@ -418,12 +431,14 @@ activate_service() {
418431 rst_title "Activate $SEARX_INSTANCE_NAME (service)" section
419432 echo
420433 uWSGI_enable_app "$SEARX_UWSGI_APP"
434+ uWSGI_restart
421435}
422436
423437deactivate_service() {
424438 rst_title "De-Activate $SEARX_INSTANCE_NAME (service)" section
425439 echo
426440 uWSGI_disable_app "$SEARX_UWSGI_APP"
441+ uWSGI_restart
427442}
428443
429444interactive_shell() {
@@ -438,12 +453,6 @@ git --no-pager diff
438453EOF
439454}
440455
441−service_is_available() {
442− curl -H 'Cache-Control: no-cache' -o /dev/null \
443− --silent --head --write-out '%{http_code}' --insecure \
444− "${1?missing URL argument}"
445−}
446−
447456enable_debug() {
448457 info_msg "try to enable debug mode ..."
449458 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
@@ -464,7 +473,16 @@ EOF
464473
465474inspect_service() {
466475 rst_title "service status & log"
467− echo
476+ cat <<EOF
477+
478+sourced ${DOT_CONFIG#"$REPO_ROOT/"} :
479+
480+ PUBLIC_URL : ${PUBLIC_URL}
481+ SEARX_URL_PATH : ${SEARX_URL_PATH}
482+ SEARX_INSTANCE_NAME : ${SEARX_INSTANCE_NAME}
483+ SEARX_INTERNAL_URL : ${SEARX_INTERNAL_URL}
484+
485+EOF
468486
469487 apache_is_installed && info_msg "Apache is installed."
470488
@@ -475,15 +493,15 @@ inspect_service() {
475493 fi
476494
477495 if pyenv_is_available; then
478− info_msg "${SEARX_PYENV}/bin/activate is available."
496+ info_msg "~$SERVICE_USER: python environment is available."
479497 else
480− err_msg "${SEARX_PYENV}/bin/activate not available!"
498+ err_msg "~$SERVICE_USER: python environment is not available!"
481499 fi
482500
483501 if clone_is_available; then
484− info_msg "Searx software is installed."
502+ info_msg "~$SERVICE_USER: Searx software is installed."
485503 else
486− err_msg "Missing searx software!"
504+ err_msg "~$SERVICE_USER: Missing searx software!"
487505 fi
488506
489507 if uWSGI_app_enabled "$SEARX_UWSGI_APP"; then
@@ -495,16 +513,12 @@ inspect_service() {
495513 uWSGI_app_available "$SEARX_UWSGI_APP" \
496514 || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
497515
498− if service_is_available "http://$SEARX_INTERNAL_URL" &>/dev/null; then
499− info_msg "uWSGI app (service) at http://$SEARX_INTERNAL_URL is available"
500− else
516+ if ! service_is_available "http://$SEARX_INTERNAL_URL"; then
501517 err_msg "uWSGI app (service) at http://$SEARX_INTERNAL_URL is not available!"
502518 fi
503519
504− if service_is_available "${SEARX_PUBLIC_URL}" &>/dev/null; then
505− info_msg "Public service at ${SEARX_PUBLIC_URL} is available"
506− else
507− err_msg "Public service at ${SEARX_PUBLIC_URL} is not available!"
520+ if ! service_is_available "${PUBLIC_URL}"; then
521+ err_msg "Public service at ${PUBLIC_URL} is not available!"
508522 fi
509523
510524 local _debug_on
@@ -530,7 +544,7 @@ inspect_service() {
530544}
531545
532546install_apache_site() {
533− rst_title "Install Apache site $SEARX_APACHE_SITE"
547+ rst_title "Install Apache site $APACHE_SEARX_SITE"
534548
535549 rst_para "\
536550This installs the searx uwsgi app as apache site. If your server ist public to
@@ -547,13 +561,27 @@ excessively bot queries."
547561 a2enmod uwsgi
548562
549563 echo
550− apache_install_site --variant=uwsgi "${SEARX_APACHE_SITE}"
564+ apache_install_site --variant=uwsgi "${APACHE_SEARX_SITE}"
551565
552− if service_is_available "${SEARX_PUBLIC_URL}" &>/dev/null; then
553− info_msg "Public service at ${SEARX_PUBLIC_URL} is available"
554− else
555− err_msg "Public service at ${SEARX_PUBLIC_URL} is not available!"
566+ if ! service_is_available "${PUBLIC_URL}"; then
567+ err_msg "Public service at ${PUBLIC_URL} is not available!"
568+ fi
569+}
570+
571+remove_apache_site() {
572+
573+ rst_title "Remove Apache site ${APACHE_SEARX_SITE}"
574+
575+ rst_para "\
576+This removes apache site ${APACHE_SEARX_SITE}."
577+
578+ ! apache_is_installed && err_msg "Apache is not installed."
579+
580+ if ! ask_yn "Do you really want to continue?"; then
581+ return
556582 fi
583+
584+ apache_remove_site "${APACHE_SEARX_SITE}"
557585}
558586
559587# ----------------------------------------------------------------------------