Skip to content

Instantly share code, notes, and snippets.

Created December 1, 2011 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1416730 to your computer and use it in GitHub Desktop.
Save anonymous/1416730 to your computer and use it in GitHub Desktop.
#!/bin/bash
# /etc/auto.smb
# This file must be executable to work! chmod 755!
key="$1"
opts="-fstype=cifs"
credfile="/home/$USER/.smb/$key.cred"
for P in /bin /sbin /usr/bin /usr/sbin
do
if [ -x $P/smbclient ]
then
SMBCLIENT=$P/smbclient
break
fi
done
[ -x $SMBCLIENT ] || exit 1
if [ -e "$credfile" ]
then
opts=$opts",credentials=$credfile"
smbclientopts="-gLA "$credfile
else
smbclientopts="-gLN"
fi
$SMBCLIENT $smbclientopts $key 2>/dev/null| awk -v key="$key" -v opts="$opts" -F'|' -- '
BEGIN { ORS=""; first=1 }
/Disk/ {
if (first)
print opts; first=0
dir = $2
loc = $2
# Enclose mount dir and location in quotes
# Double quote "$" in location as it is special
gsub(/\$$/, "\\$", loc);
gsub(/\&/,"\\\\&",loc)
print " \\\n\t \"/" dir "\"", "\"://" key "/" loc "\""
}
END { if (!first) print "\n"; else exit 1 }
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment