Estas instrucciones asumen que estás usando un archivo sparsebundle en 10.9 porque usas una unidad encriptada. Si no es así, modifícalas en consecuencia.
En primer lugar, siga las instrucciones del siguiente enlace para saber cómo utilizar security find-generic-password
para obtener la contraseña de tu unidad cifrada de tu Llavero mediante programación.
http://blog.joshdick.net/2012/10/14/programmatically_mounting_encrypted_disk_images_in_os_x.html
A continuación, cree un archivo llamado mounter
en su directorio bin local ~/bin
que contiene el siguiente código (sustituya todas las rutas por las suyas, y en el campo security find-generic-password
utilice el nombre de la clave en Llavero):
#!/usr/bin/env bash -e
PHYSICAL_DRIVE_PATH="/Volumes/Backup/"
SPARSEBUNDLE_PATH="/Volumes/Backup/TimeMachine.sparsebundle"
SPARSEBUNDLE_MOUNT_PATH="/Volumes/Time Machine/"
# Check existing states
if [ -e "$SPARSEBUNDLE_MOUNT_PATH" ]; then
echo "Already mounted."
exit 0
fi
if [ ! -e "$PHYSICAL_DRIVE_PATH" ]; then
echo "Physical drive not attached"
exit 0
fi
if [ ! -e "$SPARSEBUNDLE_PATH" ]; then
echo "Virtual drive not found on physical drive"
exit 1
fi
# The mount command uses security find-generic-password
# to get the password from the keychain store
MOUNT_PASSWORD=$(security find-generic-password -w -D "disk image password" -l TimeMachine.sparsebundle)
printf $MOUNT_PASSWORD | hdiutil attach -stdinpass -mountpoint "$SPARSEBUNDLE_MOUNT_PATH" "$SPARSEBUNDLE_PATH"
Esto es un poco verboso, pero significa no almacenar contraseñas en ningún sitio excepto en el llavero. En cualquier caso, ahora tenemos que hacer que se ejecute. Crea un archivo en ~/Library/LaunchAgents/
como ~/Library/LaunchAgents/com.martorana.dave.mounter.plist
y pon el siguiente código en él, sustituyendo, por supuesto, las rutas por tus propias rutas:
<?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>Label</key>
<string>com.martoranas.dave.mounter</string>
<key>Program</key>
<string>/Users/dave/bin/mounter</string>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
<key>StandardOutPath</key>
<string>/Users/dave/bin/ldout.log</string>
<key>StandardErrorPath</key>
<string>/Users/dave/bin/lderr.log</string>
</dict>
</plist>
Estamos utilizando launchd
en lugar de cron
por muchas razones, la más importante es el acceso a su llavero.
Ahora carga tu demonio de lanzamiento:
launchctl load -w ~/Library/LaunchAgents/com.martoranas.dave.mounter.plist
Y con eso debería bastar. Ahora launchd
ejecutará su script de shell cada 60 segundos, y si no está montado y disponible, montará su sparsebundle
imagen de disco.
Salud,
Dave