All pastes #1093878 Raw Edit

wifimount

public text v1 · immutable
#1093878 ·published 2008-08-06 15:31 UTC
rendered paste body
#!/bin/bash
while true; do

####### USER SETTINGS #######
HOME_NW="WISHIE"
SERVER_IP=192.168.0.1
SHARES="Applications Music Video Stuff DVDImages"
LOCKDIR=/tmp/netcheck.lock
MIN_SIGNAL_QUALITY="40"
INTERVAL=30

####### DO NOT EDIT BELOW THIS LINE #######

SIGNAL=`iwconfig 2>/dev/null |grep Link |awk {'print $2'}`
QUAL=${SIGNAL#*=} QUALITY=${QUAL%/*}
NETWORK=`iwgetid |awk {'print $2'} |sed -ne 's/.*\"\(.*\)\".*/\1/p'`

if [[ $1 = "network" ]];then NETWORK=""; fi
if [[ $1 = "signal" ]];then QUALITY="10"; fi


if [[ "$NETWORK" = "$HOME_NW" ]]; then
	echo "Connected to $NETWORK network with $QUALITY% signal"
		if [[ $QUALITY -gt $MIN_SIGNAL_QUALITY ]]; then
			if mkdir "$LOCKDIR" 2>/dev/null; then
				echo -n "Mounting shares: "
					for i in $SHARES; do
						mount -t nfs $SERVER_IP:/mnt/$i/ /mnt/$i
						echo -n "$i, "
					done
				echo ""
				echo "Done."
			fi	
		else
			if [[ -d $LOCKDIR ]]; then
				echo "Signal quality below $MIN_SIGNAL_QUALITY%! Unmounting drives..."
					for i in $SHARES; do
						umount $SERVER_IP:/mnt/$i/
					done	
				rm -r $LOCKDIR
			fi
		fi
else
	echo "We are not on the $HOME_NW network."	
		if [[ -d $LOCKDIR ]]; then
			echo "Drives are mounted. Unmount them!"
				for i in $SHARES; do
					umount $SERVER_IP:/mnt/$i/
				done
			rm -r $LOCKDIR
		fi
fi
sleep $INTERVAL;
done