#!/bin/sh # ------------------------------------------------------------------- # Filename: auto.smb # Version: 1.0 # Author: Dieter Demerre # CopyRight: GPL # Disclaimer: No guarantee to function, Use at Own Risk. # History: 2001-09-28 # v1.0 dd First functioning implementation # ------------------------------------------------------------------- # An executable that should be able to detect what shares are # accessable for a certain machine (passed as argument), # and thus output its mount-scheme. # ------------------------------------------------------------------- # Framework based upon the /etc/auto.net file delivered with SuSE 7.1 # ------------------------------------------------------------------- # Look at what a host is sharing to determine what we can mount. # This is very simple, but it appears to work surprisingly well # To enable a small executional trace, set debug=Y all else gives # no debug # debug=Y # Group ID for the mounted file system GID=disk # Mask for directories on the mounted filesystem # permissions related with permissions granted by Samba DMASK=0775 # Mask for files on the mounted filesystem # permissions related with permissions granted by Samba FMASK=0774 defUSR=Guest defPWD=Guest if test -z "$1" ; then host=localhost else host="$1" fi { case "$host" in localhost) SMBN=Guest SMBP=Guest SMBID="guest" ;; t642_5|pc_dd|pc_sdg|anthony|baby|nmbs) if test ! -z "$debug" -a "$debug" = "Y" ; then echo "checking $1" ; fi SMBN=$defUSR SMBP=$defPWD SMBID="username=$SMBN,password=$SMBP" ;; *) if test ! -z "$debug" -a "$debug" = "Y" ; then echo "checking $1" ; fi SMBN=Guest SMBP=Guest SMBID="guest" ;; esac } opts="-fstype=smbfs,gid=$GID,dmask=$DMASK,fmask=$FMASK,$SMBID" SMBCLIENT="/usr/bin/smbclient -L $host -U $SMBN%$SMBP 2>/dev/null" if test ! -z "$debug" -a "$debug" = "Y" ; then echo "checking $SMBN,$SMBP,$host" echo "command $SMBCLIENT" fi $SMBCLIENT | /usr/bin/grep '[^ ]*[^$ ] *Disk[$ ]*[^/]' | sort +0 | \ awk -v key="$host" -v opts="$opts" -- ' BEGIN { ORS=""; first=1 } { if (first) { print opts; first=0 }; print " \\\n\t/" $1, "//" key "/" $1 } END { if (!first) print "\n"; else exit 1 } '