Rewrite of SMB mounter that does NMB lookups now
#!/bin/bash
BASEDIR=/data/library/music
for m in `cat /etc/smbmounts.conf | grep -v ^#`; do
- dir=`echo $m | awk -F\; '{print $1}'`
- if [ ! -d $BASEDIR/$dir ]; then
- mkdir -p $BASEDIR/$dir
+
+ # Split the line first
+ readarray -d \; -t parts <<< "$m"
+ echo "There are ${#parts[*]} words in the text."
+ MOUNTID=${parts[0]}
+ SHARE=${parts[1]}
+ USER=${parts[2]}
+ PASSWORD=${parts[3]}
+ MOUNTOPTS=${parts[4]}
+
+ # Remove newline from last parameter
+ PASSWORD=$(echo $PASSWORD|tr -d '\n')
+ MOUNTOPTS=$(echo $MOUNTOPTS|tr -d '\n')
+
+ if [ "$MOUNTOPTS" == "" ]; then
+ MOUNTOPTS="rw"
+ fi
+
+ if [ ! -d $BASEDIR/$MOUNTID ]; then
+ mkdir -p $BASEDIR/$MOUNTID
fi
# Check if share is on a .local host, resolve this first
HOST=`echo $m | awk -F\; '{print $2}' | awk -F\/ '{print $3}'`
if [[ $HOST == *.local ]]; then
IP=`avahi-resolve-host-name -4 $HOST | awk '{print $2}'`
- if [ "$IP" != "" ]; then
- m=`echo $m | sed s/$HOST/$IP/`
fi
+
+ # The try to resolve using nmblookup
+ if [ "$IP" == "" ]; then
+ IP=`nmblookup $HOST|awk 'END{print $1}'`
+ fi
+
+ if [ "$IP" != "" ]; then
+ SHARE=`echo $SHARE | sed s/$HOST/$IP/`
fi
- mountcmd=`echo $m | awk -F\; '$5=="" { $5="rw" } {print "mount -t cifs -o user=" $3 ",password=" $4 "," $5 " " $2 " /data/library/music/" $1}'`
- echo $mountcmd
+ mountcmd="mount -t cifs -o user=\"$USER\",password=\"$PASSWORD\",$MOUNTOPTS $SHARE /data/library/music/$MOUNTID"
${mountcmd}
if [ -x /opt/hifiberry/bin/report-activation ]; then
