syncAll.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # Config
  3. SYNC_BIN="${HOME}/bin/video/backup/sync.sh"
  4. # Bail silently if ~/.archive_disable exists
  5. if [ -e ~/.archive_disable ]; then
  6. exit 0
  7. fi
  8. # Ensure we have a valid TMPDIR
  9. if [ ! -d "${TMPDIR}" ]; then
  10. TMPDIR="`getconf DARWIN_USER_TEMP_DIR 2>/dev/null`"
  11. if [ ! -d "${TMPDIR}" ]; then
  12. TMPDIR="/var/tmp"
  13. fi
  14. if [ ! -d "${TMPDIR}" ]; then
  15. TMPDIR="/tmp"
  16. fi
  17. fi
  18. # Bail if we're already running
  19. PID_FILE="${TMPDIR}/syncAll.pid"
  20. touch "${PID_FILE}"
  21. read SYNC_PID < "${PID_FILE}"
  22. if [ -n "${SYNC_PID}" ] && ps -A -o pid | grep -q "${SYNC_PID}"; then
  23. exit 0
  24. else
  25. echo $$ > "${PID_FILE}"
  26. fi
  27. # Fast updates for previously-synced paths
  28. # Slower updates for recently added paths
  29. "${SYNC_BIN}" Backups 5
  30. "${SYNC_BIN}" DMX 10
  31. "${SYNC_BIN}" iTunes/iTunes\ Music 10
  32. "${SYNC_BIN}" School 10
  33. "${SYNC_BIN}" Movies 5
  34. "${SYNC_BIN}" TV 5
  35. "${SYNC_BIN}" YouTube 50
  36. # If iPhoto is available, copy to Bitcasa
  37. MOUNTED=0
  38. if [ ! -d /Volumes/iPhoto ]; then
  39. MOUNTED=1
  40. hdiutil attach -readonly /mnt/media/Pictures/iPhoto.sparsebundle >/dev/null 2>&1
  41. fi
  42. if [ -d /Volumes/iPhoto ]; then
  43. BASE_LOCAL="/Volumes/iPhoto" "${SYNC_BIN}" Shared.photolibrary 1000
  44. if [ $MOUNTED -gt 0 ]; then
  45. hdiutil detach /Volumes/iPhoto >/dev/null 2>&1
  46. fi
  47. fi
  48. # Always exit cleanly
  49. rm -f "${PID_FILE}"
  50. exit 0