Last active
November 19, 2020 04:38
-
-
Save lordmorgul/50f20697cf2390e343a17e59b9457764 to your computer and use it in GitHub Desktop.
OSX mount user smb or nfs mountpoint when wifi present, avoid OSX Catalina automount repeated mountpoints issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
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/