Я регулярно использую сетевые папки общего доступа samba в корпоративной сети с моего Mac под управлением Leopard. Как я могу автоматически смонтировать эти акции по требованию, когда я получаю доступ к репрезентативному пути через оболочку или Finder?
В идеале я хочу, чтобы это было так же просто, как доступ к сетевым ресурсам из Windows по UNC-путям (aka. \\[host] [share]) по пути, например /Volumes /smb /[host] /[share].
Я попытался использовать поддержку «исполняемой карты» autofs, как написано по следующим ссылкам:
- http://images.apple.com/business/docs/Autofs.pdf
- http://lowendmac.com/ed/winston/09kw/intro-to-autofs.html
- http://ubuntuforums.org/showthread.php?t=885713
Вот скрипт auto.smb, который я немного подправил, но он не сработал, и я в тупике:
#!/bin/bash
# $Id: auto.smb,v 1.3 2005/04/05 13:02:09 raven Exp $
# This file must be executable to work! chmod 755!
# IC patch
# The problem with the original file was that it was executing smbclient -gL $key
# But $key contains the full path e.g.: server/share/subdir
# This was causing auto.smb to go to an endless loop
# This modified file corrects this problem by passing just the host to smbclient
# and in addition it provides a simple method to locate the credentials file
# The changed parts are marked as "IC patch"
# Please read the creddir variable description to see how to provide credentials files
# Note: When you search for an inexistent share, or you authentication fails the script behaves the wrong way
# This is because smbclient does protest, it just falls back like calling it
# as smbclient -gL host
# A check at the smbclient output should be done to avoid this, but I haven't figured it out yet
# Ioannis Chronakis <i.chronakis at gmail dot com>
key="$1"
mountopts="-fstype=smbfs"
smbopts=""
# IC patch
# Look for credentials files under the creddir
# If $key is just the host name, then $credfile=$creddir/$host
# If $key is in the form of host/share,
# first look for a file $creddir/$host.$share
# and it does not exist, look for $creddir/$host
creddir="/etc/auto.smb.credentials"
# IC patch
# Providing a common credfile for everything, will override the above lookup method
credfile=
if [ -z "$key" ]; then
echo host1.example.com
echo host2.example.com
echo host3.example.com
echo host4.example.com
exit
fi
# IC patch
# The problem is that the key ($1) is the full path with the host
# So there should be one key for each directory
# To solve the problem:
# Easy: Get the first part of the $1 (/host/share/...)
# Comprehensive: Look the first two (host and share)
# If key does not exist, look just for the host
host=${key%%/*}
if [[ "$key" =~ '/' ]]; then
path=${key#*/}
fi
if [ -n "$path" ]; then
if [[ "$path" =~ '/' ]]; then
share=${path%%/*}
else
share=$path
fi
fi
if [ -z "$credfile" ]; then
# Search for credentials file
# First look for $creddir/$host.$share then for $creddir/$host
if [ -n "$share" ]; then
credfile="$creddir/$host.$share"
if [ ! -e $credfile ]; then
credfile="$creddir/$host"
fi
else
credfile="$creddir/$host"
if [ ! -e $credfile ]; then
credfile="$creddir/global"
fi
fi
fi
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
mountopts="$mountopts,credentials=$credfile"
smbopts="-A $credfile"
else
smbopts="-N"
fi
if [ -z "$share" ]; then
echo $mountopts $host:/$share
exit
fi
# IC patch
# Do not browse for $key, just the host part
$SMBCLIENT $smbopts -gL $host 2>/dev/null| awk -v key="$host" -v opts="$mountopts" -F'|' -- '
BEGIN { ORS=""; first=1 }
/Disk/ { if (first) { print opts; first=0 }; sub(/ /, "\\ ", $2); sub(/\$/, "\\$", $2); print " \\\n\t " key ":/" $2 }
END { if (!first) print "\n"; else exit 1 }
'