Fix missing zfs shares in samba config

This commit is contained in:
kneutron 2023-11-04 14:40:58 -06:00 committed by GitHub
parent 42b2e79fd3
commit 51c2c879cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

58
ZFS/zfs-fix-smb-conf.sh Normal file
View File

@ -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