Here’s how I do it on my MacBook Pro (thanks smanek from this hint):
- Install sleepwatcher and install it so that it runs during bootup
- Create .wakeup file in home directory. Sleepwatcher’s /etc/rc.sleep and /etc/rc.wakeup will execute whatever is in the user’s /home/.wakeup or /home/.sleep files whenever the Mac goes to sleep or wakes up. Here’s what I have in my .wakeup file which will mount my home network shares ONLY if I am at home:
$ cat .wakeup
#!/bin/sh
# Wait for network
/bin/sleep 10
status_wifi=$(/sbin/ifconfig en1 | /usr/bin/grep status | /usr/bin/awk ‘{print $6}’)
status_ethernet=$(/sbin/ifconfig en0 |/usr/bin/grep status| /usr/bin/awk ‘{print $6}’)
#Check if wifi is up
if [ "$status_wifi" == "inactive" ]; then
echo “No Wifi”
else
echo “Got Wifi”
broadcastnet_wifi=$(/sbin/ifconfig en1 | /usr/bin/grep inet |/usr/bin/grep broadcast | /usr/bin/awk ‘{print $6}’| tr “.” ” “)
oct1_wifi=$(echo $broadcastnet_wifi | /usr/bin/awk ‘{print $1}’ )
oct2_wifi=$(echo $broadcastnet_wifi | /usr/bin/awk ‘{print $2}’)
#Check if Wifi is on home network
if [ "$oct1_wifi" -eq "192" ] && [ "$oct2_wifi" -eq "168" ]; then
echo “Wifi is on home network”
echo “Mounting SMB Shares”
/sbin/mount_smbfs //(username):(password)@(server)/(share) /Users/echua/media
/sbin/mount_smbfs //(username):(password)@(server)/(share) /Users/echua/download
echo “Mounting NFS Shares”
/sbin/mount (server):(path-to-share) /Users/echua/pics
exit
else
echo “Wifi isn’t on home network”
fi
fi
#check if ethernet is up
if [ "$status_ethernet" == "inactive" ]; then
echo “No Ethernet”
unset status_ethernet
else
echo “Got Ethernet”
broadcastnet_ethernet=$(/sbin/ifconfig en0 | /usr/bin/grep inet|/usr/bin/grep broadcast | /usr/bin/awk ‘{print $6}’| tr “.” ” “)
oct1_ethernet=$(echo $broadcastnet_ethernet | /usr/bin/awk ‘{print $1}’ )
oct2_ethernet=$(echo $broadcastnet_ethernet | /usr/bin/awk ‘{print $2}’)
if [ "$oct1_ethernet" -eq "192" ] && [ "$oct2_ethernet" -eq "168" ]; then
echo “Ethernet is on home network”
echo “Mounting SMB Shares”
/sbin/mount_smbfs //(username):(password)@(server)/(share) /Users/echua/media
/sbin/mount_smbfs //(username):(password)@(server)/(share) /Users/echua/download
echo “Mounting NFS Shares”
/sbin/mount (server):(path-to-share) /Users/echua/pics
exit
else
echo “Ethernet isn’t on home network”
exit
fi
fi