openvpn: shellcheck fixes
authorPaul Donald <redacted>
Wed, 11 Mar 2026 18:57:38 +0000 (19:57 +0100)
committerHannu Nyman <redacted>
Sun, 15 Mar 2026 06:45:36 +0000 (08:45 +0200)
correct spacing for [] if blocks and var quoting.
use json_get_vars to get user-defined scripts so the
setenv parameters are appended to the command line.

handle ovpnproto as a PROTO_STRING so it is monitored
and loaded.

follow-up to 337a449c03c597b49f2e18a7fd241d8945288e80
and 647b67e18b6bf857e60e4e2e1874fd04d4138586

Signed-off-by: Paul Donald <redacted>
net/openvpn/files/lib/netifd/proto/openvpn.sh
net/openvpn/files/usr/libexec/openvpn-hotplug

index 5ee97dd3f8ea5b02511c7f27afba4da1eadd2e24..33ffdcf5a0d5a5cb02b7f707c588ca8ac96c9906 100755 (executable)
@@ -84,6 +84,7 @@ PROTO_STRINGS='
 username
 password
 cert_password
+ovpnproto
 '
 
 proto_openvpn_init_config() {
@@ -119,6 +120,7 @@ proto_openvpn_setup() {
        json_get_var ovpnproto ovpnproto
        [ -n "$ovpnproto" ] && append exec_params " --proto $ovpnproto"
 
+       json_get_var config_file config
        # shellcheck disable=SC2154
        cd_dir="${config_file%/*}"
        [ "$cd_dir" = "$config_file" ] && cd_dir="/"
@@ -140,10 +142,7 @@ proto_openvpn_setup() {
 
        proto_add_dynamic_defaults
 
-       json_get_var username username
-       json_get_var password password
-       json_get_var cert_password cert_password
-       json_get_var config_file config
+       json_get_vars username password cert_password
 
        mkdir -p /var/run
        # combine into --askpass:
@@ -179,12 +178,15 @@ proto_openvpn_setup() {
 
        # Add default hotplug handling if 'script_security' option is equal '3'
        if [ "$script_security" -eq '3' ]; then
+               local up down route_up route_pre_down
+               local client tls_client
                logger -t "openvpn(proto)" \
                        -p daemon.info "Enabled default hotplug processing, as the openvpn configuration 'script_security' is '3'"
 
                append exec_params " --setenv INTERFACE $config"
                append exec_params " --script-security 3"
 
+               json_get_vars up down route_up route_pre_down
                append exec_params "--up '/usr/libexec/openvpn-hotplug'"
                [ -n "$up" ] && append exec_params "--setenv user_up '$up'"
 
@@ -197,11 +199,11 @@ proto_openvpn_setup() {
                append exec_params "--route-pre-down '/usr/libexec/openvpn-hotplug'"
                [ -n "$route_pre_down" ] && append exec_params "--setenv user_route_pre_down '$route_pre_down'"
 
-               json_get_var client client
-               json_get_var tls_client tls_client
+               json_get_vars client tls_client
                if [ "$client" = 1 ] || [ "$tls_client" = 1 ]; then
                        append exec_params "--ipchange '/usr/libexec/openvpn-hotplug'"
-                       [ -n "$ip_change" ] && append exec_params "--setenv user_ipchange '$ipchange'"
+                       json_get_var ipchange ipchange
+                       [ -n "$ipchange" ] && append exec_params "--setenv user_ipchange '$ipchange'"
                fi
        else
                logger -t "openvpn(proto)" \
index dcc5b01df966478af55bf7073405b27086494404..a6022ca23589fd98490cdaa820e98c4790ce8b86 100644 (file)
@@ -1,11 +1,11 @@
 #!/bin/sh
 
-[ -z "$script_type"] && {
+[ -z "$script_type" ] && {
        logger -t "openvpn(proto)" -p daemon.warn "hotplug: variable 'script_type' not found"
        exit
 }
 
-[ -z "$INTERFACE"] && {
+[ -z "$INTERFACE" ] && {
        logger -t "openvpn(proto)" -p daemon.warn "hotplug: variable 'INTERFACE' not found"
        exit
 }
@@ -13,6 +13,6 @@
 ACTION="$script_type"
 INSTANCE="$INTERFACE"
 
-export ACTION=$ACTION
-export INSTANCE=$INSTANCE
+export ACTION="$ACTION"
+export INSTANCE="$INSTANCE"
 exec /sbin/hotplug-call openvpn "$@"
git clone https://git.99rst.org/PROJECT