Przeglądaj źródła

Better parameters

Zachary Kotlarek 12 lat temu
rodzic
commit
e9d7bacf45
2 zmienionych plików z 20 dodań i 18 usunięć
  1. 5 8
      backup/sync.sh
  2. 15 10
      backup/syncPhotos.sh

+ 5 - 8
backup/sync.sh

@@ -1,14 +1,11 @@
 #!/bin/bash
 
-# Ensure the media share is mounted
-if ! ~/bin/video/isMediaMounted; then
-	echo 'Media share not available' 1>&2
-	exit 1
-fi
-
 # Config
+if [ -z "${VIDEO_DIR}" ]; then
+	VIDEO_DIR="${HOME}/bin/video"
+fi
 if [ -z "${BASE_LOCAL}" ]; then
-	BASE_LOCAL="`~/bin/video/mediaPath`"
+	BASE_LOCAL="`${VIDEO_DIR}/mediaPath`"
 fi
 if [ -z "${BASE_REMOTE}" ]; then
 	BASE_REMOTE="/mnt/remote/opendrive"
@@ -34,7 +31,7 @@ if [ -z "${SUB_DIR}" ] || [ $NUM_FILES -lt 1 ] || [ $DELAY_DAYS -lt 1 ]; then
 fi
 
 # Bail if the load is high
-if ! ~/bin/video/checkLoad.sh; then
+if ! "${VIDEO_DIR}/checkLoad.sh"; then
 	exit 0
 fi
 

+ 15 - 10
backup/syncPhotos.sh

@@ -1,25 +1,30 @@
 #!/bin/bash
 
+# User config
 export BASE_LOCAL="/Volumes/iPhoto"
 export BASE_REMOTE="/Volumes/webdav.opendrive.com"
+SOURCE_LOCAL="/mnt/media/Pictures/iPhoto.sparsebundle"
+SOURCE_REMOTE="https://webdav.opendrive.com"
 TARGET="Shared.photolibrary"
 
+# App config
+RETRIES=10
+SYNC_BIN="${HOME}/bin/video/backup/sync.sh"
+
 # Mount the remote drive if needed
 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
+	# 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}"
 fi
-# Drive not mounted
 if [ ! -d "${BASE_REMOTE}/${TARGET}" ]; then
 	MOUNTED_REMOTE=1
 	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
 			exit 1
 		fi
@@ -32,12 +37,12 @@ fi
 MOUNTED_LOCAL=0
 if [ ! -d "${BASE_LOCAL}" ]; then
 	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
 
 # Backup if all went well
 if [ -d "${BASE_REMOTE}" ] && [ -d "${BASE_LOCAL}" ]; then
-	~/bin/video/backup/sync.sh "${TARGET}" 1000
+	"${SYNC_BIN}" "${TARGET}" 1000
 fi
 
 # Detach the local drive if we mounted it