Skip to content

Instantly share code, notes, and snippets.

@CameronNemo
Forked from gboudreau/mount_shares_locally
Last active August 29, 2015 14:02
Show Gist options
  • Save CameronNemo/893d48f6530a0fde8cee to your computer and use it in GitHub Desktop.
Save CameronNemo/893d48f6530a0fde8cee to your computer and use it in GitHub Desktop.
Upstart script to mount Samba shares locally
description "mount Samba shares locally"
author "Cameron Norman <camerontnorman@gmail.com>"
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