فهرست منبع

Support use on either system, and with the NFS-based app

Zachary Kotlarek 12 سال پیش
والد
کامیت
8512f15187
5فایلهای تغییر یافته به همراه48 افزوده شده و 48 حذف شده
  1. 33 16
      backup/checkMount.sh
  2. 9 0
      backup/remoteDir.sh
  3. 1 1
      backup/sync.sh
  4. 1 1
      backup/syncAll.sh
  5. 4 30
      backup/syncPhotos.sh

+ 33 - 16
backup/checkMount.sh

@@ -1,11 +1,15 @@
 #!/bin/bash
 
 # Config
+TIMEOUT=20
+DARWIN_APP="/Applications/Zach/Internet/OpenDrive.app"
+if [ -z "${VIDEO_DIR}" ]; then
+	VIDEO_DIR="${HOME}/bin/video"
+fi
 if [ -z "${BASE_REMOTE}" ]; then
-	BASE_REMOTE="/mnt/remote/opendrive"
+	BASE_REMOTE="`"${VIDEO_DIR}/backup/remoteDir.sh"`"
 fi
 WC="${BASE_REMOTE}/.live_check"
-TIMEOUT=20
 
 # State
 FAILED=0
@@ -32,26 +36,39 @@ fi
 
 # Reset if needed
 if [ $FAILED -gt 0 ]; then
-	SUOD=""
-	if [ $UID -gt 0 ]; then
-		SUDO="sudo"
-	fi
+	echo 'Resetting OpenDrive mount' 1>&2
 
-	DASH_NAME="`echo "${BASE_REMOTE}" | cut -d '/' -f 2- | sed 's%/%-%g'`"
-	PID=`ps ax -o pid=,command= | grep 'mount.davfs' | grep "${BASE_REMOTE}" | awk '{print $1}'`
+	if uname | grep -qi Darwin; then
+		PID=`ps ax -o pid=,command= | grep -v grep | grep '/Contents/MacOS/OpenDrive' | awk '{print $1}'`
+		if [ -n "${PID}" ]; then
+			${SUDO} kill -9 $PID
+		fi
 
-	echo 'Resetting WebDAV mount' 1>&2
+		open "${DARWIN_APP}"
 
-	if [ -n "${PID}" ] && [ $PID -gt 1 ]; then
-		${SUDO} kill -9 $PID
-	fi
+		# WebDAV mount
+		#SOURCE_REMOTE="https://webdav.opendrive.com"
+		#mount_webdav -s "${SOURCE_REMOTE}" "${BASE_REMOTE}"
+
+	else
+		SUOD=""
+		if [ $UID -gt 0 ]; then
+			SUDO="sudo"
+		fi
 
-	${SUDO} umount "${BASE_REMOTE}"
-	${SUDO} rm -f "/var/run/mount.davfs/${DASH_NAME}.pid"
-	${SUDO} mount "${BASE_REMOTE}"
+		PID=`ps ax -o pid=,command= | grep -v grep | grep 'mount.davfs' | grep "${BASE_REMOTE}" | awk '{print $1}'`
+		if [ -n "${PID}" ]; then
+			${SUDO} kill -9 $PID
+		fi
+
+		DASH_NAME="`echo "${BASE_REMOTE}" | cut -d '/' -f 2- | sed 's%/%-%g'`"
+		${SUDO} umount "${BASE_REMOTE}"
+		${SUDO} rm -f "/var/run/mount.davfs/${DASH_NAME}.pid"
+		${SUDO} mount "${BASE_REMOTE}"
+	fi
 
 	exit 1
 fi
 
-# Always exit cleanly
+# Exit cleanly
 exit 0

+ 9 - 0
backup/remoteDir.sh

@@ -0,0 +1,9 @@
+#!/bin/bash
+
+if [ -z "${BASE_REMOTE}" ]; then
+	BASE_REMOTE="/mnt/remote/opendrive"
+	if [ ! -d `dirname "${BASE_REMOTE}"` ]; then
+		BASE_REMOTE="/Volumes/OpenDrive"
+	fi
+fi
+echo "${BASE_REMOTE}"

+ 1 - 1
backup/sync.sh

@@ -8,7 +8,7 @@ if [ -z "${BASE_LOCAL}" ]; then
 	BASE_LOCAL="`${VIDEO_DIR}/mediaPath`"
 fi
 if [ -z "${BASE_REMOTE}" ]; then
-	BASE_REMOTE="/mnt/remote/opendrive"
+	BASE_REMOTE="`"${VIDEO_DIR}/backup/remoteDir.sh"`"
 fi
 
 # Command-line arguments

+ 1 - 1
backup/syncAll.sh

@@ -29,7 +29,7 @@ else
 	echo $$ > "${PID_FILE}"
 fi
 
-# Ensure the drive is available
+# Ensure the remote drive is available
 "${VIDEO_DIR}/backup/checkMount.sh"
 
 # Fast updates for previously-synced paths

+ 4 - 30
backup/syncPhotos.sh

@@ -2,38 +2,17 @@
 
 # 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
-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
-if [ ! -d "${BASE_REMOTE}/${TARGET}" ]; then
-	MOUNTED_REMOTE=1
-	FAIL_COUNT=0
-	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
-		FAIL_COUNT=$(( $FAIL_COUNT + 1 ))
-		sleep 5
-	done
-fi
+# Ensure the remote drive is available
+"${VIDEO_DIR}/backup/checkMount.sh"
 
-# Mount th local drive if needed
+# Mount the local drive if needed
 MOUNTED_LOCAL=0
 if [ ! -d "${BASE_LOCAL}" ]; then
 	MOUNTED_LOCAL=1
@@ -41,7 +20,7 @@ if [ ! -d "${BASE_LOCAL}" ]; then
 fi
 
 # Backup if all went well
-if [ -d "${BASE_REMOTE}" ] && [ -d "${BASE_LOCAL}" ]; then
+if [ -d "${BASE_LOCAL}" ]; then
 	"${SYNC_BIN}" "${TARGET}" 1000
 fi
 
@@ -50,10 +29,5 @@ if [ -d "${BASE_LOCAL}" ] && [ $MOUNTED_LOCAL -gt 0 ]; then
 	hdiutil detach "${BASE_LOCAL}" >/dev/null 2>&1
 fi
 
-# Detach the remote drive if we mounted it
-if [ -d "${BASE_REMOTE}" ] &&[ $MOUNTED_REMOTE -gt 0 ]; then
-	umount "${BASE_REMOTE}"
-fi
-
 # Always exit cleanly
 exit 0