@@ -1,5 +1,6 @@
11#!/usr/bin/env bash
22# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
3+# SPDX-License-Identifier: AGPL-3.0-or-later
34# shellcheck disable=SC2119
45
56# shellcheck source=utils/lib.sh
@@ -9,33 +10,41 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
910# config
1011# ----------------------------------------------------------------------------
1112
12−SERVICE_NAME="searx"
13−SERVICE_USER="${SERVICE_NAME}"
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" \
17+| sed -e 's,^.*://\([^\:/]*\).*,\1,g') }"
18+
19+SERVICE_USER="searx"
1420# shellcheck disable=SC2034
1521SERVICE_GROUP="${SERVICE_USER}"
1622SERVICE_HOME="/home/${SERVICE_USER}"
1723
18−SEARX_URL="127.0.0.1:8888"
19−
24+SEARX_INTERNAL_URL="127.0.0.1:8888"
2025SEARX_GIT_URL="https://github.com/asciimoo/searx.git"
2126SEARX_GIT_BRANCH="master"
22−
23−# FIXME: Arch Linux & RHEL should be added
24−
25−SEARX_APT_PACKAGES="\
26−libapache2-mod-uwsgi uwsgi uwsgi-plugin-python3 \
27− git build-essential libxslt-dev python3-dev python3-babel zlib1g-dev \
28− libffi-dev libssl-dev"
29−
3027SEARX_PYENV="${SERVICE_HOME}/searx-pyenv"
3128SEARX_SRC="${SERVICE_HOME}/searx-src"
3229SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
33−SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(uname -n)}"
3430SEARX_UWSGI_APP="searx.ini"
31+# shellcheck disable=SC2034
3532SEARX_UWSGI_SOCKET="/run/uwsgi/app/searx/socket"
3633
34+# FIXME: Arch Linux & RHEL should be added
35+
36+SEARX_APT_PACKAGES="\
37+ uwsgi uwsgi-plugin-python3 \
38+ git build-essential libxslt-dev python3-dev python3-babel zlib1g-dev \
39+ libffi-dev libssl-dev \
40+"
41+
3742# Apache Settings
38−SEARX_APACHE_URL="/searx"
43+
44+APACHE_APT_PACKAGES="\
45+ apache2 libapache2-mod-uwsgi \
46+"
47+
3948SEARX_APACHE_SITE="searx.conf"
4049
4150# shellcheck disable=SC2034
@@ -63,7 +72,7 @@ usage:
6372 $(basename "$0") remove [all|user|pyenv|searx-src]
6473 $(basename "$0") activate [service]
6574 $(basename "$0") deactivate [service]
66− $(basename "$0") show [service]
75+ $(basename "$0") inspect [service]
6776 $(basename "$0") option [debug-on|debug-off]
6877
6978shell
@@ -80,16 +89,23 @@ activate
8089 activate and start service daemon (systemd unit)
8190deactivate service
8291 stop and deactivate service daemon (systemd unit)
83−show service
84− run some small tests and show service's status and log
92+inspect service
93+ run some small tests and inspect service's status and log
8594option
8695 set one of te available options
96+
97+Use environment SEARX_PUBLIC_URL to set public URL of your WEB-Server:
98+
99+ SEARX_PUBLIC_URL : ${SEARX_PUBLIC_URL}
100+ SEARX_URL_PATH : ${SEARX_URL_PATH}
101+ SEARX_INSTANCE_NAME : ${SEARX_INSTANCE_NAME}
102+
87103EOF
88104 [ ! -z ${1+x} ] && echo -e "$1"
89105}
90106
91107main() {
92− rst_title "$SERVICE_NAME" part
108+ rst_title "$SEARX_INSTANCE_NAME" part
93109
94110 local _usage="ERROR: unknown or missing $1 command $2"
95111
@@ -101,11 +117,11 @@ main() {
101117 sudo_or_exit
102118 interactive_shell
103119 ;;
104− show)
120+ inspect)
105121 case $2 in
106122 service)
107123 sudo_or_exit
108− show_service
124+ inspect_service
109125 ;;
110126 *) usage "$_usage"; exit 42;;
111127 esac ;;
@@ -161,7 +177,7 @@ main() {
161177_service_prefix=" |$SERVICE_USER| "
162178
163179install_all() {
164− rst_title "Install $SERVICE_NAME (service)"
180+ rst_title "Install $SEARX_INSTANCE_NAME (service)"
165181 pkg_install "$SEARX_APT_PACKAGES"
166182 wait_key
167183 assert_user
@@ -175,11 +191,15 @@ install_all() {
175191 test_local_searx
176192 wait_key
177193 install_searx_uwsgi
178− if service_is_available; then
179− info_msg "URL http://$SEARX_URL is available."
194+ if service_is_available "http://$SEARX_INTERNAL_URL" &>/dev/null; then
195+ info_msg "URL http://$SEARX_INTERNAL_URL is available."
180196 else
181− err_msg "URL http://$SEARX_URL not available, check searx & uwsgi setup!"
197+ err_msg "URL http://$SEARX_INTERNAL_URL not available, check searx & uwsgi setup!"
198+ fi
199+ if ask_yn "Do you want to inspect the installation?" Yn; then
200+ inspect_service
182201 fi
202+
183203}
184204
185205update_searx() {
@@ -230,13 +250,13 @@ EOF
230250}
231251
232252remove_all() {
233− rst_title "De-Install $SERVICE_NAME (service)"
253+ rst_title "De-Install $SEARX_INSTANCE_NAME (service)"
234254
235255 rst_para "\
236256It goes without saying that this script can only be used to remove
237257installations that were installed with this script."
238258
239− if ! ask_yn "Do you really want to deinstall $SERVICE_NAME?"; then
259+ if ! ask_yn "Do you really want to deinstall $SEARX_INSTANCE_NAME?"; then
240260 return
241261 fi
242262 remove_searx_uwsgi
@@ -364,12 +384,20 @@ EOF
364384test_local_searx() {
365385 rst_title "Testing searx instance localy" section
366386 echo
387+
388+ if service_is_available "http://$SEARX_INTERNAL_URL" &>/dev/null; then
389+ err_msg "URL/port http://$SEARX_INTERNAL_URL is already in use, you"
390+ err_msg "should stop that service before starting local tests!"
391+ if ! ask_yn "Continue with local tests?"; then
392+ return
393+ fi
394+ fi
367395 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
368396cd ${SEARX_SRC}
369397sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS"
370398timeout 5 python3 searx/webapp.py &
371399sleep 1
372−curl --location --verbose --head --insecure $SEARX_URL
400+curl --location --verbose --head --insecure $SEARX_INTERNAL_URL
373401sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
374402EOF
375403}
@@ -387,13 +415,13 @@ remove_searx_uwsgi() {
387415}
388416
389417activate_service() {
390− rst_title "Activate $SERVICE_NAME (service)" section
418+ rst_title "Activate $SEARX_INSTANCE_NAME (service)" section
391419 echo
392420 uWSGI_enable_app "$SEARX_UWSGI_APP"
393421}
394422
395423deactivate_service() {
396− rst_title "De-Activate $SERVICE_NAME (service)" section
424+ rst_title "De-Activate $SEARX_INSTANCE_NAME (service)" section
397425 echo
398426 uWSGI_disable_app "$SEARX_UWSGI_APP"
399427}
@@ -411,7 +439,9 @@ EOF
411439}
412440
413441service_is_available() {
414− curl --insecure "http://$SEARX_URL" &>/dev/null
442+ curl -H 'Cache-Control: no-cache' -o /dev/null \
443+ --silent --head --write-out '%{http_code}' --insecure \
444+ "${1?missing URL argument}"
415445}
416446
417447enable_debug() {
@@ -432,42 +462,51 @@ EOF
432462 uWSGI_restart
433463}
434464
435−show_service() {
465+inspect_service() {
436466 rst_title "service status & log"
437467 echo
438468
439469 apache_is_installed && info_msg "Apache is installed."
440470
441471 if user_is_available; then
442− info_msg "service account $SERVICE_USER available."
443− else
444− err_msg "service account $SERVICE_USER not available!"
445− fi
446− if service_is_available; then
447− info_msg "URL http://$SEARX_URL is available."
472+ info_msg "Service account $SERVICE_USER exists."
448473 else
449− err_msg "URL http://$SEARX_URL not available!"
474+ err_msg "Service account $SERVICE_USER does not exists!"
450475 fi
476+
451477 if pyenv_is_available; then
452478 info_msg "${SEARX_PYENV}/bin/activate is available."
453479 else
454480 err_msg "${SEARX_PYENV}/bin/activate not available!"
455481 fi
482+
456483 if clone_is_available; then
457484 info_msg "Searx software is installed."
458485 else
459486 err_msg "Missing searx software!"
460487 fi
461488
462− uWSGI_app_available "$SEARX_UWSGI_APP" \
463− || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
464−
465489 if uWSGI_app_enabled "$SEARX_UWSGI_APP"; then
466490 info_msg "uWSGI app $SEARX_UWSGI_APP is enabled."
467491 else
468492 err_msg "uWSGI app $SEARX_UWSGI_APP not enabled!"
469493 fi
470494
495+ uWSGI_app_available "$SEARX_UWSGI_APP" \
496+ || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
497+
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
501+ err_msg "uWSGI app (service) at http://$SEARX_INTERNAL_URL is not available!"
502+ fi
503+
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!"
508+ fi
509+
471510 local _debug_on
472511 if ask_yn "Enable searx debug mode?"; then
473512 enable_debug
@@ -503,8 +542,18 @@ excessively bot queries."
503542 if ! ask_yn "Do you really want to install apache site for searx-uwsgi?"; then
504543 return
505544 fi
545+
546+ pkg_install "$APACHE_APT_PACKAGES"
547+ a2enmod uwsgi
548+
506549 echo
507550 apache_install_site --variant=uwsgi "${SEARX_APACHE_SITE}"
551+
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!"
556+ fi
508557}
509558
510559# ----------------------------------------------------------------------------