samba4: Run init script through shellcheck 9590/head
authorRosen Penev <rosenp@gmail.com>
Mon, 29 Jul 2019 00:51:00 +0000 (17:51 -0700)
committerRosen Penev <rosenp@gmail.com>
Mon, 29 Jul 2019 00:51:00 +0000 (17:51 -0700)
Some performance improvements by batching file writes.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
net/samba4/Makefile
net/samba4/files/samba.init

index 3fb6c29ca545f85ebe776e7e631a0d3ac821bc5c..3137fa055b17ccb9302238183d7c0acaebe11001 100644 (file)
@@ -3,21 +3,21 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=samba
 PKG_VERSION:=4.9.11
-PKG_RELEASE:=1
-
-PKG_MAINTAINER:=Andy Walsh <andy.walsh44+github@gmail.com>
-PKG_LICENSE:=GPL-3.0-only
-PKG_LICENSE_FILES:=COPYING
+PKG_RELEASE:=2
 
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://ftp.heanet.ie/mirrors/ftp.samba.org/stable/ \
                https://ftp.gwdg.de/pub/samba/stable/ \
                https://ftp.riken.jp/net/samba/samba/stable/ \
                http://www.nic.funet.fi/index/samba/pub/samba/stable/ \
                http://samba.mirror.bit.nl/samba/ftp/stable/ \
                https://download.samba.org/pub/samba/stable/
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_HASH:=bb736624d16f7369e395de2f15fec153b554f76f95864015b4ce1f2ae53e817b
 
+PKG_MAINTAINER:=Andy Walsh <andy.walsh44+github@gmail.com>
+PKG_LICENSE:=GPL-3.0-only
+PKG_LICENSE_FILES:=COPYING
+
 # samba4=(asn1_compile) e2fsprogs=(compile_et) nfs-kernel-server=(rpcgen)
 HOST_BUILD_DEPENDS:=nfs-kernel-server/host e2fsprogs/host
 PKG_BUILD_DEPENDS:=samba4/host
@@ -43,7 +43,7 @@ define Package/samba4/Default
   SECTION:=net
   CATEGORY:=Network
   TITLE:=Samba $(PKG_VERSION)
-  URL:=http://www.samba.org/
+  URL:=https://www.samba.org/
 endef
 
 define Package/samba4/Default/description
index 48a2d0dcaf60fdeb19ffe07a86e55a9809697fd0..d7eed562aaa3f78e5b83262aa2e066169efce85f 100644 (file)
@@ -7,7 +7,8 @@ smb_header() {
        config_get samba_iface $1 interface "loopback lan"
 
        # resolve interfaces
-       local interfaces=$(
+       local interfaces
+       interfaces=$(
                . /lib/functions/network.sh
 
                local net
@@ -15,19 +16,20 @@ smb_header() {
                        local device
                        network_is_up $net || continue
                        network_get_device device "$net"
-                       echo -n "${device:-$net} "
+                       printf "%s " "${device:-$net}"
                done
        )
 
        local workgroup description charset
        # we dont use netbios anymore as default and wsd/avahi is dns based
-       local hostname="$(cat /proc/sys/kernel/hostname)"
+       local hostname
+       hostname="$(cat /proc/sys/kernel/hostname)"
 
        config_get workgroup            $1 workgroup    "WORKGROUP"
        config_get description          $1 description  "Samba on OpenWrt"
-       config_get charset                      $1 charset              "UTF-8"
-       
-       config_get_bool MACOS                   $1 macos                        0
+       config_get charset              $1 charset      "UTF-8"
+
+       config_get_bool MACOS           $1 macos                0
        config_get_bool DISABLE_NETBIOS $1 disable_netbios      0
        config_get_bool DISABLE_AD_DC   $1 disable_ad_dc        0
        config_get_bool DISABLE_WINBIND $1 disable_winbind      0
@@ -40,15 +42,16 @@ smb_header() {
            -e "s#|CHARSET|#$charset#g" \
            /etc/samba/smb.conf.template > /var/etc/smb.conf
 
-       echo -e "\n######### Dynamic written config options #########\n" >> /var/etc/smb.conf
-       if [ "$DISABLE_NETBIOS" -eq 1 ] || [ ! -x /usr/sbin/nmbd ]; then
-               echo -e "\tdisable netbios = yes" >> /var/etc/smb.conf
-       fi
+       {
+               printf "\n######### Dynamic written config options #########\n"
+               if [ "$DISABLE_NETBIOS" -eq 1 ] || [ ! -x /usr/sbin/nmbd ]; then
+                       printf "\tdisable netbios = yes\n"
+               fi
 
-       local homes
-       config_get_bool homes $1 homes 0
-       [ $homes -gt 0 ] && {
-               cat <<EOT >> /var/etc/smb.conf
+               local homes
+               config_get_bool homes $1 homes 0
+               [ $homes -gt 0 ] && {
+                       cat <<EOT
 
 [homes]
        comment     = Home Directories
@@ -57,14 +60,15 @@ smb_header() {
        read only   = no
        create mask = 0750
 EOT
-       }
+               }
+       } >> /var/etc/smb.conf
 
        [ -e /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
-       
+
        if ! [ -L /etc/samba/smb.conf ]; then
                logger -t 'samba4-server' "Local custom /etc/samba/smb.conf file detected, all luci/config settings are ignored!"
        fi
-       
+
 }
 
 smb_add_share() {
@@ -104,43 +108,45 @@ smb_add_share() {
        config_get write_list $1 write_list
        config_get read_list $1 read_list
 
-       [ -z "$name" -o -z "$path" ] && return
+       [ -z "$name" ] || [ -z "$path" ] && return
 
-       echo -e "\n[$name]\n\tpath = $path" >> /var/etc/smb.conf
-       
-       if [ "$force_root" -eq 1 ]; then
-               echo -e "\tforce user = root" >> /var/etc/smb.conf
-               echo -e "\tforce group = root" >> /var/etc/smb.conf
-       else
-               [ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/smb.conf
-       fi
+       {
+               printf "\n[$name]\n\tpath = %s\n" "$path"
 
-       [ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/smb.conf
-       [ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/smb.conf
-
-       [ -n "$browseable" ] && echo -e "\tbrowseable = $browseable" >> /var/etc/smb.conf
-       [ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var/etc/smb.conf
-       [ -n "$writeable" ] && echo -e "\twriteable = $writeable" >> /var/etc/smb.conf
-       [ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/smb.conf
-       [ -n "$guest_only" ] && echo -e "\tguest only = $guest_only" >> /var/etc/smb.conf
-       [ -n "$inherit_owner" ] && echo -e "\tinherit owner = $inherit_owner" >> /var/etc/smb.conf
-
-       [ -n "$write_list" ] && echo -e "\twrite list = $write_list" >> /var/etc/smb.conf
-       [ -n "$read_list" ] && echo -e "\tread list = $read_list" >> /var/etc/smb.conf
-
-       if [ "$MACOS" -eq 1 ]; then
-               vfs_objects="catia fruit streams_xattr $vfs_objects"
-               echo -e "\tfruit:encoding = native" >> /var/etc/smb.conf
-               echo -e "\tfruit:metadata = stream" >> /var/etc/smb.conf
-               echo -e "\tfruit:veto_appledouble = no" >> /var/etc/smb.conf
-               # avoid mixed shares order for aapl
-               if [ "$timemachine" -eq 1 ]; then
-                       echo -e "\tfruit:time machine = yes" >> /var/etc/smb.conf
-                       [ -n "$timemachine_maxsize" ] && echo -e "\tfruit:time machine max size = ${timemachine_maxsize}G" >> /var/etc/smb.conf
+               if [ "$force_root" -eq 1 ]; then
+                       printf "\tforce user = root\n"
+                       printf "\tforce group = root\n"
+               else
+                       [ -n "$users" ] && printf "\tvalid users = %s\n" "$users"
                fi
-       fi
-       
-       [ -n "$vfs_objects" ] && echo -e "\tvfs objects = $vfs_objects" >> /var/etc/smb.conf
+
+               [ -n "$create_mask" ] && printf "\tcreate mask = %s\n" "$create_mask"
+               [ -n "$dir_mask" ] && printf "\tdirectory mask = %s\n" "$dir_mask"
+
+               [ -n "$browseable" ] && printf "\tbrowseable = %s\n" "$browseable"
+               [ -n "$read_only" ] && printf "\tread only = %s\n" "$read_only"
+               [ -n "$writeable" ] && printf "\twriteable = %s\n" "$writeable"
+               [ -n "$guest_ok" ] && printf "\tguest ok = %s\n" "$guest_ok"
+               [ -n "$guest_only" ] && printf "\tguest only = %s\n" "$guest_only"
+               [ -n "$inherit_owner" ] && printf "\tinherit owner = %s\n" "$inherit_owner"
+
+               [ -n "$write_list" ] && printf "\twrite list = %s\n" "$write_list"
+               [ -n "$read_list" ] && printf "\tread list = %s\n" "$read_list"
+
+               if [ "$MACOS" -eq 1 ]; then
+                       vfs_objects="catia fruit streams_xattr $vfs_objects"
+                       printf "\tfruit:encoding = native\n"
+                       printf "\tfruit:metadata = stream\n"
+                       printf "\tfruit:veto_appledouble = no\n"
+                       # avoid mixed shares order for aapl
+                       if [ "$timemachine" -eq 1 ]; then
+                               printf "\tfruit:time machine = yes\n"
+                               [ -n "$timemachine_maxsize" ] && printf "\tfruit:time machine max size = %sG\n" "${timemachine_maxsize}"
+                       fi
+               fi
+
+               [ -n "$vfs_objects" ] && printf "\tvfs objects = %s\n" "$vfs_objects"
+       } >> /var/etc/smb.conf
 }
 
 init_config() {
@@ -149,10 +155,8 @@ init_config() {
        [ -d /var/cache/samba ] || mkdir -p /var/cache/samba
        [ -d /var/run/samba ] || mkdir -p /var/run/samba
        [ -d /var/log/samba ] || mkdir -p /var/log/samba
-       [ -d /var/lock ] && chmod 0755 /var/lock || {
-               mkdir -p /var/lock
-               chmod 0755 /var/lock
-       }
+       [ -d /var/lock ] || mkdir -p /var/lock
+       chmod 0755 /var/lock
 
        config_load samba4
        config_foreach smb_header samba
@@ -161,9 +165,9 @@ init_config() {
 
 service_triggers() {
        PROCD_RELOAD_DELAY=2000
-       
+
        procd_add_reload_trigger "dhcp" "system" "samba4"
-       
+
        local i
        for i in $samba_iface; do
                procd_add_reload_interface_trigger $i
@@ -207,9 +211,9 @@ start_service() {
        fi
        # lower priority using renice (if found)
        if [ -x /usr/bin/renice ]; then
-               [ -x /usr/sbin/samba ] && renice -n 2 $(pidof samba)
-               [ -x /usr/sbin/smbd ] && renice -n 2 $(pidof smbd)
-               [ -x /usr/sbin/nmbd ] && renice -n 2 $(pidof nmbd)
-               [ -x /usr/sbin/winbindd ] && renice -n 2 $(pidof winbindd)
+               [ -x /usr/sbin/samba ] && renice -n 2 "$(pidof samba)"
+               [ -x /usr/sbin/smbd ] && renice -n 2 "$(pidof smbd)"
+               [ -x /usr/sbin/nmbd ] && renice -n 2 "$(pidof nmbd)"
+               [ -x /usr/sbin/winbindd ] && renice -n 2 "$(pidof winbindd)"
        fi
 }