on master help sign in
utils & Makefile: add .config.mk & .config.sh for searx brands

By isolating the environment of makefiles and bash scripts into .config.mk and .config.sh it is simple to maintain searx brands by setting some central environments. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit79e1f837ef7e7c402fd6e9dbb167aac695f2aee7 authorMarkus Heiser <markus.heiser@darmarit.de> dateTue 4 Feb 2020, 10:39 (7 years ago) parent94ac560
9 files changed+124−56
.config.mk+13 .config.sh+54 .gitignore−1 Makefile+3−3 utils/dot_config−17 utils/filtron.sh+14−11 utils/lib.sh+5−8 utils/morty.sh+26−9 utils/searx.sh+9−7
.config.mknew file+13
@@ -0,0 +1,13 @@
1+# -*- coding: utf-8; mode: makefile-gmake -*-
2+# SPDX-License-Identifier: AGPL-3.0-or-later
3+#
4+# This environment is used by Makefile targets. If you not maintain your own
5+# searx brand, you normally not need to change the defaults (except SEARX_URL).
6+# Compare your settings here with file .config.sh used by the toolboxing in
7+# utils.
8+
9+export SEARX_URL=https://searx.me
10+
11+export GIT_URL=https://github.com/asciimoo/searx
12+export DOCS_URL=https://asciimoo.github.io/searx
13+
.config.shnew file+54
@@ -0,0 +1,54 @@
1+# -*- coding: utf-8; mode: sh -*-
2+# SPDX-License-Identifier: AGPL-3.0-or-later
3+# shellcheck shell=bash
4+#
5+# This environment is used by ./utils scripts like filtron.sh or searx.sh. The
6+# default values are *most flexible* and *best maintained*, you normally not
7+# need to change the defaults (except PUBLIC_URL).
8+#
9+# Before you change any value here you have to uninstall any previous
10+# installation. Further is it recommended to backup your changes simply by
11+# adding them to you local brand (git branch)::
12+#
13+# git add .config
14+#
15+# Compare your settings here with file .config.mk used by the Makefile targets.
16+
17+# The public URL of the searx instance: PUBLIC_URL="https://mydomain.xy/searx"
18+PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}"
19+PUBLIC_HOST="${PUBLIC_HOST:-$(echo "$PUBLIC_URL" | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')}"
20+
21+# searx.sh
22+# ---------
23+
24+SEARX_INTERNAL_URL="${SEARX_INTERNAL_URL:-127.0.0.1:8888}"
25+
26+# Only change, if you maintain a searx brand in your searx fork
27+SEARX_DOCS_URL="${SEARX_DOCS_URL:-https://asciimoo.github.io/searx}"
28+SEARX_GIT_URL="${SEARX_GIT_URL:-https://github.com/asciimoo/searx.git}"
29+SEARX_GIT_BRANCH="${SEARX_GIT_BRANCH:-master}"
30+
31+# filtron.sh
32+# ----------
33+
34+FILTRON_API="${FILTRON_API:-127.0.0.1:4005}"
35+FILTRON_LISTEN="${FILTRON_LISTEN:-127.0.0.1:4004}"
36+FILTRON_TARGET="${FILTRON_TARGET:-127.0.0.1:8888}"
37+
38+# morty.sh
39+# --------
40+
41+# morty listen address
42+MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}"
43+
44+# system services
45+# ---------------
46+
47+# **experimental**: Set SERVICE_USER to run all services by one account, but be
48+# aware that removing discrete components might conflict!
49+#
50+# SERVICE_USER=searx
51+
52+# Common $HOME folder of the service accounts
53+SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"
54+
.gitignore−1
@@ -25,4 +25,3 @@ dist/
2525local/
2626gh-pages/
2727searx.egg-info/
28−.config
Makefile+3−3
@@ -1,8 +1,6 @@
11# -*- coding: utf-8; mode: makefile-gmake -*-
22
3−export GIT_URL=https://github.com/asciimoo/searx
4−export SEARX_URL=https://searx.me
5−export DOCS_URL=https://asciimoo.github.io/searx
3+include ./.config.mk
64
75PYOBJECTS = searx
86DOC = docs
@@ -80,6 +78,8 @@ test.sh:
8078 shellcheck -x utils/lib.sh
8179 shellcheck -x utils/filtron.sh
8280 shellcheck -x utils/searx.sh
81+ shellcheck -x utils/morty.sh
82+ shellcheck -x .config.sh
8383
8484test.pep8: pyenvinstall
8585 $(PY_ENV_ACT); ./manage.sh pep8_check
utils/dot_configdeleted−17
@@ -1,17 +0,0 @@
1−# -*- coding: utf-8; mode: sh -*-
2−# SPDX-License-Identifier: AGPL-3.0-or-later
3−#
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).
9−
10−# The public URL of the searx instance
11−PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}"
12−PUBLIC_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+14−11
@@ -19,13 +19,14 @@ FILTRON_ETC="/etc/filtron"
1919
2020FILTRON_RULES="$FILTRON_ETC/rules.json"
2121
22−FILTRON_API="127.0.0.1:4005"
23−FILTRON_LISTEN="127.0.0.1:4004"
24−FILTRON_TARGET="127.0.0.1:8888"
22+FILTRON_API="${FILTRON_API:-127.0.0.1:4005}"
23+FILTRON_LISTEN="${FILTRON_LISTEN:-127.0.0.1:4004}"
24+FILTRON_TARGET="${FILTRON_TARGET:-127.0.0.1:8888}"
2525
2626SERVICE_NAME="filtron"
2727SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
28−SERVICE_HOME="/home/${SERVICE_USER}"
28+SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"
29+SERVICE_HOME="${SERVICE_HOME_BASE}/${SERVICE_USER}"
2930SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
3031# shellcheck disable=SC2034
3132SERVICE_GROUP="${SERVICE_USER}"
@@ -70,9 +71,9 @@ shell
7071 start interactive shell from user ${SERVICE_USER}
7172install / remove
7273 :all: complete setup of filtron service
73− :user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
74+ :user: add/remove service user '$SERVICE_USER' ($SERVICE_HOME)
7475update filtron
75− Update filtron installation of user ${SERVICE_USER}
76+ Update filtron installation ($SERVICE_HOME)
7677activate service
7778 activate and start service daemon (systemd unit)
7879deactivate service
@@ -87,10 +88,12 @@ apache : ${PUBLIC_URL}
8788
8889If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
8990
90− PUBLIC_URL : ${PUBLIC_URL}
91− PUBLIC_HOST : ${PUBLIC_HOST}
92− SERVICE_USER : ${SERVICE_USER}
93−
91+ PUBLIC_URL : ${PUBLIC_URL}
92+ PUBLIC_HOST : ${PUBLIC_HOST}
93+ SERVICE_USER : ${SERVICE_USER}
94+ FILTRON_API : ${FILTRON_API}
95+ FILTRON_LISTEN : ${FILTRON_LISTEN}
96+ FILTRON_TARGET : ${FILTRON_TARGET}
9497EOF
9598 [ ! -z ${1+x} ] && echo -e "$1"
9699}
@@ -305,7 +308,7 @@ EOF
305308 err_msg "Filtron does not listening on: http://${FILTRON_LISTEN}"
306309 fi
307310
308− if service_is_available ""http://${FILTRON_TARGET}"" ; then
311+ if service_is_available "http://${FILTRON_TARGET}" ; then
309312 info_msg "Filtron's target is available at: http://${FILTRON_TARGET}"
310313 fi
311314
utils/lib.sh+5−8
@@ -32,18 +32,15 @@ if [[ -z ${DIFF_CMD} ]]; then
3232 fi
3333fi
3434
35−DOT_CONFIG="${DOT_CONFIG:-${REPO_ROOT}/.config}"
35+DOT_CONFIG="${DOT_CONFIG:-${REPO_ROOT}/.config.sh}"
3636
3737source_dot_config() {
38− if [[ ! -e "$DOT_CONFIG" ]]; then
39− info_msg "installing $DOT_CONFIG"
40− cp "$(dirname "${BASH_SOURCE[0]}")/dot_config" "$DOT_CONFIG"
41− if [[ ! -z ${SUDO_USER} ]]; then
42− chown "${SUDO_USER}:${SUDO_USER}" "$DOT_CONFIG"
43− fi
38+ if [[ ! -e "${DOT_CONFIG}" ]]; then
39+ err_msg "configuration does not extsts at: ${DOT_CONFIG}"
40+ return 42
4441 fi
4542 # shellcheck disable=SC1090
46− source "${REPO_ROOT}/.config"
43+ source "${DOT_CONFIG}"
4744}
4845
4946sudo_or_exit() {
utils/morty.sh+26−9
@@ -11,17 +11,20 @@ source_dot_config
1111# ----------------------------------------------------------------------------
1212
1313PUBLIC_URL_PATH_MORTY="/morty"
14−PUBLIC_URL_MORTY="$(dirname ${PUBLIC_URL})${PUBLIC_URL_PATH_MORTY}"
14+PUBLIC_URL_MORTY="$(dirname "${PUBLIC_URL}")${PUBLIC_URL_PATH_MORTY}"
1515
1616MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}"
17+# shellcheck disable=SC2034
1718MORTY_TIMEOUT=5
1819
1920SERVICE_NAME="morty"
2021SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
21−SERVICE_HOME="/home/${SERVICE_USER}"
22+SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"
23+SERVICE_HOME="${SERVICE_HOME_BASE}/${SERVICE_USER}"
2224SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
2325# shellcheck disable=SC2034
2426SERVICE_GROUP="${SERVICE_USER}"
27+# shellcheck disable=SC2034
2528SERVICE_ENV_DEBUG=false
2629
2730GO_ENV="${SERVICE_HOME}/.go_env"
@@ -53,14 +56,15 @@ usage::
5356 $(basename "$0") inspect [service]
5457 $(basename "$0") option [debug-on|debug-off]
5558 $(basename "$0") apache [install|remove]
59+ $(basename "$0") info [searx]
5660
5761shell
5862 start interactive shell from user ${SERVICE_USER}
5963install / remove
6064 all: complete setup of morty service
61− user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
65+ user: add/remove service user '$SERVICE_USER' ($SERVICE_HOME)
6266update morty
63− Update morty installation of user ${SERVICE_USER}
67+ Update morty installation ($SERVICE_HOME)
6468activate service
6569 activate and start service daemon (systemd unit)
6670deactivate service
@@ -77,17 +81,24 @@ If needed, set the environment variable MORTY_LISTEN in the
7781${DOT_CONFIG#"$REPO_ROOT/"} file::
7882
7983 MORTY_LISTEN : ${MORTY_LISTEN}
80− SERVICE_USER : ${SERVICE_USER}
84+ SERVICE_USER : ${SERVICE_USER}
85+EOF
86+ info_searx
87+ [ ! -z ${1+x} ] && echo -e "$1"
88+}
89+
90+info_searx() {
91+ # shellcheck disable=SC1117
92+ cat <<EOF
8193
8294To activate morty in searx, add result_proxy to your settings.yml::
8395
8496 result_proxy:
8597 url : ${PUBLIC_URL_MORTY}/
8698
87−further read: https://asciimoo.github.io/searx/admin/morty.html
99+further read: ${DOCS_URL}/admin/morty.html
88100
89101EOF
90− [ ! -z ${1+x} ] && echo -e "$1"
91102}
92103
93104main() {
@@ -154,6 +165,11 @@ main() {
154165 remove) remove_apache_site ;;
155166 *) usage "$_usage"; exit 42;;
156167 esac ;;
168+ info)
169+ case $2 in
170+ searx) info_searx ;;
171+ *) usage "$_usage"; exit 42;;
172+ esac ;;
157173 option)
158174 sudo_or_exit
159175 case $2 in
@@ -176,7 +192,7 @@ install_all() {
176192 wait_key
177193 systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
178194 wait_key
179− echo
195+ info_searx
180196 if ! service_is_available "http://${MORTY_LISTEN}" ; then
181197 err_msg "Morty does not listening on: http://${MORTY_LISTEN}"
182198 fi
@@ -258,6 +274,7 @@ set_service_env_debug() {
258274
259275 # usage: set_service_env_debug [false|true]
260276
277+ # shellcheck disable=SC2034
261278 local SERVICE_ENV_DEBUG="${1:-false}"
262279 if systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then
263280 systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
@@ -308,9 +325,9 @@ EOF
308325 systemctl --no-pager -l status "${SERVICE_NAME}"
309326 echo
310327
311− # shellcheck disable=SC2059
312328 info_msg "morty URL --> http://${MORTY_LISTEN}"
313329 info_msg "public URL --> ${PUBLIC_URL_MORTY}"
330+ # shellcheck disable=SC2059
314331 printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
315332 read -r -s -n1 -t 2
316333 echo
utils/searx.sh+9−7
@@ -11,6 +11,8 @@ source_dot_config
1111# config
1212# ----------------------------------------------------------------------------
1313
14+SEARX_INTERNAL_URL="${SEARX_INTERNAL_URL:-127.0.0.1:8888}"
15+
1416SEARX_URL_PATH="${SEARX_URL_PATH:-$(echo "${PUBLIC_URL}" \
1517| sed -e 's,^.*://[^/]*\(/.*\),\1,g')}"
1618[[ "${SEARX_URL_PATH}" == "${PUBLIC_URL}" ]] && SEARX_URL_PATH=/
@@ -19,13 +21,13 @@ SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(echo "$PUBLIC_URL" \
1921
2022SERVICE_NAME="searx"
2123SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
22−SERVICE_HOME="/home/${SERVICE_USER}"
24+SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"
25+SERVICE_HOME="${SERVICE_HOME_BASE}/${SERVICE_USER}"
2326# shellcheck disable=SC2034
2427SERVICE_GROUP="${SERVICE_USER}"
2528
26−SEARX_INTERNAL_URL="127.0.0.1:8888"
27−SEARX_GIT_URL="https://github.com/asciimoo/searx.git"
28−SEARX_GIT_BRANCH="master"
29+SEARX_GIT_URL="${SEARX_GIT_URL:-https://github.com/asciimoo/searx.git}"
30+SEARX_GIT_BRANCH="${SEARX_GIT_BRANCH:-master}"
2931SEARX_PYENV="${SERVICE_HOME}/searx-pyenv"
3032SEARX_SRC="${SERVICE_HOME}/searx-src"
3133SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
@@ -82,11 +84,11 @@ shell
8284 start interactive shell from user ${SERVICE_USER}
8385install / remove
8486 :all: complete (de-) installation of searx service
85− :user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
87+ :user: add/remove service user '$SERVICE_USER' ($SERVICE_HOME)
8688 :searx-src: clone $SEARX_GIT_URL
8789 :pyenv: create/remove virtualenv (python) in $SEARX_PYENV
8890update searx
89− Update searx installation of user ${SERVICE_USER}
91+ Update searx installation ($SERVICE_HOME)
9092activate service
9193 activate and start service daemon (systemd unit)
9294deactivate service
@@ -521,9 +523,9 @@ EOF
521523 systemctl --no-pager -l status "${SERVICE_NAME}"
522524 echo
523525
524− # shellcheck disable=SC2059
525526 info_msg "public URL --> ${PUBLIC_URL}"
526527 info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
528+ # shellcheck disable=SC2059
527529 printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
528530 read -r -s -n1 -t 2
529531 echo