From 1168cd222ddbcb77d6471e87e6ac9a705a0336a2 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 15 Jul 2023 15:09:35 -0500 Subject: [PATCH] update --- nextcloud-sync.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 nextcloud-sync.sh diff --git a/nextcloud-sync.sh b/nextcloud-sync.sh new file mode 100755 index 0000000..9b49078 --- /dev/null +++ b/nextcloud-sync.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +[ -f /opt/nc-sync.running ] && [ $(expr $(date +%s) - $(stat -L --format %Y /opt/nc-sync.running)) -gt 21600 ] && /bin/rm -f /opt/nc-sync.running + +if [ ! -f /opt/nc-sync.running ]; then + NC_PATH="/mnt/NC-Games" + SYNC_FOLDER="/mnt/NC-Games/._sync_nextcloud" + + touch /opt/nc-sync.running + + + if [ ! -f ${NC_PATH}/mounted ]; then + /usr/bin/mount -a + sleep 5s + fi + + if [ -f ${NC_PATH}/mounted ] || [ "${1}" == "skipmount" ]; then + [ -f /opt/mount.failure ] && /bin/rm -f /opt/mount.failure + if [ -f ${SYNC_FOLDER}/failures.txt ]; then + if [ -f ${SYNC_FOLDER}/failures2.txt ]; then + echo "Nextcloud sync failure, ${SYNC_FOLDER}/failures.txt exists." + echo -e "${SYNC_FOLDER}/failures.txt Exists\n\n$(date)" | mail -s "Nextcloud Sync Failure" 9208839613@mms.att.net + /bin/rm -f /opt/nc-sync.running + exit 1 + else + /bin/mv ${SYNC_FOLDER}/failures.txt ${SYNC_FOLDER}/failures2.txt + fi + fi + if [ ! -f ${SYNC_FOLDER}/failures.txt ]; then + echo "Sync Started" + /opt/nextcloud-sync-cron/nextcloud-sync-cron.sh --verbose /opt/nextcloud-sync-cron/nextcloud-client.conf + echo "Sync Finished" + if [ -f ${SYNC_FOLDER}/failures2.txt ] && [ ! -f ${SYNC_FOLDER}/failures.txt ]; then + echo "$(date): Fixed" >> ${NC_PATH}/sync.log + /bin/rm -f ${SYNC_FOLDER}/failures* + fi + /bin/rm -f /opt/nc-sync.running + exit 0 + fi + else + if [ -f /opt/mount.failure ]; then + echo -e "The folder ${NC_PATH} Cannot be mounted\n\n$(date)" | mail -s "Nextcloud Sync Unmounted" 9208839613@mms.att.net + /bin/rm -f /opt/nc-sync.running + exit 1 + else + /usr/bin/mount -a + touch /opt/mount.failure + /bin/rm -f /opt/nc-sync.running + exit 1 + fi + fi + +else + echo "There is a sync in process" + exit 0 +fi +exit 1 \ No newline at end of file