syncthing: validate strelaysrv config
authorGeorge Sapkin <redacted>
Fri, 13 Mar 2026 23:32:09 +0000 (01:32 +0200)
committerHannu Nyman <redacted>
Sat, 21 Mar 2026 13:49:07 +0000 (15:49 +0200)
Validate UCI config for strelaysrv service.

Switch instance name to strelaysrv.

Signed-off-by: George Sapkin <redacted>
utils/syncthing/files/strelaysrv.conf
utils/syncthing/files/strelaysrv.init

index 4f4f26f912b4eadbe9435b0f06519d5858ea78a9..9accd28033e9670d1f3efc0f408e234a94fdd154 100644 (file)
@@ -22,6 +22,7 @@ config strelaysrv 'strelaysrv'
 
        # Running as 'root' is possible, but not recommended
        # option user 'syncthing'
+       # option group 'syncthing'
 
        # CLI options with no value should be defined as booleans
        # option debug '0'
index 5e4c55e14acf2782222e12a29a54a65f536729e4..95e33cb657c6fb06154e1a192e1761c0bae579cf 100644 (file)
@@ -5,68 +5,60 @@
 START=90
 STOP=10
 
-USE_PROCD=1
-
 PROG=/usr/bin/strelaysrv
-
-config_cb() {
-       [ $# -eq 0 ] && return
-
-       option_cb() {
-               local option="$1"
-               local value="$2"
-               # Remove the leading underscore from the option name for backward
-               # compatibility
-               option="${option#_}"
-               eval $option="$value"
-       }
-}
+USE_PROCD=1
 
 service_triggers() {
        procd_add_reload_trigger 'strelaysrv'
 }
 
 start_service() {
-       # Options with default value different with the syncthing should be defined
-       # explicitly here
-       local enabled=0
-       local debug=0
-       local ext_address=''
-       local gc=0
-       local global_rate=''
-       local keys='/etc/strelaysrv'
-       local listen=':22067'
-       local maxprocs=0
-       local memlimit=0
-       local message_timeout=''
-       local nat=0
-       local nat_lease=''
-       local nat_renewal=''
-       local nat_timeout=''
-       local network_timeout=''
-       local nice=0
-       local per_session_rate=''
-       local ping_interval=''
-       local pools=''
-       local pprof=0
-       local protocol=''
-       local provided_by=''
-       local status_srv=''
-       local token=''
-       local user='syncthing'
-
        config_load 'strelaysrv'
 
-       [ "$enabled" -gt 0 ] || return 0
-
-       local group=$(id -gn $user)
+       local config_name="strelaysrv"
+       local debug enabled ext_address global_rate keys listen memlimit \
+               message_timeout nat nat_lease nat_renewal nat_timeout network_timeout \
+               nice per_session_rate ping_interval pools pprof protocol provided_by \
+               status_srv token user
+
+       local gc maxprocs memlimit
+
+       uci_validate_section 'strelaysrv' 'strelaysrv' "$config_name" \
+               'debug:bool:0' \
+               'enabled:bool:0' \
+               'ext_address:string' \
+               'gc:uinteger:0' \
+               'global_rate:string' \
+               'group:string:syncthing' \
+               'keys:string:/etc/strelaysrv' \
+               'listen:string::22067' \
+               'maxprocs:uinteger:0' \
+               'memlimit:uinteger:0' \
+               'message_timeout:string' \
+               'nat:bool:0' \
+               'nat_lease:string' \
+               'nat_renewal:string' \
+               'nat_timeout:string' \
+               'network_timeout:string' \
+               'nice:range(-20,19):0' \
+               'per_session_rate:string' \
+               'ping_interval:string' \
+               'pools:string' \
+               'pprof:bool:0' \
+               'protocol:or("tcp", "tcp4", "tcp6"):tcp' \
+               'provided_by:string' \
+               'status_srv:string' \
+               'token:string' \
+               'user:string:syncthing'
+
+       [ "$enabled" = 1 ] || return 0
+
+       [ -z "$group" ] && group=$(id -gn "$user")
 
        mkdir -p "$keys"
-       [ -d "$keys" ] && chown -R "$user":"$group" "$keys"
-
-       config_get nice strelaysrv nice "0"
+       [ -d "$keys" ] && chown -R "$user:$group" "$keys"
 
-       procd_open_instance
+       procd_open_instance strelaysrv
 
        procd_set_param command "$PROG"
 
@@ -75,41 +67,35 @@ start_service() {
        [ "$memlimit" -le 0 ] || procd_append_param env GOMEMLIMIT="$memlimit"
 
        [ "$debug" -eq 0 ] || procd_append_param command -debug
-       [ -z "$ext_address" ] || \
+       [ -z "$ext_address" ] ||
                procd_append_param command -ext-address="$ext_address"
-       [ -z "$global_rate" ] || \
+       [ -z "$global_rate" ] ||
                procd_append_param command -global-rate="$global_rate"
        procd_append_param command -keys="$keys"
-       [ -z "$listen" ] || \
-               procd_append_param command -listen="$listen"
-       [ -z "$message_timeout" ] || \
+       [ -z "$listen" ] || procd_append_param command -listen="$listen"
+       [ -z "$message_timeout" ] ||
                procd_append_param command -message-timeout="$message_timeout"
-       [ "$nat" -eq 0 ] || \
-               procd_append_param command -nat
-       [ -z "$nat_lease" ] || \
-               procd_append_param command -nat-lease="$nat_lease"
-       [ -z "$nat_renewal" ] || \
+       [ "$nat" -eq 0 ] || procd_append_param command -nat
+       [ -z "$nat_lease" ] || procd_append_param command -nat-lease="$nat_lease"
+       [ -z "$nat_renewal" ] ||
                procd_append_param command -nat-renewal="$nat_renewal"
-       [ -z "$nat_timeout" ] || \
+       [ -z "$nat_timeout" ] ||
                procd_append_param command -nat-timeout="$nat_timeout"
-       [ -z "$network_timeout" ] || \
+       [ -z "$network_timeout" ] ||
                procd_append_param command -network-timeout="$network_timeout"
-       [ -z "$per_session_rate" ] || \
+       [ -z "$per_session_rate" ] ||
                procd_append_param command -per-session-rate="$per_session_rate"
-       [ -z "$ping_interval" ] || \
+       [ -z "$ping_interval" ] ||
                procd_append_param command -ping-interval="$ping_interval"
        # pools is set to an empty value by default
        procd_append_param command -pools="$pools"
-       [ "$pprof" -eq 0 ] || \
-               procd_append_param command -pprof
-       [ -z "$protocol" ] || \
-               procd_append_param command -protocol="$protocol"
-       [ -z "$provided_by" ] || \
+       [ "$pprof" -eq 0 ] || procd_append_param command -pprof
+       [ -z "$protocol" ] || procd_append_param command -protocol="$protocol"
+       [ -z "$provided_by" ] ||
                procd_append_param command -provided-by="$provided_by"
        # status-srv is set to an empty value by default
        procd_append_param command -status-srv="$status_srv"
-       [ -z "$token" ] || \
-               procd_append_param command -token="$token"
+       [ -z "$token" ] || procd_append_param command -token="$token"
 
        procd_set_param nice "$nice"
        procd_set_param term_timeout 15
git clone https://git.99rst.org/PROJECT