syncPhotos.sh 907 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # Config
  3. TIMEOUT=20
  4. export BASE_LOCAL="/Volumes/iPhoto"
  5. SOURCE_LOCAL="/mnt/media/Pictures/iPhoto.sparsebundle"
  6. TARGET="Shared.photolibrary"
  7. if [ -z "${VIDEO_DIR}" ]; then
  8. VIDEO_DIR="${HOME}/bin/video"
  9. fi
  10. # Ensure the remote drive is available
  11. "${VIDEO_DIR}/backup/checkMount.sh" >/dev/null 2>&1
  12. # Mount the local drive if needed
  13. MOUNTED_LOCAL=0
  14. if [ ! -d "${BASE_LOCAL}" ]; then
  15. MOUNTED_LOCAL=1
  16. hdiutil attach -readonly "${SOURCE_LOCAL}" >/dev/null 2>&1
  17. fi
  18. # Backup if all went well
  19. if [ -d "${BASE_LOCAL}" ]; then
  20. "${VIDEO_DIR}/backup/sync.sh" "${TARGET}" 1000
  21. fi
  22. # Detach the local drive if we mounted it
  23. if [ -d "${BASE_LOCAL}" ] && [ $MOUNTED_LOCAL -gt 0 ]; then
  24. hdiutil detach "${BASE_LOCAL}" >/dev/null 2>&1
  25. fi
  26. # Always ask the remote drive to detach. There is no other use.
  27. timeout "${TIMEOUT}" osascript -e 'tell application "OpenDrive" to quit'
  28. # Always exit cleanly
  29. exit 0