Created
October 26, 2014 15:43
-
-
Save gpolitis/4e86f62d0b1372b38fd1 to your computer and use it in GitHub Desktop.
auto.smb file from the autofs5 debian package patched with WOL (wake-on-lan) functionality and guest or authed login
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 | |
# This file must be executable to work! chmod 755! | |
key="$1" | |
opts="-fstype=cifs,file_mode=0640,dir_mode=0750" | |
macaddr=`grep $key /etc/ethers | egrep -v '^#' | cut -d' ' -f1` | |
max_retries=60 | |
ping_deadline=1 | |
# Detect credentials. | |
credentials="/etc/auto.master.d/auth.$key" | |
if [ -f $credentials ]; then | |
opts="$opts,credentials=$credentials" | |
else | |
opts="$opts,sec=none" | |
fi | |
# TODO find and use whatever is installed, wakeonlan or etherwake. | |
# If we have a mac address for the host, wake it up, if necessary. | |
if [ -n "$macaddr" ]; then | |
ping -c 1 -w $ping_deadline -q $key > /dev/null | |
status=$? | |
if [ $status -ne 0 ]; then | |
/usr/bin/wakeonlan $macaddr > /dev/null | |
for i in `seq 1 $max_retries` | |
do | |
ping -c 1 -w $ping_deadline -q $key > /dev/null | |
status=$? | |
if [ $status -ne 0 ]; then | |
if [ $i -eq $max_retries ]; then | |
exit 1 | |
fi | |
# no need to sleep as the ping has a timeout anyway | |
# sleep 1 | |
else | |
break | |
fi | |
done | |
fi | |
fi | |
# Find locations. | |
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 | |
$SMBCLIENT -gNL $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