Last active
August 20, 2024 03:56
-
-
Save chris-gillatt/591cae2402ef7033c3184b30905af3fa to your computer and use it in GitHub Desktop.
Mount disks from NAS to Macbook automatically
This file contains hidden or 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 | |
| # Script to mount volumes to Macbook from NAS | |
| # Get Network SSID | |
| NETWORK_SSID=$(networksetup -getairportnetwork en0 | awk -F ': ' '{print $2}') && echo "NETWORK: $NETWORK_SSID" | |
| USER=<user> | |
| HOST=<hostname> | |
| # Function to mount volumes on NAS and use Mac Keychain for credentials | |
| # Note - Hostnames are configured via DHCP on DNS host (usually a router) | |
| mount_volumes () { | |
| osascript <<EOF | |
| mount volume "smb://$USER@$HOST/volume1" | |
| mount volume "smb://$USER@$HOST/volume2" | |
| EOF | |
| } > /dev/null 2>&1 | |
| MOUNT_STATUS=$(mount | grep -c "$HOST") | |
| # If expected network SSID, mount volumes | |
| if [[ "$NETWORK_SSID" =~ "<network name>" ]] && \ | |
| [[ "$MOUNT_STATUS" -lt 2 ]]; then | |
| mount_volumes | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment