From 51c2c879cdf312071b2aa41769ef37203819ceff Mon Sep 17 00:00:00 2001 From: kneutron <50146127+kneutron@users.noreply.github.com> Date: Sat, 4 Nov 2023 14:40:58 -0600 Subject: [PATCH] Fix missing zfs shares in samba config --- ZFS/zfs-fix-smb-conf.sh | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ZFS/zfs-fix-smb-conf.sh diff --git a/ZFS/zfs-fix-smb-conf.sh b/ZFS/zfs-fix-smb-conf.sh new file mode 100644 index 0000000..779ce9f --- /dev/null +++ b/ZFS/zfs-fix-smb-conf.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# for suse, may also work on rhel-derived +# Fix missing zfs shares in samba config +# 2023.Nov kneutron + +conf=/etc/samba/smb.conf +cp -v $conf /etc/samba/smb.conf.bak-$(date +%Y%m%d)'@'$(date +%H%M) + +template=" +# boojumfix +[SHARENAME] + path = REPLACEME + writable = yes + guest ok = yes + guest only = no + create mode = 0777 + directory mode = 0777 + +" + +tmpfile=/tmp/fixsmb.tmp.txt +>$tmpfile + +mods=0 +for zd in $(zfs get sharesmb |awk '$3=="on" {print $1}'); do + [ "$zd" = "" ] && break; + + mtpt=$(df |grep "$zd" |awk '{print $6}') + echo "$zd = $mtpt" + +#set -x +# only if not already in smb.conf + if [ $(grep -c $mtpt $conf) -lt 1 ]; then + echo "$template" >$tmpfile + + dasher=$(echo $zd |tr '/' '-') + + sed -i 's|SHARENAME|'$dasher'|g' $tmpfile + sed -i 's|REPLACEME|'$mtpt'|' $tmpfile + cat $tmpfile >> $conf + + let mods=$mods+1 + fi +done + +cat $conf +ls -l $conf +echo "Modified $mods shares" + +if [ $mods -gt 0 ]; then + msg="$(date) - $0 - Restarting samba service" + logger $msg + echo "$msg" + systemctl restart smb +fi + +zfs-show-my-shares.sh