summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-04-29 10:31:59 +0200
committerGitHub <noreply@github.com>2021-04-29 10:31:59 +0200
commit3282cdca13b3aae093a23a45aad6729c286b1eb4 (patch)
tree53d12de0cb008bb4959fbeb54be691addca8cc08
parent1e3148fea94429f62cc577d1790e414afe2c7896 (diff)
parent666bf1d32b7ce53133025c5471746e494deeeade (diff)
Merge pull request #38 from return42/filtron-rules
[filtron.sh] make filtron rule file configurable
-rw-r--r--.config.sh1
-rwxr-xr-xutils/filtron.sh50
-rwxr-xr-xutils/lib.sh4
-rwxr-xr-xutils/searx.sh4
4 files changed, 50 insertions, 9 deletions
diff --git a/.config.sh b/.config.sh
index 7eed5f681..e9e79d82c 100644
--- a/.config.sh
+++ b/.config.sh
@@ -40,6 +40,7 @@ fi
# FILTRON_API="127.0.0.1:4005"
# FILTRON_LISTEN="127.0.0.1:4004"
# FILTRON_TARGET="127.0.0.1:8888"
+# FILTRON_RULES_TEMPLATE="${REPO_ROOT}/utils/templates/etc/searx/use_default_settings.yml"
# morty.sh
# --------
diff --git a/utils/filtron.sh b/utils/filtron.sh
index 6034cb343..5680811ea 100755
--- a/utils/filtron.sh
+++ b/utils/filtron.sh
@@ -24,6 +24,7 @@ FILTRON_URL_PATH="${FILTRON_URL_PATH:-$(echo "${PUBLIC_URL}" \
FILTRON_ETC="/etc/filtron"
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_LISTEN="${FILTRON_LISTEN:-127.0.0.1:4004}"
@@ -94,7 +95,7 @@ nginx (${PUBLIC_URL})
:install: nginx site with a reverse proxy (ProxyPass)
: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::
PUBLIC_URL : ${PUBLIC_URL}
@@ -148,9 +149,7 @@ main() {
all) install_all ;;
user) assert_user ;;
rules)
- rst_title "Re-Install filtron rules"
- echo
- install_template --no-eval "$FILTRON_RULES" root root 644
+ install_rules
systemd_restart_service "${SERVICE_NAME}"
;;
*) usage "$_usage"; exit 42;;
@@ -213,6 +212,7 @@ install_all() {
install_go "${GO_PKG_URL}" "${GO_TAR}" "${SERVICE_USER}"
wait_key
install_filtron
+ install_rules
wait_key
systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
wait_key
@@ -292,7 +292,6 @@ install_filtron() {
tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_svcpr"
go get -v -u github.com/asciimoo/filtron
EOF
- install_template --no-eval "$FILTRON_RULES" root root 644
}
update_filtron() {
@@ -303,6 +302,47 @@ go get -v -u github.com/asciimoo/filtron
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() {
rst_title "service status & log"
diff --git a/utils/lib.sh b/utils/lib.sh
index d1781a71f..8867bfe8e 100755
--- a/utils/lib.sh
+++ b/utils/lib.sh
@@ -461,7 +461,7 @@ install_template() {
choose_one _reply "choose next step with file $dst" \
"replace file" \
"leave file unchanged" \
- "interactiv shell" \
+ "interactive shell" \
"diff files"
case $_reply in
@@ -474,7 +474,7 @@ install_template() {
"leave file unchanged")
break
;;
- "interactiv shell")
+ "interactive shell")
echo -e "// edit ${_Red}${dst}${_creset} to your needs"
echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
sudo -H -u "${owner}" -i
diff --git a/utils/searx.sh b/utils/searx.sh
index 2d2358344..a5345c075 100755
--- a/utils/searx.sh
+++ b/utils/searx.sh
@@ -436,7 +436,7 @@ install_settings() {
choose_one action "What should happen to the settings file? " \
"keep configuration unchanged" \
"use origin settings" \
- "start interactiv shell"
+ "start interactive shell"
case $action in
"keep configuration unchanged")
info_msg "leave settings file unchanged"
@@ -446,7 +446,7 @@ install_settings() {
info_msg "install origin settings"
cp "${SEARX_SETTINGS_TEMPLATE}" "${SEARX_SETTINGS_PATH}"
;;
- "start interactiv shell")
+ "start interactive shell")
backup_file "${SEARX_SETTINGS_PATH}"
echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
sudo -H -i