From 924bf6551794e5962688c1e2962dc0c94869e2f1 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 29 Jan 2020 20:00:50 +0100 Subject: utils/searx.sh & filtron.sh: misc changes from first tests (WIP) Signed-off-by: Markus Heiser --- utils/filtron.sh | 155 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 114 insertions(+), 41 deletions(-) (limited to 'utils/filtron.sh') diff --git a/utils/filtron.sh b/utils/filtron.sh index 7defe1ec5..6ea001d42 100755 --- a/utils/filtron.sh +++ b/utils/filtron.sh @@ -5,6 +5,7 @@ # shellcheck source=utils/lib.sh source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" +source_dot_config # ---------------------------------------------------------------------------- # config @@ -30,7 +31,9 @@ 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") -APACHE_SITE="searx.conf" +# Apache Settings + +APACHE_FILTRON_SITE="searx.conf" # shellcheck disable=SC2034 CONFIG_FILES=( @@ -53,22 +56,32 @@ usage: $(basename "$0") remove [all] $(basename "$0") activate [service] $(basename "$0") deactivate [service] - $(basename "$0") show [service] + $(basename "$0") inspect [service] + $(basename "$0") apache [install|remove] + shell start interactive shell from user ${SERVICE_USER} -install / remove all - complete setup of filtron service +install / remove + all: complete setup of filtron service + user: add/remove service user '$SERVICE_USER' at $SERVICE_HOME update filtron Update filtron installation of user ${SERVICE_USER} -activate +activate service activate and start service daemon (systemd unit) deactivate service stop and deactivate service daemon (systemd unit) -install user - add service user '$SERVICE_USER' at $SERVICE_HOME -show service +inspect service show service status and log +apache + install: apache site with a reverse proxy (ProxyPass) + remove: apache site ${APACHE_FILTRON_SITE} + +If needed change the environment variable PUBLIC_URL of your WEB service in the +${DOT_CONFIG#"$REPO_ROOT/"} file: + + PUBLIC_URL : ${PUBLIC_URL} + EOF [ ! -z ${1+x} ] && echo -e "$1" } @@ -76,6 +89,10 @@ EOF main() { rst_title "$SERVICE_NAME" part + required_commands \ + dpkg apt-get install git wget curl \ + || exit + local _usage="ERROR: unknown or missing $1 command $2" case $1 in @@ -86,11 +103,11 @@ main() { sudo_or_exit interactive_shell ;; - show) + inspect) case $2 in service) sudo_or_exit - show_service + inspect_service ;; *) usage "$_usage"; exit 42;; esac ;; @@ -126,6 +143,14 @@ main() { service) deactivate_service ;; *) usage "$_usage"; exit 42;; esac ;; + apache) + sudo_or_exit + case $2 in + install) install_apache_site ;; + remove) remove_apache_site ;; + *) usage "$_usage"; exit 42;; + esac ;; + *) usage "ERROR: unknown or missing command $1"; exit 42;; esac } @@ -140,14 +165,29 @@ install_all() { wait_key install_service wait_key + echo + if ! service_is_available "http://${FILTRON_LISTEN}" ; then + err_msg "Filtron does not listening on: http://${FILTRON_LISTEN}" + fi if apache_is_installed; then - install_apache_site - wait_key + 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 + } remove_all() { rst_title "De-Install $SERVICE_NAME (service)" + + rst_para "\ +It goes without saying that this script can only be used to remove +installations that were installed with this script." + remove_service wait_key remove_user @@ -155,18 +195,6 @@ remove_all() { wait_key } -filtron_is_available() { - curl --insecure "http://${FILTRON_LISTEN}" &>/dev/null -} - -api_is_available() { - curl --insecure "http://${FILTRON_API}" &>/dev/null -} - -target_is_available() { - curl --insecure "http://${FILTRON_TARGET}" &>/dev/null -} - install_service() { rst_title "Install System-D Unit ${SERVICE_NAME}.service" section echo @@ -191,7 +219,7 @@ systemctl enable $SERVICE_NAME.service systemctl restart $SERVICE_NAME.service EOF tee_stderr <&1 -systemctl status $SERVICE_NAME.service +systemctl status --no-pager $SERVICE_NAME.service EOF } @@ -265,9 +293,8 @@ mkdir -p \$HOME/local rm -rf \$HOME/local/go tar -C \$HOME/local -xzf ${CACHE}/${GO_TAR} EOF - echo sudo -i -u "$SERVICE_USER" </dev/null && echo "Go Installation not found in PATH!?!" +! which go >/dev/null && echo "ERROR - Go Installation not found in PATH!?!" which go >/dev/null && go version && echo "congratulations -- Go installation OK :)" EOF } @@ -293,9 +320,20 @@ go get -v -u github.com/asciimoo/filtron EOF } -show_service() { +inspect_service() { + rst_title "service status & log" - echo + + cat <