From: George Sapkin Date: Wed, 6 Aug 2025 19:41:53 +0000 (+0300) Subject: syncthing: improve discovery argument parsing X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=6ccb3b6174d319666bcdd1319b2be4fa7cbd9b30;p=feed%2Fpackages.git syncthing: improve discovery argument parsing Fixes: 47644ba46 ("syncthing: fix discovery and relay extra args") Signed-off-by: George Sapkin --- diff --git a/utils/syncthing/files/stdiscosrv.conf b/utils/syncthing/files/stdiscosrv.conf index 3e04014513..5606c5f252 100644 --- a/utils/syncthing/files/stdiscosrv.conf +++ b/utils/syncthing/files/stdiscosrv.conf @@ -7,11 +7,13 @@ config stdiscosrv 'stdiscosrv' # Find the documents from: https://docs.syncthing.net/users/stdiscosrv.html # option cert '/etc/stdiscosrv/cert.pem' # option key '/etc/stdiscosrv/key.pem' - # option db_flush_interval '5m' + # option db_flush_interval '5m' # option metrics_listen '' - # CLI options with no value should be defined as booleans and theirs names - # should be prefixed with '_'. - # option _compression '0' - # option _debug '0' - # option _http '1' + # Running as 'root' is possible, but not recommended + # option user 'syncthing' + + # CLI options with no value should be defined as booleans + # option compression '0' + # option debug '0' + # option http '1' diff --git a/utils/syncthing/files/stdiscosrv.init b/utils/syncthing/files/stdiscosrv.init index 7ad243a202..bc1da536a5 100644 --- a/utils/syncthing/files/stdiscosrv.init +++ b/utils/syncthing/files/stdiscosrv.init @@ -13,43 +13,36 @@ config_cb() { option_cb() { local option="$1" local value="$2" - case $option in - enabled|listen|cert|db_dir|key) - eval $option=$value - ;; - _*) - [ "$value" = "0" ] || extra_args="$extra_args -${option//_/-}" - ;; - *) - extra_args="$extra_args --${option//_/-}='$value'" - ;; - esac - } - - list_cb() { - local name="$1" - local value="$2" - [ "$name" = "_" ] && extra_args="$extra_args --${value//_/-}" || return 0 + # Remove the leading underscore from the option name for backward + # compatibility + option="${option#_}" + eval $option="$value" } } service_triggers() { - procd_add_reload_trigger "stdiscosrv" + procd_add_reload_trigger 'stdiscosrv' } start_service() { - local extra_args - # Options with default value different with the syncthing should be defined explicitly here + local conf_dir='/etc/stdiscosrv' + + # Options with default value different with the syncthing should be defined + # explicitly here local enabled=0 - local listen=":8443" - local conf_dir="/etc/stdiscosrv" + local compression=0 local cert="$conf_dir/cert.pem" - local key="$conf_dir/key.pem" local db_dir="$conf_dir/discovery.db" + local db_flush_interval='' + local debug=0 + local http=0 + local key="$conf_dir/key.pem" + local listen=':8443' + local metrics_listen='' local nice=0 - local user="syncthing" + local user='syncthing' - config_load "stdiscosrv" + config_load 'stdiscosrv' [ "$enabled" -gt 0 ] || return 0 @@ -58,19 +51,22 @@ start_service() { [ -d "$db_dir" ] || mkdir -p "$db_dir" [ -d "$conf_dir" ] && chown -R "$user":"$group" "$conf_dir" - config_get nice stdiscosrv nice "0" - procd_open_instance procd_set_param command "$PROG" - procd_append_param command --listen="$listen" - procd_append_param command --db-dir="$db_dir" procd_append_param command --cert="$cert" + [ "$compression" -eq 0 ] || procd_append_param command --compression + procd_append_param command --db-dir="$db_dir" + [ -z "$db_flush_interval" ] || procd_append_param command --db-flush-interval="$db_flush_interval" + [ "$debug" -eq 0 ] || procd_append_param command --debug + [ "$http" -eq 0 ] || procd_append_param command --http procd_append_param command --key="$key" - [ -z "$extra_args" ] || procd_append_param command "$extra_args" + procd_append_param command --listen="$listen" + [ -z "$metrics_listen" ] || procd_append_param command --metrics-listen="$metrics_listen" procd_set_param nice "$nice" procd_set_param term_timeout 15 procd_set_param user "$user" + procd_set_param group "$group" procd_set_param respawn procd_set_param stdout 1 procd_set_param stderr 1