Created
December 1, 2011 13:28
-
-
Save anonymous/1416730 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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