forked from zaclys/searxng
utils/filtron.sh: add command 'update filtron'
BTW: tidy up some code style and fix some issues reported by the linter. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
39feb141bc
commit
3ed82a97af
|
@ -12,8 +12,12 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||||
FILTRON_ETC="/etc/filtron"
|
FILTRON_ETC="/etc/filtron"
|
||||||
|
|
||||||
FILTRON_RULES="$FILTRON_ETC/rules.json"
|
FILTRON_RULES="$FILTRON_ETC/rules.json"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
FILTRON_API="127.0.0.1:4005"
|
FILTRON_API="127.0.0.1:4005"
|
||||||
|
# shellcheck disable=SC2034
|
||||||
FILTRON_LISTEN="127.0.0.1:4004"
|
FILTRON_LISTEN="127.0.0.1:4004"
|
||||||
|
# shellcheck disable=SC2034
|
||||||
FILTRON_TARGET="127.0.0.1:8888"
|
FILTRON_TARGET="127.0.0.1:8888"
|
||||||
|
|
||||||
SERVICE_NAME="filtron"
|
SERVICE_NAME="filtron"
|
||||||
|
@ -28,6 +32,7 @@ GO_ENV="${SERVICE_HOME}/.go_env"
|
||||||
GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
|
GO_PKG_URL="https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz"
|
||||||
GO_TAR=$(basename "$GO_PKG_URL")
|
GO_TAR=$(basename "$GO_PKG_URL")
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
CONFIG_FILES=(
|
CONFIG_FILES=(
|
||||||
"${FILTRON_RULES}"
|
"${FILTRON_RULES}"
|
||||||
"${SERVICE_SYSTEMD_UNIT}"
|
"${SERVICE_SYSTEMD_UNIT}"
|
||||||
|
@ -44,6 +49,7 @@ usage:
|
||||||
|
|
||||||
$(basename "$0") shell
|
$(basename "$0") shell
|
||||||
$(basename "$0") install [all|user]
|
$(basename "$0") install [all|user]
|
||||||
|
$(basename "$0") update [filtron]
|
||||||
$(basename "$0") remove [all]
|
$(basename "$0") remove [all]
|
||||||
$(basename "$0") activate [service]
|
$(basename "$0") activate [service]
|
||||||
$(basename "$0") deactivate [service]
|
$(basename "$0") deactivate [service]
|
||||||
|
@ -53,6 +59,8 @@ shell
|
||||||
start interactive shell from user ${SERVICE_USER}
|
start interactive shell from user ${SERVICE_USER}
|
||||||
install / remove all
|
install / remove all
|
||||||
complete setup of filtron service
|
complete setup of filtron service
|
||||||
|
update filtron
|
||||||
|
Update filtron installation of user ${SERVICE_USER}
|
||||||
activate
|
activate
|
||||||
activate and start service daemon (systemd unit)
|
activate and start service daemon (systemd unit)
|
||||||
deactivate service
|
deactivate service
|
||||||
|
@ -71,33 +79,39 @@ main(){
|
||||||
local _usage="ERROR: unknown or missing $1 command $2"
|
local _usage="ERROR: unknown or missing $1 command $2"
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
--source-only) ;;
|
--source-only) ;;
|
||||||
-h|--help) usage; exit 0;;
|
-h|--help) usage; exit 0;;
|
||||||
|
|
||||||
shell)
|
shell)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
interactive_shell
|
interactive_shell
|
||||||
;;
|
;;
|
||||||
show)
|
show)
|
||||||
case $2 in
|
case $2 in
|
||||||
service)
|
service)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
show_service
|
show_service
|
||||||
;;
|
;;
|
||||||
*) usage "$_usage"; exit 42;;
|
*) usage "$_usage"; exit 42;;
|
||||||
esac ;;
|
esac ;;
|
||||||
install)
|
install)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
case $2 in
|
case $2 in
|
||||||
all) install_all ;;
|
all) install_all ;;
|
||||||
user) assert_user ;;
|
user) assert_user ;;
|
||||||
|
*) usage "$_usage"; exit 42;;
|
||||||
|
esac ;;
|
||||||
|
update)
|
||||||
|
sudo_or_exit
|
||||||
|
case $2 in
|
||||||
|
filtron) update_filtron ;;
|
||||||
*) usage "$_usage"; exit 42;;
|
*) usage "$_usage"; exit 42;;
|
||||||
esac ;;
|
esac ;;
|
||||||
remove)
|
remove)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
case $2 in
|
case $2 in
|
||||||
all) remove_all;;
|
all) remove_all;;
|
||||||
user) remove_user ;;
|
user) remove_user ;;
|
||||||
*) usage "$_usage"; exit 42;;
|
*) usage "$_usage"; exit 42;;
|
||||||
esac ;;
|
esac ;;
|
||||||
activate)
|
activate)
|
||||||
|
@ -242,16 +256,24 @@ EOF
|
||||||
install_template --no-eval "$FILTRON_RULES" root root 644
|
install_template --no-eval "$FILTRON_RULES" root root 644
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_filtron() {
|
||||||
|
rst_title "Update filtron" section
|
||||||
|
echo
|
||||||
|
tee_stderr <<EOF | sudo -i -u "$SERVICE_USER" 2>&1 | prefix_stdout "$_service_prefix"
|
||||||
|
go get -v -u github.com/asciimoo/filtron
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
show_service () {
|
show_service () {
|
||||||
rst_title "service status & log"
|
rst_title "service status & log"
|
||||||
echo
|
echo
|
||||||
systemctl status filtron.service
|
systemctl status filtron.service
|
||||||
echo
|
echo
|
||||||
read -s -n1 -t 5 -p "// use CTRL-C to stop monitoring the log"
|
read -r -s -n1 -t 5 -p "// use CTRL-C to stop monitoring the log"
|
||||||
echo
|
echo
|
||||||
while true; do
|
while true; do
|
||||||
trap break 2
|
trap break 2
|
||||||
journalctl -f -u filtron
|
journalctl -f -u filtron
|
||||||
done
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ info_msg() { echo -e "INFO: $*"; }
|
||||||
|
|
||||||
clean_stdin() {
|
clean_stdin() {
|
||||||
if [[ $(uname -s) != 'Darwin' ]]; then
|
if [[ $(uname -s) != 'Darwin' ]]; then
|
||||||
while $(read -n1 -t 0.1); do : ; done
|
while read -n1 -t 0.1; do : ; done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue