wsdd2: run init script through shellcheck 11712/head
authorRosen Penev <rosenp@gmail.com>
Mon, 30 Mar 2020 01:39:37 +0000 (18:39 -0700)
committerRosen Penev <rosenp@gmail.com>
Mon, 30 Mar 2020 04:35:43 +0000 (21:35 -0700)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
net/wsdd2/Makefile
net/wsdd2/files/wsdd2.init

index 222c792e6e0911ef53c6991f4db6c8c21c0815e1..b0cfe331ea091d75d44f0f80a8c79b983fc3dcf8 100644 (file)
@@ -1,7 +1,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=wsdd2
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL:=https://github.com/Andy2244/wsdd2.git
index 24595e0f361dd633b727c250ba017314e220fd24..ee60eee2d80bd49d26b986ea1ed241fe97ff979e 100644 (file)
@@ -5,8 +5,8 @@ USE_PROCD=1
 
 SMB_CONF=""
 BIND_IF_PARM=""
-NB_PARM=""
-WG_PARM=""
+NB_PARM="$(cat /proc/sys/kernel/hostname)"
+WG_PARM="WORKGROUP"
 BI_PARM=""
 
 start_service() {
@@ -17,67 +17,61 @@ start_service() {
                SMB_CONF="/etc/ksmbd/smb.conf"
        fi
 
-       if [ -e /etc/samba/smb.conf ]; then
+       [ -e /etc/samba/smb.conf ] && {
                if [ -e /etc/init.d/samba4 ] && /etc/init.d/samba4 running; then
                        SMB_CONF="/etc/samba/smb.conf"
                elif [ -e /etc/init.d/samba ] && /etc/init.d/samba running; then
                        SMB_CONF="/etc/samba/smb.conf"
                fi
-       fi
-       
-       if [ -z "$SMB_CONF" ]; then
+       }
+
+       [ -z "$SMB_CONF" ] && {
                logger -p daemon.error -t 'wsdd2' "samba36/4 or ksmbd is not running, can't start wsdd2!"
                exit 1
-       fi
-       
+       }
+
        local nb_name
        nb_name="$(grep -i 'netbios name' $SMB_CONF | awk -F'=' '{print $2}' | tr -d ' \n')"
-       if [ -n "$nb_name" ]; then
-               NB_PARM="-N $nb_name"
-       else
-               local hostname
-               hostname="$(cat /proc/sys/kernel/hostname)"
-               NB_PARM="-N $hostname"
-       fi
+       [ -n "$nb_name" ] && NB_PARM="$nb_name"
 
        local wg_name
        wg_name="$(grep -i 'workgroup' $SMB_CONF | awk -F'=' '{print $2}' | tr -d ' \n')"
-       if [ -n "$wg_name" ]; then
-               WG_PARM="-G $wg_name"
-       else
-               WG_PARM="-G WORKGROUP"
-       fi
+       [ -n "$wg_name" ] && WG_PARM="$wg_name"
 
        # resolve lan interface (BUG: No multi-interface binds atm)
        local ifname
-       if network_get_device ifname lan; then
-               BIND_IF_PARM="-i $ifname"
-       fi
+       network_get_device ifname lan
 
        local board_vendor
        local board_model
        local board_sku
 
-       if [ -e /tmp/sysinfo/board_name ]; then
-               board_vendor="$(cat /tmp/sysinfo/board_name | awk -F',' '{print $1}' | tr ' ' '_' | tr -d ' \n')"
-               board_sku="$(cat /tmp/sysinfo/board_name | awk -F',' '{print $2}' | tr ' ' '_' | tr -d ' \n')"
-       fi
-       if [ -e /tmp/sysinfo/model ]; then
-               board_model="$(cat /tmp/sysinfo/model | tr ' ' '_' | tr -d ' \n')"
-       fi
-       if [ -n "$board_vendor" ] && [ -n "$board_model" ]; then
+       [ -e /tmp/sysinfo/board_name ] && {
+               board_vendor="$(awk -F',' '{print $1}' /tmp/sysinfo/board_name | tr ' ' '_' | tr -d ' \n')"
+               board_sku="$(awk -F',' '{print $2}' /tmp/sysinfo/board_name | tr ' ' '_' | tr -d ' \n')"
+       }
+
+       [ -e /tmp/sysinfo/model ] && {
+               board_model="$(awk -F':' '{print $1}' /tmp/sysinfo/model | tr ' ' '_' | tr -d ' \n')"
+       }
+
+       [ -n "$board_vendor" ] && [ -n "$board_model" ] && {
                if [ -n "$board_sku" ]; then
-                       BI_PARM="-b vendor:$board_vendor,model:$board_model,sku:$board_sku"
+                       BI_PARM="vendor:$board_vendor,model:$board_model,sku:$board_sku"
                else
-                       BI_PARM="-b vendor:$board_vendor,model:$board_model"
+                       BI_PARM="vendor:$board_vendor,model:$board_model"
                fi
-       fi
+       }
 
        procd_open_instance
-    procd_set_param command /usr/bin/wsdd2 -w $BIND_IF_PARM $NB_PARM $WG_PARM $BI_PARM
-    procd_set_param respawn
-    procd_set_param file $SMB_CONF
-    procd_close_instance
+       procd_set_param command /usr/bin/wsdd2
+       [ -n "$ifname" ] && procd_append_param command -i "$ifname"
+       procd_append_param command -N "$NB_PARM"
+       procd_append_param command -G "$WG_PARM"
+       procd_append_param command -b "$BI_PARM"
+       procd_set_param respawn
+       procd_set_param file "$SMB_CONF"
+       procd_close_instance
 }
 
 service_triggers() {