Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OSX mount user smb or nfs mountpoint when wifi present, avoid OSX Catalina automount repeated mountpoints issues
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Enabled</key>
<true/>
<key>Label</key>
<string>com.userdomain.mountpoint</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/Users/username/bin/mount_wifi_smb_example.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>300</integer>
</dict>
</plist>
#!/bin/bash
if [ -f '/Volumes/mountpoint/.mounted' ]; then
#echo Nothing to do, share is mounted
exit
else
if [ -z `/Users/username/bin/airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'` ]; then
#echo SSID is Null, we're not connected with the Airport to any Network.
umount -f /Volumes/mountpoint
rmdir /Volumes/mountpoint
exit
else
if [ ! -d '/Volumes/mountpoint' ]; then
mkdir '/Volumes/mountpoint'
fi
if [ `/Users/username/bin/airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'` == "wifiname" ]; then
#echo SSID is wifiname!
/sbin/mount -o rw,locallocks,noowners,nolockd,resvport,rsize=65536,wsize=65536,intr,hard,tcp,rdirplus,readahead=128,nfc -t nfs '//machine/mnt/mountpoint' '/Volumes/mountpoint'
touch /Volumes/mountpoint/.mounted
elif [ `/Users/username/bin/airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'` == "wifiname2" ]; then
#echo SSID is wifiname2!
/sbin/mount -o rw,locallocks,noowners,nolockd,resvport,rsize=65536,wsize=65536,intr,hard,tcp,rdirplus,readahead=128,nfc -t nfs '//machine/mnt/mountpoint' '/Volumes/mountpoint'
touch /Volumes/mountpoint/.mounted
fi
fi
fi
#!/bin/bash
if [ -f '/Volumes/mountpoint/.mounted' ]; then
#echo Nothing to do, share is mounted
exit
else
if [ -z `/Users/username/bin/airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'` ]; then
#echo SSID is Null, we're not connected with the Airport to any Network.
umount -f /Volumes/mountpoint
rmdir /Volumes/mountpoint
exit
else
if [ ! -d '/Volumes/mountpoint' ]; then
mkdir '/Volumes/mountpoint'
fi
if [ `/Users/username/bin/airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'` == "wifiname" ]; then
#echo SSID is wifiname!
/sbin/mount -o nodev,nosuid -t smbfs '//username:smbpasswd@machine/mountpoint' '/Volumes/mountpoint'
touch /Volumes/mountpoint/.mounted
elif [ `/Users/username/bin/airport -I | grep '.* SSID:' | sed 's/^.* SSID: //'` == "wifiname2" ]; then
#echo SSID is wifiname2!
/sbin/mount -o nodev,nosuid -t smbfs '//username:smbpasswd@machine/mountpoint' '/Volumes/mountpoint'
touch /Volumes/mountpoint/.mounted
fi
fi
fi
@lordmorgul

This comment has been minimized.

Copy link
Owner Author

@lordmorgul lordmorgul commented Dec 7, 2019

This assumes you have the 'airport' binary utility present in your home directory. I copied it there a long time ago, but here is at least one reference to how the user getting access to it easily.

http://osxdaily.com/2007/01/18/airport-the-little-known-command-line-wireless-utility/

@lordmorgul

This comment has been minimized.

Copy link
Owner Author

@lordmorgul lordmorgul commented Dec 16, 2019

Correct if statement for testing existence of the .mounted file is to use '-f' instead of '-d' which was for directory previously checking that instead of contained .mounted file. The file prevents detecting the same path exists but is a local directory instead of the mountpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment