diff --git a/.config.mk b/.config.mk new file mode 100644 index 00000000..3349a760 --- /dev/null +++ b/.config.mk @@ -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 + diff --git a/.config.sh b/.config.sh new file mode 100644 index 00000000..346cb901 --- /dev/null +++ b/.config.sh @@ -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}" + diff --git a/.gitignore b/.gitignore index 42b76ca9..3c998afa 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,3 @@ dist/ local/ gh-pages/ searx.egg-info/ -.config diff --git a/Makefile b/Makefile index 6577b374..500910d8 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/utils/dot_config b/utils/dot_config deleted file mode 100644 index 1ddfa868..00000000 --- a/utils/dot_config +++ /dev/null @@ -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 diff --git a/utils/filtron.sh b/utils/filtron.sh index 2a68f172..3c545ff1 100755 --- a/utils/filtron.sh +++ b/utils/filtron.sh @@ -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 diff --git a/utils/lib.sh b/utils/lib.sh index 78641cc0..05ff5e59 100755 --- a/utils/lib.sh +++ b/utils/lib.sh @@ -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() { diff --git a/utils/morty.sh b/utils/morty.sh index be741c2a..ba4e7dd2 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -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 < 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 diff --git a/utils/searx.sh b/utils/searx.sh index ec4eaacc..2b5e92c4 100755 --- a/utils/searx.sh +++ b/utils/searx.sh @@ -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