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>
This commit is contained in:
Markus Heiser 2020-02-04 10:39:42 +01:00
parent 94ac560dcc
commit 79e1f837ef
9 changed files with 124 additions and 56 deletions

13
.config.mk Normal file
View File

@ -0,0 +1,13 @@
# -*- coding: utf-8; mode: makefile-gmake -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# This environment is used by Makefile targets. If you not maintain your own
# searx brand, you normally not need to change the defaults (except SEARX_URL).
# Compare your settings here with file .config.sh used by the toolboxing in
# utils.
export SEARX_URL=https://searx.me
export GIT_URL=https://github.com/asciimoo/searx
export DOCS_URL=https://asciimoo.github.io/searx

54
.config.sh Normal file
View File

@ -0,0 +1,54 @@
# -*- coding: utf-8; mode: sh -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
# shellcheck shell=bash
#
# This environment is used by ./utils scripts like filtron.sh or searx.sh. The
# default values are *most flexible* and *best maintained*, you normally not
# need to change the defaults (except PUBLIC_URL).
#
# Before you change any value here you have to uninstall any previous
# installation. Further is it recommended to backup your changes simply by
# adding them to you local brand (git branch)::
#
# git add .config
#
# Compare your settings here with file .config.mk used by the Makefile targets.
# The public URL of the searx instance: PUBLIC_URL="https://mydomain.xy/searx"
PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}"
PUBLIC_HOST="${PUBLIC_HOST:-$(echo "$PUBLIC_URL" | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')}"
# searx.sh
# ---------
SEARX_INTERNAL_URL="${SEARX_INTERNAL_URL:-127.0.0.1:8888}"
# Only change, if you maintain a searx brand in your searx fork
SEARX_DOCS_URL="${SEARX_DOCS_URL:-https://asciimoo.github.io/searx}"
SEARX_GIT_URL="${SEARX_GIT_URL:-https://github.com/asciimoo/searx.git}"
SEARX_GIT_BRANCH="${SEARX_GIT_BRANCH:-master}"
# filtron.sh
# ----------
FILTRON_API="${FILTRON_API:-127.0.0.1:4005}"
FILTRON_LISTEN="${FILTRON_LISTEN:-127.0.0.1:4004}"
FILTRON_TARGET="${FILTRON_TARGET:-127.0.0.1:8888}"
# morty.sh
# --------
# morty listen address
MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}"
# system services
# ---------------
# **experimental**: Set SERVICE_USER to run all services by one account, but be
# aware that removing discrete components might conflict!
#
# SERVICE_USER=searx
# Common $HOME folder of the service accounts
SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"

1
.gitignore vendored
View File

@ -25,4 +25,3 @@ dist/
local/
gh-pages/
searx.egg-info/
.config

View File

@ -1,8 +1,6 @@
# -*- coding: utf-8; mode: makefile-gmake -*-
export GIT_URL=https://github.com/asciimoo/searx
export SEARX_URL=https://searx.me
export DOCS_URL=https://asciimoo.github.io/searx
include ./.config.mk
PYOBJECTS = searx
DOC = docs
@ -80,6 +78,8 @@ test.sh:
shellcheck -x utils/lib.sh
shellcheck -x utils/filtron.sh
shellcheck -x utils/searx.sh
shellcheck -x utils/morty.sh
shellcheck -x .config.sh
test.pep8: pyenvinstall
$(PY_ENV_ACT); ./manage.sh pep8_check

View File

@ -1,17 +0,0 @@
# -*- coding: utf-8; mode: sh -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# This environment is used by ./utils scripts like filtron.sh or searx.sh. The
# default values are *most flexible* and *best maintained*, you normally not
# need to change them. Before you change any value here you have to uninstall
# any previous installation. It is recommended to backup your changes simply by
# adding them to you local brand (git branch).
# The public URL of the searx instance
PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}"
PUBLIC_HOST="${PUBLIC_HOST:-$(echo "$PUBLIC_URL" | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')}"
# Run all services by one account, but be aware that removing discrete
# components might conflict! **experimental**
#
# SERVICE_USER=service_account42

View File

@ -19,13 +19,14 @@ FILTRON_ETC="/etc/filtron"
FILTRON_RULES="$FILTRON_ETC/rules.json"
FILTRON_API="127.0.0.1:4005"
FILTRON_LISTEN="127.0.0.1:4004"
FILTRON_TARGET="127.0.0.1:8888"
FILTRON_API="${FILTRON_API:-127.0.0.1:4005}"
FILTRON_LISTEN="${FILTRON_LISTEN:-127.0.0.1:4004}"
FILTRON_TARGET="${FILTRON_TARGET:-127.0.0.1:8888}"
SERVICE_NAME="filtron"
SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
SERVICE_HOME="/home/${SERVICE_USER}"
SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"
SERVICE_HOME="${SERVICE_HOME_BASE}/${SERVICE_USER}"
SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
# shellcheck disable=SC2034
SERVICE_GROUP="${SERVICE_USER}"
@ -70,9 +71,9 @@ shell
start interactive shell from user ${SERVICE_USER}
install / remove
:all: complete setup of filtron service
:user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
:user: add/remove service user '$SERVICE_USER' ($SERVICE_HOME)
update filtron
Update filtron installation of user ${SERVICE_USER}
Update filtron installation ($SERVICE_HOME)
activate service
activate and start service daemon (systemd unit)
deactivate service
@ -87,10 +88,12 @@ apache : ${PUBLIC_URL}
If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
PUBLIC_URL : ${PUBLIC_URL}
PUBLIC_HOST : ${PUBLIC_HOST}
SERVICE_USER : ${SERVICE_USER}
PUBLIC_URL : ${PUBLIC_URL}
PUBLIC_HOST : ${PUBLIC_HOST}
SERVICE_USER : ${SERVICE_USER}
FILTRON_API : ${FILTRON_API}
FILTRON_LISTEN : ${FILTRON_LISTEN}
FILTRON_TARGET : ${FILTRON_TARGET}
EOF
[ ! -z ${1+x} ] && echo -e "$1"
}
@ -305,7 +308,7 @@ EOF
err_msg "Filtron does not listening on: http://${FILTRON_LISTEN}"
fi
if service_is_available ""http://${FILTRON_TARGET}"" ; then
if service_is_available "http://${FILTRON_TARGET}" ; then
info_msg "Filtron's target is available at: http://${FILTRON_TARGET}"
fi

View File

@ -32,18 +32,15 @@ if [[ -z ${DIFF_CMD} ]]; then
fi
fi
DOT_CONFIG="${DOT_CONFIG:-${REPO_ROOT}/.config}"
DOT_CONFIG="${DOT_CONFIG:-${REPO_ROOT}/.config.sh}"
source_dot_config() {
if [[ ! -e "$DOT_CONFIG" ]]; then
info_msg "installing $DOT_CONFIG"
cp "$(dirname "${BASH_SOURCE[0]}")/dot_config" "$DOT_CONFIG"
if [[ ! -z ${SUDO_USER} ]]; then
chown "${SUDO_USER}:${SUDO_USER}" "$DOT_CONFIG"
fi
if [[ ! -e "${DOT_CONFIG}" ]]; then
err_msg "configuration does not extsts at: ${DOT_CONFIG}"
return 42
fi
# shellcheck disable=SC1090
source "${REPO_ROOT}/.config"
source "${DOT_CONFIG}"
}
sudo_or_exit() {

View File

@ -11,17 +11,20 @@ source_dot_config
# ----------------------------------------------------------------------------
PUBLIC_URL_PATH_MORTY="/morty"
PUBLIC_URL_MORTY="$(dirname ${PUBLIC_URL})${PUBLIC_URL_PATH_MORTY}"
PUBLIC_URL_MORTY="$(dirname "${PUBLIC_URL}")${PUBLIC_URL_PATH_MORTY}"
MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}"
# shellcheck disable=SC2034
MORTY_TIMEOUT=5
SERVICE_NAME="morty"
SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
SERVICE_HOME="/home/${SERVICE_USER}"
SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"
SERVICE_HOME="${SERVICE_HOME_BASE}/${SERVICE_USER}"
SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
# shellcheck disable=SC2034
SERVICE_GROUP="${SERVICE_USER}"
# shellcheck disable=SC2034
SERVICE_ENV_DEBUG=false
GO_ENV="${SERVICE_HOME}/.go_env"
@ -53,14 +56,15 @@ usage::
$(basename "$0") inspect [service]
$(basename "$0") option [debug-on|debug-off]
$(basename "$0") apache [install|remove]
$(basename "$0") info [searx]
shell
start interactive shell from user ${SERVICE_USER}
install / remove
all: complete setup of morty service
user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
user: add/remove service user '$SERVICE_USER' ($SERVICE_HOME)
update morty
Update morty installation of user ${SERVICE_USER}
Update morty installation ($SERVICE_HOME)
activate service
activate and start service daemon (systemd unit)
deactivate service
@ -77,17 +81,24 @@ If needed, set the environment variable MORTY_LISTEN in the
${DOT_CONFIG#"$REPO_ROOT/"} file::
MORTY_LISTEN : ${MORTY_LISTEN}
SERVICE_USER : ${SERVICE_USER}
SERVICE_USER : ${SERVICE_USER}
EOF
info_searx
[ ! -z ${1+x} ] && echo -e "$1"
}
info_searx() {
# shellcheck disable=SC1117
cat <<EOF
To activate morty in searx, add result_proxy to your settings.yml::
result_proxy:
url : ${PUBLIC_URL_MORTY}/
further read: https://asciimoo.github.io/searx/admin/morty.html
further read: ${DOCS_URL}/admin/morty.html
EOF
[ ! -z ${1+x} ] && echo -e "$1"
}
main() {
@ -154,6 +165,11 @@ main() {
remove) remove_apache_site ;;
*) usage "$_usage"; exit 42;;
esac ;;
info)
case $2 in
searx) info_searx ;;
*) usage "$_usage"; exit 42;;
esac ;;
option)
sudo_or_exit
case $2 in
@ -176,7 +192,7 @@ install_all() {
wait_key
systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
wait_key
echo
info_searx
if ! service_is_available "http://${MORTY_LISTEN}" ; then
err_msg "Morty does not listening on: http://${MORTY_LISTEN}"
fi
@ -258,6 +274,7 @@ set_service_env_debug() {
# usage: set_service_env_debug [false|true]
# shellcheck disable=SC2034
local SERVICE_ENV_DEBUG="${1:-false}"
if systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then
systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
@ -308,9 +325,9 @@ EOF
systemctl --no-pager -l status "${SERVICE_NAME}"
echo
# shellcheck disable=SC2059
info_msg "morty URL --> http://${MORTY_LISTEN}"
info_msg "public URL --> ${PUBLIC_URL_MORTY}"
# shellcheck disable=SC2059
printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
read -r -s -n1 -t 2
echo

View File

@ -11,6 +11,8 @@ source_dot_config
# config
# ----------------------------------------------------------------------------
SEARX_INTERNAL_URL="${SEARX_INTERNAL_URL:-127.0.0.1:8888}"
SEARX_URL_PATH="${SEARX_URL_PATH:-$(echo "${PUBLIC_URL}" \
| sed -e 's,^.*://[^/]*\(/.*\),\1,g')}"
[[ "${SEARX_URL_PATH}" == "${PUBLIC_URL}" ]] && SEARX_URL_PATH=/
@ -19,13 +21,13 @@ SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(echo "$PUBLIC_URL" \
SERVICE_NAME="searx"
SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
SERVICE_HOME="/home/${SERVICE_USER}"
SERVICE_HOME_BASE="${SERVICE_HOME_BASE:-/usr/local}"
SERVICE_HOME="${SERVICE_HOME_BASE}/${SERVICE_USER}"
# shellcheck disable=SC2034
SERVICE_GROUP="${SERVICE_USER}"
SEARX_INTERNAL_URL="127.0.0.1:8888"
SEARX_GIT_URL="https://github.com/asciimoo/searx.git"
SEARX_GIT_BRANCH="master"
SEARX_GIT_URL="${SEARX_GIT_URL:-https://github.com/asciimoo/searx.git}"
SEARX_GIT_BRANCH="${SEARX_GIT_BRANCH:-master}"
SEARX_PYENV="${SERVICE_HOME}/searx-pyenv"
SEARX_SRC="${SERVICE_HOME}/searx-src"
SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
@ -82,11 +84,11 @@ shell
start interactive shell from user ${SERVICE_USER}
install / remove
:all: complete (de-) installation of searx service
:user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME
:user: add/remove service user '$SERVICE_USER' ($SERVICE_HOME)
:searx-src: clone $SEARX_GIT_URL
:pyenv: create/remove virtualenv (python) in $SEARX_PYENV
update searx
Update searx installation of user ${SERVICE_USER}
Update searx installation ($SERVICE_HOME)
activate service
activate and start service daemon (systemd unit)
deactivate service
@ -521,9 +523,9 @@ EOF
systemctl --no-pager -l status "${SERVICE_NAME}"
echo
# shellcheck disable=SC2059
info_msg "public URL --> ${PUBLIC_URL}"
info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
# shellcheck disable=SC2059
printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
read -r -s -n1 -t 2
echo