Merge pull request #38 from return42/filtron-rules

[filtron.sh] make filtron rule file configurable
This commit is contained in:
Alexandre Flament 2021-04-29 10:31:59 +02:00 committed by GitHub
commit 3282cdca13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 9 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 interactive 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 interactive 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"

View File

@ -461,7 +461,7 @@ install_template() {
choose_one _reply "choose next step with file $dst" \ choose_one _reply "choose next step with file $dst" \
"replace file" \ "replace file" \
"leave file unchanged" \ "leave file unchanged" \
"interactiv shell" \ "interactive shell" \
"diff files" "diff files"
case $_reply in case $_reply in
@ -474,7 +474,7 @@ install_template() {
"leave file unchanged") "leave file unchanged")
break break
;; ;;
"interactiv shell") "interactive shell")
echo -e "// edit ${_Red}${dst}${_creset} to your needs" echo -e "// edit ${_Red}${dst}${_creset} to your needs"
echo -e "// exit with [${_BCyan}CTRL-D${_creset}]" echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
sudo -H -u "${owner}" -i sudo -H -u "${owner}" -i

View File

@ -436,7 +436,7 @@ install_settings() {
choose_one action "What should happen to the settings file? " \ choose_one action "What should happen to the settings file? " \
"keep configuration unchanged" \ "keep configuration unchanged" \
"use origin settings" \ "use origin settings" \
"start interactiv shell" "start interactive shell"
case $action in case $action in
"keep configuration unchanged") "keep configuration unchanged")
info_msg "leave settings file unchanged" info_msg "leave settings file unchanged"
@ -446,7 +446,7 @@ install_settings() {
info_msg "install origin settings" info_msg "install origin settings"
cp "${SEARX_SETTINGS_TEMPLATE}" "${SEARX_SETTINGS_PATH}" cp "${SEARX_SETTINGS_TEMPLATE}" "${SEARX_SETTINGS_PATH}"
;; ;;
"start interactiv shell") "start interactive shell")
backup_file "${SEARX_SETTINGS_PATH}" backup_file "${SEARX_SETTINGS_PATH}"
echo -e "// exit with [${_BCyan}CTRL-D${_creset}]" echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
sudo -H -i sudo -H -i