[filtron.sh] make filtron rule file configurable

To select a different file with filtron rules, set environment

    FILTRON_RULES_TEMPLATE

the default is

    utils/templates/etc/filtron/rules.json

The installation is done by the new function install_rules() which offers a
multiple choice in case of collisions (known from searx.sh install setup).

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2021-04-28 12:10:10 +02:00
parent fe3831db1a
commit d9ffb09011
2 changed files with 46 additions and 5 deletions

View file

@ -40,6 +40,7 @@ fi
# FILTRON_API="127.0.0.1:4005" # FILTRON_API="127.0.0.1:4005"
# FILTRON_LISTEN="127.0.0.1:4004" # FILTRON_LISTEN="127.0.0.1:4004"
# FILTRON_TARGET="127.0.0.1:8888" # FILTRON_TARGET="127.0.0.1:8888"
# FILTRON_RULES_TEMPLATE="${REPO_ROOT}/utils/templates/etc/searx/use_default_settings.yml"
# morty.sh # morty.sh
# -------- # --------

View file

@ -24,6 +24,7 @@ FILTRON_URL_PATH="${FILTRON_URL_PATH:-$(echo "${PUBLIC_URL}" \
FILTRON_ETC="/etc/filtron" FILTRON_ETC="/etc/filtron"
FILTRON_RULES="$FILTRON_ETC/rules.json" FILTRON_RULES="$FILTRON_ETC/rules.json"
FILTRON_RULES_TEMPLATE="${FILTRON_RULES_TEMPLATE:-${REPO_ROOT}/utils/templates/etc/filtron/rules.json}"
FILTRON_API="${FILTRON_API:-127.0.0.1:4005}" FILTRON_API="${FILTRON_API:-127.0.0.1:4005}"
FILTRON_LISTEN="${FILTRON_LISTEN:-127.0.0.1:4004}" FILTRON_LISTEN="${FILTRON_LISTEN:-127.0.0.1:4004}"
@ -94,7 +95,7 @@ nginx (${PUBLIC_URL})
:install: nginx site with a reverse proxy (ProxyPass) :install: nginx site with a reverse proxy (ProxyPass)
:remove: nginx site ${NGINX_FILTRON_SITE} :remove: nginx site ${NGINX_FILTRON_SITE}
filtron rules: ${FILTRON_RULES} filtron rules: ${FILTRON_RULES_TEMPLATE}
If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file:: If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"}' file::
PUBLIC_URL : ${PUBLIC_URL} PUBLIC_URL : ${PUBLIC_URL}
@ -148,9 +149,7 @@ main() {
all) install_all ;; all) install_all ;;
user) assert_user ;; user) assert_user ;;
rules) rules)
rst_title "Re-Install filtron rules" install_rules
echo
install_template --no-eval "$FILTRON_RULES" root root 644
systemd_restart_service "${SERVICE_NAME}" systemd_restart_service "${SERVICE_NAME}"
;; ;;
*) usage "$_usage"; exit 42;; *) usage "$_usage"; exit 42;;
@ -213,6 +212,7 @@ install_all() {
install_go "${GO_PKG_URL}" "${GO_TAR}" "${SERVICE_USER}" install_go "${GO_PKG_URL}" "${GO_TAR}" "${SERVICE_USER}"
wait_key wait_key
install_filtron install_filtron
install_rules
wait_key wait_key
systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}" systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
wait_key wait_key
@ -292,7 +292,6 @@ install_filtron() {
tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr" tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr"
go get -v -u github.com/asciimoo/filtron go get -v -u github.com/asciimoo/filtron
EOF EOF
install_template --no-eval "$FILTRON_RULES" root root 644
} }
update_filtron() { update_filtron() {
@ -303,6 +302,47 @@ go get -v -u github.com/asciimoo/filtron
EOF EOF
} }
install_rules() {
rst_title "Install filtron rules"
echo
if [[ ! -f "${FILTRON_RULES}" ]]; then
info_msg "install rules ${FILTRON_RULES_TEMPLATE}"
info_msg " --> ${FILTRON_RULES}"
mkdir -p "$(dirname "${FILTRON_RULES}")"
cp "${FILTRON_RULES_TEMPLATE}" "${FILTRON_RULES}"
return
fi
rst_para "Diff between origin's rules file (+) and current (-):"
echo "${FILTRON_RULES}" "${FILTRON_RULES_TEMPLATE}"
$DIFF_CMD "${FILTRON_RULES}" "${FILTRON_RULES_TEMPLATE}"
local action
choose_one action "What should happen to the rules file? " \
"keep configuration unchanged" \
"use origin rules" \
"start interactiv shell"
case $action in
"keep configuration unchanged")
info_msg "leave rules file unchanged"
;;
"use origin rules")
backup_file "${FILTRON_RULES}"
info_msg "install origin rules"
cp "${FILTRON_RULES_TEMPLATE}" "${FILTRON_RULES}"
;;
"start interactiv shell")
backup_file "${FILTRON_RULES}"
echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
sudo -H -i
rst_para 'Diff between new rules file (-) and current (+):'
echo
$DIFF_CMD "${FILTRON_RULES_TEMPLATE}" "${FILTRON_RULES}"
wait_key
;;
esac
}
inspect_service() { inspect_service() {
rst_title "service status & log" rst_title "service status & log"