From a4437c47ac0bd22cd7f5aaa8e7895cdd8e93a317 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 2 Feb 2020 18:14:10 +0100 Subject: utils/morty.sh: add script to install morty result proxy Signed-off-by: Markus Heiser --- utils/morty.sh | 382 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100755 utils/morty.sh (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh new file mode 100755 index 000000000..49f7e2724 --- /dev/null +++ b/utils/morty.sh @@ -0,0 +1,382 @@ +#!/usr/bin/env bash +# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*- +# SPDX-License-Identifier: AGPL-3.0-or-later + +# shellcheck source=utils/lib.sh +source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" +source_dot_config + +# ---------------------------------------------------------------------------- +# config +# ---------------------------------------------------------------------------- + +PUBLIC_URL_PATH_MORTY="/morty" +PUBLIC_URL_MORTY="$(dirname ${PUBLIC_URL})${PUBLIC_URL_PATH_MORTY}" + +MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}" +MORTY_TIMEOUT=5 + +SERVICE_NAME="morty" +SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}" +SERVICE_HOME="/home/${SERVICE_USER}" +SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service" +# shellcheck disable=SC2034 +SERVICE_GROUP="${SERVICE_USER}" +SERVICE_ENV_DEBUG=false + +GO_ENV="${SERVICE_HOME}/.go_env" +GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz" +GO_TAR=$(basename "$GO_PKG_URL") + +# shellcheck disable=SC2034 +CONFIG_FILES=() + +# Apache Settings + +APACHE_MORTY_SITE="morty.conf" + +# ---------------------------------------------------------------------------- +usage() { +# ---------------------------------------------------------------------------- + + # shellcheck disable=SC1117 + cat < "$GO_ENV" <> ~/.profile +EOF +} + +morty_is_installed() { + [[ -f $SERVICE_HOME/go-apps/bin/morty ]] +} + +_svcpr=" |${SERVICE_USER}| " + +install_morty() { + rst_title "Install morty in user's ~/go-apps" section + echo + tee_stderr <&1 | prefix_stdout "$_svcpr" +go get -v -u github.com/asciimoo/morty +EOF + tee_stderr <&1 | prefix_stdout "$_svcpr" +cd \$GOPATH/src/github.com/asciimoo/morty +go test +go test -benchmem -bench . +EOF +} + +update_morty() { + rst_title "Update morty" section + echo + tee_stderr <&1 | prefix_stdout "$_svcpr" +go get -v -u github.com/asciimoo/morty +EOF + tee_stderr <&1 | prefix_stdout "$_svcpr" +cd \$GOPATH/src/github.com/asciimoo/morty +go test +go test -benchmem -bench . +EOF +} + +set_service_env_debug() { + + # usage: set_service_env_debug [false|true] + + local SERVICE_ENV_DEBUG="${1:-false}" + if systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then + systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}" + fi +} + +inspect_service() { + + rst_title "service status & log" + + cat < http://${MORTY_LISTEN}" + info_msg "public URL --> ${PUBLIC_URL_MORTY}" + printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log" + read -r -s -n1 -t 2 + echo + while true; do + trap break 2 + journalctl -f -u "${SERVICE_NAME}" + done + + if [[ $_debug_on == 1 ]]; then + FORCE_SELECTION=Y disable_debug + fi + return 0 +} + + +enable_debug() { + warn_msg "Do not enable debug in production enviroments!!" + info_msg "Enabling debug option needs to reinstall systemd service!" + set_service_env_debug true +} + +disable_debug() { + info_msg "Disabling debug option needs to reinstall systemd service!" + set_service_env_debug false +} + +install_apache_site() { + + rst_title "Install Apache site $APACHE_MORTY_SITE" + + rst_para "\ +This installs a reverse proxy (ProxyPass) into apache site (${APACHE_MORTY_SITE})" + + ! apache_is_installed && err_msg "Apache is not installed." + + if ! ask_yn "Do you really want to continue?"; then + return + fi + + a2enmod headers + a2enmod proxy + a2enmod proxy_http + + echo + apache_install_site "${APACHE_MORTY_SITE}" + + info_msg "testing public url .." + if ! service_is_available "${PUBLIC_URL_MORTY}"; then + err_msg "Public service at ${PUBLIC_URL_MORTY} is not available!" + fi +} + +remove_apache_site() { + + rst_title "Remove Apache site $APACHE_MORTY_SITE" + + rst_para "\ +This removes apache site ${APACHE_MORTY_SITE}." + + ! apache_is_installed && err_msg "Apache is not installed." + + if ! ask_yn "Do you really want to continue?"; then + return + fi + + apache_remove_site "$APACHE_MORTY_SITE" +} +# ---------------------------------------------------------------------------- +main "$@" +# ---------------------------------------------------------------------------- -- cgit v1.2.3 From e7401796f652c946f52faf12b1b7c871ceaa7211 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 2 Feb 2020 18:20:20 +0100 Subject: utils/morty.sh: fixed public url Signed-off-by: Markus Heiser --- utils/morty.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 49f7e2724..4f689e2b7 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -81,7 +81,7 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file:: To activate morty in searx, add result_proxy to your settings.yml:: result_proxy: - url : ${PUBLIC_URL_MORTY} + url : ${PUBLIC_URL_MORTY}/ further read: https://asciimoo.github.io/searx/admin/morty.html -- cgit v1.2.3 From 94ac560dcc85e2e75d3b14706a65eb9488643eb4 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 3 Feb 2020 13:25:51 +0100 Subject: doc: add descriptions of our tooling box in ./utils Initial started with the scripts for searx, filtron and morty installations. Signed-off-by: Markus Heiser --- utils/morty.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 4f689e2b7..be741c2a4 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -77,6 +77,7 @@ If needed, set the environment variable MORTY_LISTEN in the ${DOT_CONFIG#"$REPO_ROOT/"} file:: MORTY_LISTEN : ${MORTY_LISTEN} + SERVICE_USER : ${SERVICE_USER} To activate morty in searx, add result_proxy to your settings.yml:: -- cgit v1.2.3 From 79e1f837ef7e7c402fd6e9dbb167aac695f2aee7 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 4 Feb 2020 10:39:42 +0100 Subject: 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 --- utils/morty.sh | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index be741c2a4..ba4e7dd2e 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 -- cgit v1.2.3 From 2f40f61f83afb34f0c4b95019a53050a504ce43a Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 4 Feb 2020 17:59:58 +0100 Subject: /etc/filtron/rules.json: normalize rules from docs & tooling box Signed-off-by: Markus Heiser --- utils/morty.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index ba4e7dd2e..6c63351cf 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -84,7 +84,7 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file:: SERVICE_USER : ${SERVICE_USER} EOF info_searx - [ ! -z ${1+x} ] && echo -e "$1" + [ ! -z ${1+x} ] && err_msg "$1" } info_searx() { -- cgit v1.2.3 From 71d7550dbe750f35f0dd7b5c513bc9e8db9512ee Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 4 Feb 2020 19:47:33 +0100 Subject: tooling box ./utils/*: minor fix from production test --- utils/morty.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 6c63351cf..7a9db08a8 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -84,7 +84,7 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file:: SERVICE_USER : ${SERVICE_USER} EOF info_searx - [ ! -z ${1+x} ] && err_msg "$1" + [ ! -z "${1+x}" ] && err_msg "$1" } info_searx() { @@ -196,6 +196,12 @@ install_all() { if ! service_is_available "http://${MORTY_LISTEN}" ; then err_msg "Morty does not listening on: http://${MORTY_LISTEN}" fi + if apache_is_installed; then + info_msg "Apache is installed on this host." + if ask_yn "Do you want to install a reverse proxy (ProxyPass)" Yn; then + install_apache_site + fi + fi if ask_yn "Do you want to inspect the installation?" Yn; then inspect_service fi -- cgit v1.2.3 From ad3273986024c80cfe067d1b77983901a41b6d01 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 16 Feb 2020 20:07:37 +0100 Subject: shellcheck: fix usse -n instead of ! -z (SC2236 SC2237) - https://www.shellcheck.net/wiki/SC2236 -- Use -n instead of ! -z. - https://www.shellcheck.net/wiki/SC2237 -- Use [ -n .. ] instead of ! [ -z .... Signed-off-by: Markus Heiser --- utils/morty.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 7a9db08a8..bd4ad5901 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -84,7 +84,7 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file:: SERVICE_USER : ${SERVICE_USER} EOF info_searx - [ ! -z "${1+x}" ] && err_msg "$1" + [[ -n ${1} ]] && err_msg "$1" } info_searx() { -- cgit v1.2.3 From 5fb6d4f508d9744a8d82160ca184729514bc18c8 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 23 Feb 2020 12:10:45 +0100 Subject: LXC: normalize package installation & user creation. utils/lib.sh: - get DIST_ID & DIST_VERSION from /etc/os-release - pkg_[install|remove|...] supports ubuntu, debian, archlinux & fedora utils/lxc.sh - Workaround for the "setrlimit(RLIMIT_CORE): Operation not permitted" error:: 'Set disable_coredump false' >> /etc/sudo.conf utils/[searx.sh|filtron.sh|morty.sh] - switched user creation from 'adduser' perl script to 'useradd' built-in command utils/searx.sh - install packages for ubuntu, debian, archlinux & fedora Signed-off-by: Markus Heiser --- utils/morty.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index bd4ad5901..37ee87edf 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -105,7 +105,7 @@ main() { rst_title "$SERVICE_NAME" part required_commands \ - dpkg apt-get install git wget curl \ + sudo install git wget curl \ || exit local _usage="ERROR: unknown or missing $1 command $2" @@ -224,9 +224,11 @@ assert_user() { rst_title "user $SERVICE_USER" section echo tee_stderr 1 < Date: Tue, 25 Feb 2020 20:20:17 +0100 Subject: utils/lib.sh: make uWSGI installation available for all distros support: ubuntu, debin, fedora, archlinux Signed-off-by: Markus Heiser --- utils/morty.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 37ee87edf..1ce15608f 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -96,6 +96,11 @@ To activate morty in searx, add result_proxy to your settings.yml:: result_proxy: url : ${PUBLIC_URL_MORTY}/ + server: + ... + image_proxy : True # Proxying image results through searx + ... + further read: ${DOCS_URL}/admin/morty.html EOF -- cgit v1.2.3 From af6acd3417bf53c151b9ba6068186c1e472a2776 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 26 Feb 2020 19:07:55 +0100 Subject: LXC: install searx-suite installs searx, filtron & morty on all containers Signed-off-by: Markus Heiser --- utils/morty.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 1ce15608f..fcc9dc728 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -207,7 +207,7 @@ install_all() { install_apache_site fi fi - if ask_yn "Do you want to inspect the installation?" Yn; then + if ask_yn "Do you want to inspect the installation?" Ny; then inspect_service fi @@ -408,6 +408,7 @@ This removes apache site ${APACHE_MORTY_SITE}." apache_remove_site "$APACHE_MORTY_SITE" } + # ---------------------------------------------------------------------------- main "$@" # ---------------------------------------------------------------------------- -- cgit v1.2.3 From 37c135f2cec6113aa2baaf1b52fe46fd64265975 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Thu, 27 Feb 2020 19:13:03 +0100 Subject: LXC: improved UX when working with a bunch of containers Signed-off-by: Markus Heiser --- utils/morty.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index fcc9dc728..e7e2f8651 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -255,7 +255,7 @@ morty_is_installed() { [[ -f $SERVICE_HOME/go-apps/bin/morty ]] } -_svcpr=" |${SERVICE_USER}| " +_svcpr=" ${_Yellow}|${SERVICE_USER}|${_creset} " install_morty() { rst_title "Install morty in user's ~/go-apps" section -- cgit v1.2.3 From 491cb95a1f910e17ac022ddfa73b68aae2fbc6e2 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 1 Mar 2020 18:28:10 +0100 Subject: utils/lxc.env: separate environment that is used in containers Signed-off-by: Markus Heiser --- utils/morty.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index e7e2f8651..c3531f735 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -5,6 +5,7 @@ # shellcheck source=utils/lib.sh source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" source_dot_config +source "${REPO_ROOT}/utils/lxc.env" # ---------------------------------------------------------------------------- # config -- cgit v1.2.3 From c3e4753ce951f759844db13d98f9ad5b226f84b6 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 2 Mar 2020 19:00:19 +0100 Subject: docs: generic documentation from the installation scripts Signed-off-by: Markus Heiser --- utils/morty.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index c3531f735..143e7e0c8 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -183,6 +183,10 @@ main() { debug-off) disable_debug ;; *) usage "$_usage"; exit 42;; esac ;; + doc) + echo + echo ".. generic utils/morty.sh documentation" + ;; *) usage "ERROR: unknown or missing command $1"; exit 42;; esac -- cgit v1.2.3 From b1e90cff23eae2181d2b430e77471f488947d1a9 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sat, 7 Mar 2020 20:24:08 +0100 Subject: LXC: separate lxc-suite from lxc & improved command line. Signed-off-by: Markus Heiser --- utils/morty.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 143e7e0c8..175bdf019 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -5,7 +5,7 @@ # shellcheck source=utils/lib.sh source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" source_dot_config -source "${REPO_ROOT}/utils/lxc.env" +source "${REPO_ROOT}/utils/lxc-searx.env" # ---------------------------------------------------------------------------- # config -- cgit v1.2.3 From e7f69b63f1169a60f6f15b827dfe4f5748a41d2c Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 8 Mar 2020 02:41:45 +0100 Subject: LXC: from searx.sh, morty.sh and filtron.sh tests Signed-off-by: Markus Heiser --- utils/morty.sh | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 175bdf019..58de0cc99 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -6,6 +6,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" source_dot_config source "${REPO_ROOT}/utils/lxc-searx.env" +in_container && lxc_set_suite_env # ---------------------------------------------------------------------------- # config @@ -83,7 +84,14 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file:: MORTY_LISTEN : ${MORTY_LISTEN} SERVICE_USER : ${SERVICE_USER} + EOF + if in_container; then + lxc_suite_info + else + info_msg "public URL --> ${PUBLIC_URL}" + info_msg "internal URL --> http://${SEARX_INTERNAL_URL}" + fi info_searx [[ -n ${1} ]] && err_msg "$1" } @@ -333,21 +341,32 @@ EOF wait_key fi + if ! service_is_available "${PUBLIC_URL}"; then + warn_msg "Public service at ${PUBLIC_URL} is not available!" + if ! in_container; then + warn_msg "Check if public name is correct and routed or use the public IP from above." + fi + fi + + if in_container; then + lxc_suite_info + else + info_msg "public URL --> ${PUBLIC_URL_MORTY}" + info_msg "morty URL --> http://${MORTY_LISTEN}" + fi + local _debug_on - if ask_yn "Enable filtron debug mode?"; then + if ask_yn "Enable filtron debug mode (needs reinstall of systemd service)?"; then enable_debug _debug_on=1 + else + systemctl --no-pager -l status "${SERVICE_NAME}" fi - - echo - systemctl --no-pager -l status "${SERVICE_NAME}" echo - 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 + read -r -s -n1 -t 5 echo while true; do trap break 2 -- cgit v1.2.3 From 7b4cf2eb489d8f6c95ccac5af180254b78e7c460 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 29 Mar 2020 15:09:34 +0200 Subject: tooling box: simplify build enviroments - no more need for a .config.mk - docs: use searx.brands environment - searx.sh, filtron.sh & morty.sh are sourcing utils/brand.env Signed-off-by: Markus Heiser --- utils/morty.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 58de0cc99..a20cde36c 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -4,6 +4,8 @@ # shellcheck source=utils/lib.sh source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" +# shellcheck source=utils/brand.env +source "${REPO_ROOT}/utils/brand.env" source_dot_config source "${REPO_ROOT}/utils/lxc-searx.env" in_container && lxc_set_suite_env @@ -12,8 +14,9 @@ in_container && lxc_set_suite_env # config # ---------------------------------------------------------------------------- -PUBLIC_URL_PATH_MORTY="/morty" -PUBLIC_URL_MORTY="$(dirname "${PUBLIC_URL}")${PUBLIC_URL_PATH_MORTY}" +PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}" +PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty}" +PUBLIC_URL_MORTY="$(echo $PUBLIC_URL | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}" MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}" # shellcheck disable=SC2034 -- cgit v1.2.3 From 3e4d022d0425e4f7647573c97f105aa5208e5537 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 30 Mar 2020 11:03:46 +0200 Subject: [fix] make test.sh: fix various shellcheck error messages Signed-off-by: Markus Heiser --- utils/morty.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index a20cde36c..e6e14be8a 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -16,7 +16,7 @@ in_container && lxc_set_suite_env PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}" PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty}" -PUBLIC_URL_MORTY="$(echo $PUBLIC_URL | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}" +PUBLIC_URL_MORTY="$(echo "$PUBLIC_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}" MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}" # shellcheck disable=SC2034 -- cgit v1.2.3 From e32b08f61681da42104bc94b7b3266e41a79c58b Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 3 Apr 2020 20:26:20 +0200 Subject: utils/morty.sh: add generic documentation Signed-off-by: Markus Heiser --- utils/morty.sh | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index e6e14be8a..ec1d47cb6 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -194,11 +194,7 @@ main() { debug-off) disable_debug ;; *) usage "$_usage"; exit 42;; esac ;; - doc) - echo - echo ".. generic utils/morty.sh documentation" - ;; - + doc) rst-doc ;; *) usage "ERROR: unknown or missing command $1"; exit 42;; esac } @@ -436,6 +432,33 @@ This removes apache site ${APACHE_MORTY_SITE}." apache_remove_site "$APACHE_MORTY_SITE" } +rst-doc() { + + eval "echo \"$(< "${REPO_ROOT}/docs/build-templates/morty.rst")\"" + + echo -e "\n.. START install systemd unit" + cat < Date: Sat, 4 Apr 2020 17:53:16 +0200 Subject: misc: fix variuous marginals Signed-off-by: Markus Heiser --- utils/morty.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index ec1d47cb6..d79faa037 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -15,6 +15,7 @@ in_container && lxc_set_suite_env # ---------------------------------------------------------------------------- PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}" +PUBLIC_HOST="${PUBLIC_HOST:-$(echo "$PUBLIC_URL" | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')}" PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty}" PUBLIC_URL_MORTY="$(echo "$PUBLIC_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}" @@ -378,7 +379,6 @@ EOF return 0 } - enable_debug() { warn_msg "Do not enable debug in production enviroments!!" info_msg "Enabling debug option needs to reinstall systemd service!" -- cgit v1.2.3 From c81849cb5a22d937c0f1de1d02d1fb8e3a7849cd Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 5 Apr 2020 17:40:37 +0200 Subject: filtron.sh & morty.sh: improve usage message (if used in containers) BTW: normalize soma variable names Signed-off-by: Markus Heiser --- utils/morty.sh | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index d79faa037..17039a05e 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -83,39 +83,37 @@ apache : ${PUBLIC_URL_MORTY} :install: apache site with a reverse proxy (ProxyPass) :remove: apache site ${APACHE_MORTY_SITE} -If needed, set the environment variable MORTY_LISTEN in the -${DOT_CONFIG#"$REPO_ROOT/"} file:: - - MORTY_LISTEN : ${MORTY_LISTEN} - SERVICE_USER : ${SERVICE_USER} - +If needed, set the environment variables in the '${DOT_CONFIG#"$REPO_ROOT/"}' file:: + PUBLIC_URL_MORTY: ${PUBLIC_URL_MORTY} + MORTY_LISTEN: ${MORTY_LISTEN} + SERVICE_USER: ${SERVICE_USER} EOF if in_container; then - lxc_suite_info - else - info_msg "public URL --> ${PUBLIC_URL}" - info_msg "internal URL --> http://${SEARX_INTERNAL_URL}" + # in containers the service is listening on 0.0.0.0 (see lxc-searx.env) + for ip in $(global_IPs) ; do + if [[ $ip =~ .*:.* ]]; then + echo " container URL (IPv6): http://[${ip#*|}]:3000/" + else + # IPv4: + echo " container URL (IPv4): http://${ip#*|}:3000/" + fi + done fi + echo info_searx + [[ -n ${1} ]] && err_msg "$1" } info_searx() { # shellcheck disable=SC1117 cat < Date: Tue, 7 Apr 2020 18:31:51 +0200 Subject: apache: normalize installation (docs and script)s over all distros Signed-off-by: Markus Heiser --- utils/morty.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 17039a05e..4de411999 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -402,15 +402,12 @@ This installs a reverse proxy (ProxyPass) into apache site (${APACHE_MORTY_SITE} ! apache_is_installed && err_msg "Apache is not installed." - if ! ask_yn "Do you really want to continue?"; then + if ! ask_yn "Do you really want to continue?" Yn; then return + else + install_apache fi - a2enmod headers - a2enmod proxy - a2enmod proxy_http - - echo apache_install_site "${APACHE_MORTY_SITE}" info_msg "testing public url .." -- cgit v1.2.3 From f693149cded4f783380f8f02154bd9288b72cdd5 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 8 Apr 2020 18:38:36 +0200 Subject: Changes from the installation tests on (all) LXC containers. Tested and fixed HTTP & uWSGI installation on: ubu1604 ubu1804 ubu1910 ubu2004 fedora31 archlinux Signed-off-by: Markus Heiser --- utils/morty.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 4de411999..34d792dbe 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -14,12 +14,16 @@ in_container && lxc_set_suite_env # config # ---------------------------------------------------------------------------- -PUBLIC_URL="${PUBLIC_URL:-http://$(uname -n)/searx}" -PUBLIC_HOST="${PUBLIC_HOST:-$(echo "$PUBLIC_URL" | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')}" +MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}" PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty}" -PUBLIC_URL_MORTY="$(echo "$PUBLIC_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}" -MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}" +SEARX_URL="${PUBLIC_URL:-http://$(uname -n)/searx}" +PUBLIC_URL_MORTY="$(echo "$SEARX_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}" +if in_container; then + # container hostnames do not have a DNS entry, use primary IP + PUBLIC_URL_MORTY="$(url_replace_hostname "$PUBLIC_URL_MORTY" "$(primary_ip)")" +fi + # shellcheck disable=SC2034 MORTY_TIMEOUT=5 @@ -425,7 +429,7 @@ This removes apache site ${APACHE_MORTY_SITE}." ! apache_is_installed && err_msg "Apache is not installed." - if ! ask_yn "Do you really want to continue?"; then + if ! ask_yn "Do you really want to continue?" Yn; then return fi -- cgit v1.2.3 From 44edc9256932961f5fd3c0778da009c493d9ce35 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Thu, 9 Apr 2020 14:28:34 +0200 Subject: [fix] morty: PUBLIC_URL_PATH_MORTY needs trailing slash Signed-off-by: Markus Heiser --- utils/morty.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 34d792dbe..2aee0ac97 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -15,7 +15,7 @@ in_container && lxc_set_suite_env # ---------------------------------------------------------------------------- MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}" -PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty}" +PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty/}" SEARX_URL="${PUBLIC_URL:-http://$(uname -n)/searx}" PUBLIC_URL_MORTY="$(echo "$SEARX_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}" -- cgit v1.2.3 From 58d5da8b57c5aeab92f551e8d175be67537c351c Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sat, 11 Apr 2020 13:19:11 +0200 Subject: nginx: normalize installation (docs and script)s over all distros This is the revision of the documentation about the varous nginx installation variants. It also implements the nginx installation scripts for morty and filtron. Signed-off-by: Markus Heiser --- utils/morty.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 8 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 2aee0ac97..eae1b5bbc 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -47,6 +47,7 @@ CONFIG_FILES=() # Apache Settings APACHE_MORTY_SITE="morty.conf" +NGINX_MORTY_SITE="morty.conf" # ---------------------------------------------------------------------------- usage() { @@ -54,9 +55,7 @@ usage() { # shellcheck disable=SC1117 cat < Date: Mon, 13 Apr 2020 11:34:28 +0200 Subject: tooling box: added nginx + polished bash scripts and environment - add installation method for nginx sites, morty and filtron - clean up PUBLIC_URL environment in and outside of containers - clean up comand lines - handle uWSGI quirks on fedora (emperor mode) - handle Python quirks on debian (there is no 'python' command anymore) - lib.sh: add die and die_caller functions - lxc_suite_install_info is now a function - lint: shellcheck Signed-off-by: Markus Heiser --- utils/morty.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index eae1b5bbc..851b8864d 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -7,6 +7,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" # shellcheck source=utils/brand.env source "${REPO_ROOT}/utils/brand.env" source_dot_config +SEARX_URL="${PUBLIC_URL:-http://$(uname -n)/searx}" source "${REPO_ROOT}/utils/lxc-searx.env" in_container && lxc_set_suite_env @@ -17,12 +18,7 @@ in_container && lxc_set_suite_env MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}" PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty/}" -SEARX_URL="${PUBLIC_URL:-http://$(uname -n)/searx}" -PUBLIC_URL_MORTY="$(echo "$SEARX_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}" -if in_container; then - # container hostnames do not have a DNS entry, use primary IP - PUBLIC_URL_MORTY="$(url_replace_hostname "$PUBLIC_URL_MORTY" "$(primary_ip)")" -fi +PUBLIC_URL_MORTY="${PUBLIC_URL_MORTY:-$(echo "$SEARX_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}}" # shellcheck disable=SC2034 MORTY_TIMEOUT=5 @@ -229,6 +225,11 @@ install_all() { if ask_yn "Do you want to install a reverse proxy (ProxyPass)" Yn; then install_apache_site fi + elif nginx_is_installed; then + info_msg "nginx is installed on this host." + if ask_yn "Do you want to install a reverse proxy (ProxyPass)" Yn; then + install_nginx_site + fi fi info_searx if ask_yn "Add image and result proxy to searx settings.yml?" Yn; then @@ -462,7 +463,9 @@ This installs a reverse proxy (ProxyPass) into nginx site (${NGINX_MORTY_SITE})" "${REPO_ROOT}/utils/searx.sh" install uwsgi + # shellcheck disable=SC2034 SEARX_SRC=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_SRC) + # shellcheck disable=SC2034 SEARX_URL_PATH=$("${REPO_ROOT}/utils/searx.sh" --getenv SEARX_URL_PATH) nginx_install_app "${NGINX_MORTY_SITE}" -- cgit v1.2.3 From ea3255835a259516c7a8b62eb319a338cebf7e9f Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 28 Apr 2020 16:21:45 +0200 Subject: utils/morty.sh: set morty key to avoid service abuse - https://github.com/asciimoo/searx/issues/1871#issuecomment-592459798 make install all generates random MORTY_KEY, install service with that key and sets option in the searx settingy.yml file. Signed-off-by: Markus Heiser --- utils/morty.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 851b8864d..6b90db581 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -208,6 +208,9 @@ main() { } install_all() { + + MORTY_KEY="$(head -c 32 /dev/urandom | base64)" + rst_title "Install $SERVICE_NAME (service)" assert_user wait_key @@ -233,7 +236,7 @@ install_all() { fi info_searx if ask_yn "Add image and result proxy to searx settings.yml?" Yn; then - "${REPO_ROOT}/utils/searx.sh" option result-proxy "${PUBLIC_URL_MORTY}" + "${REPO_ROOT}/utils/searx.sh" option result-proxy "${PUBLIC_URL_MORTY}" "${MORTY_KEY}" "${REPO_ROOT}/utils/searx.sh" option image-proxy-on fi -- cgit v1.2.3 From 8829796f76bc74c584db1d2a83553ac0611372a0 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 28 Apr 2020 16:54:42 +0200 Subject: utils/morty.sh option new-key: set new morty key A command to set new morty key in morty & searx service (settings.yml) and to restart both services with new key:: utils/morty.sh option new-key Signed-off-by: Markus Heiser --- utils/morty.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'utils/morty.sh') diff --git a/utils/morty.sh b/utils/morty.sh index 6b90db581..75bfeeedf 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -59,7 +59,7 @@ usage:: $(basename "$0") activate [service] $(basename "$0") deactivate [service] $(basename "$0") inspect [service] - $(basename "$0") option [debug-on|debug-off] + $(basename "$0") option [debug-on|debug-off|new-key] $(basename "$0") apache [install|remove] $(basename "$0") nginx [install|remove] $(basename "$0") info [searx] @@ -79,6 +79,7 @@ inspect service show service status and log option set one of the available options + :new-key: set new morty key apache : ${PUBLIC_URL_MORTY} :install: apache site with a reverse proxy (ProxyPass) :remove: apache site ${APACHE_MORTY_SITE} @@ -198,6 +199,7 @@ main() { option) sudo_or_exit case $2 in + new-key) set_new_key ;; debug-on) enable_debug ;; debug-off) disable_debug ;; *) usage "$_usage"; exit 42;; @@ -410,6 +412,23 @@ disable_debug() { set_service_env_debug false } + +set_new_key() { + rst_title "Set morty key" + echo + + MORTY_KEY="$(head -c 32 /dev/urandom | base64)" + info_msg "morty key: '${MORTY_KEY}'" + + warn_msg "this will need to reinstall services .." + MSG="${_Green}press any [${_BCyan}KEY${_Green}] to continue // stop with [${_BCyan}CTRL-C${_creset}]" wait_key + + systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}" + "${REPO_ROOT}/utils/searx.sh" option result-proxy "${PUBLIC_URL_MORTY}" "${MORTY_KEY}" + "${REPO_ROOT}/utils/searx.sh" option image-proxy-on +} + + install_apache_site() { rst_title "Install Apache site $APACHE_MORTY_SITE" -- cgit v1.2.3