Skip to content

Instantly share code, notes, and snippets.

@hall757
Created February 28, 2024 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hall757/d8eaf3101993a37702ea47edaabe09c0 to your computer and use it in GitHub Desktop.
Save hall757/d8eaf3101993a37702ea47edaabe09c0 to your computer and use it in GitHub Desktop.
Ensures sdcard in macbook used for time capsule backups is always mounted.
#!/bin/bash
#
# Ensures sd card in macbook used for timecapsule backups is always mounted.
# Gets encryption password from keychain.
#
# Put this file in /usr/local/bin/mounter.sh
#
# Edit the volume name and disk id of sd card
#
# Add to crontab by running 'crontab -e' and adding following line
# * * * * * /usr/local/bin/mounter.sh
#
function mount_it {
label="$1"
uuid="$2"
if [ $(df | grep -c "/Volumes/${label}") -eq 0 ]
then
device=$(/usr/bin/sudo /usr/sbin/diskutil list | /usr/bin/grep "APFS Volume ${label}" | /usr/bin/sed -e 's/.*disk/disk/')
/usr/bin/sudo /usr/sbin/diskutil apfs unlockVolume /dev/${device} -passphrase "$(/usr/bin/security find-generic-password -s $uuid -w 2>/dev/null | sed -e 's/00$//' | xxd -r -p )"
/use/bin/sudo /use/sbin/diskutil mount /dev/${device} > /dev/null 2> /dev/null
fi
}
mount_it volume_name volume_id
# example: mount_it microSD 0384F0A9-4089-4793-A943-9AA86A954F13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment