-
-
Save CameronNemo/893d48f6530a0fde8cee to your computer and use it in GitHub Desktop.
Upstart script to mount Samba shares locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description "mount Samba shares locally" | |
author "Cameron Norman <[email protected]>" | |
start on started smbd | |
stop on stopping smbd | |
env username="your username" | |
pre-start script | |
uid=$(id -u $username) | |
gid=$(id -g $username) | |
mkdir -p /mnt/samba/ | |
cd /mnt/samba | |
testparm -s /etc/samba/smb.conf 2>/dev/null | grep "^\[" | grep -v "\[global\]" | grep -v "\[homes\]" | awk -F'[' '{print $2}' | awk -F']' '{print $1}' | xargs -d "\n" mkdir -p | |
for d in *; do | |
test "$(mount | grep "//127.0.0.1/$d/* on " | wc -l)" = "0" || { echo "Share $d already mounted."; continue } | |
/sbin/mount.cifs "//127.0.0.1/$d" "$d" -o credentials=/home/${username}/.smb_credentials,uid=${uid},gid=${gid},file_mode=0660,dir_mode=0770,nobrl,hard,_netdev,iocharset=utf8,noserverino,mfsymlinks | |
done | |
end script | |
post-stop exec /bin/umount -l /mnt/samba/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment