|
@@ -1,25 +1,30 @@
|
|
|
#!/bin/bash
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
+# User config
|
|
|
export BASE_LOCAL="/Volumes/iPhoto"
|
|
export BASE_LOCAL="/Volumes/iPhoto"
|
|
|
export BASE_REMOTE="/Volumes/webdav.opendrive.com"
|
|
export BASE_REMOTE="/Volumes/webdav.opendrive.com"
|
|
|
|
|
+SOURCE_LOCAL="/mnt/media/Pictures/iPhoto.sparsebundle"
|
|
|
|
|
+SOURCE_REMOTE="https://webdav.opendrive.com"
|
|
|
TARGET="Shared.photolibrary"
|
|
TARGET="Shared.photolibrary"
|
|
|
|
|
|
|
|
|
|
+# App config
|
|
|
|
|
+RETRIES=10
|
|
|
|
|
+SYNC_BIN="${HOME}/bin/video/backup/sync.sh"
|
|
|
|
|
+
|
|
|
# Mount the remote drive if needed
|
|
# Mount the remote drive if needed
|
|
|
MOUNTED_REMOTE=0
|
|
MOUNTED_REMOTE=0
|
|
|
-# Mount point exists but is unreadable, so kill it
|
|
|
|
|
-if [ -e "${BASE_REMOTE}" ] && [ ! -d "${BASE_REMOTE}" ]; then
|
|
|
|
|
- umount "${BASE_REMOTE}"
|
|
|
|
|
-fi
|
|
|
|
|
-# Mount point does not exist
|
|
|
|
|
if [ ! -d "${BASE_REMOTE}" ]; then
|
|
if [ ! -d "${BASE_REMOTE}" ]; then
|
|
|
|
|
+ # Mount may be timed out, which will fail the -d test
|
|
|
|
|
+ if mount | grep -q "${BASE_REMOTE}"; then
|
|
|
|
|
+ umount "${BASE_REMOTE}"
|
|
|
|
|
+ fi
|
|
|
mkdir "${BASE_REMOTE}"
|
|
mkdir "${BASE_REMOTE}"
|
|
|
fi
|
|
fi
|
|
|
-# Drive not mounted
|
|
|
|
|
if [ ! -d "${BASE_REMOTE}/${TARGET}" ]; then
|
|
if [ ! -d "${BASE_REMOTE}/${TARGET}" ]; then
|
|
|
MOUNTED_REMOTE=1
|
|
MOUNTED_REMOTE=1
|
|
|
FAIL_COUNT=0
|
|
FAIL_COUNT=0
|
|
|
- while ! mount_webdav -s https://webdav.opendrive.com "${BASE_REMOTE}"; do
|
|
|
|
|
- if [ $FAIL_COUNT -gt 5 ]; then
|
|
|
|
|
|
|
+ while ! mount_webdav -s "${SOURCE_REMOTE}" "${BASE_REMOTE}"; do
|
|
|
|
|
+ if [ $FAIL_COUNT -gt $RETRIES ]; then
|
|
|
echo "Unable to mount remote drive" 1>&2
|
|
echo "Unable to mount remote drive" 1>&2
|
|
|
exit 1
|
|
exit 1
|
|
|
fi
|
|
fi
|
|
@@ -32,12 +37,12 @@ fi
|
|
|
MOUNTED_LOCAL=0
|
|
MOUNTED_LOCAL=0
|
|
|
if [ ! -d "${BASE_LOCAL}" ]; then
|
|
if [ ! -d "${BASE_LOCAL}" ]; then
|
|
|
MOUNTED_LOCAL=1
|
|
MOUNTED_LOCAL=1
|
|
|
- hdiutil attach -readonly /mnt/media/Pictures/iPhoto.sparsebundle >/dev/null 2>&1
|
|
|
|
|
|
|
+ hdiutil attach -readonly "${SOURCE_LOCAL}" >/dev/null 2>&1
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# Backup if all went well
|
|
# Backup if all went well
|
|
|
if [ -d "${BASE_REMOTE}" ] && [ -d "${BASE_LOCAL}" ]; then
|
|
if [ -d "${BASE_REMOTE}" ] && [ -d "${BASE_LOCAL}" ]; then
|
|
|
- ~/bin/video/backup/sync.sh "${TARGET}" 1000
|
|
|
|
|
|
|
+ "${SYNC_BIN}" "${TARGET}" 1000
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# Detach the local drive if we mounted it
|
|
# Detach the local drive if we mounted it
|