From 3cee70f01eefb6aac534f54e5bea5fc8e48659e7 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 8 Sep 2016 20:31:11 +0200 Subject: [PATCH] bin/owncloud-sync --- bin/owncloud-sync | 67 ++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/bin/owncloud-sync b/bin/owncloud-sync index d8a57921..9341f4c3 100755 --- a/bin/owncloud-sync +++ b/bin/owncloud-sync @@ -87,6 +87,43 @@ Nicolas Boisselier nicolas.boisselier@gmail.com " } +owncloud_sync() { + if [ "$DEBUG" -gt 0 ]; then + echo DEBUG: owncloudcmd -n --non-interactive "$1" "$2" + return + fi + + lock=~/$NAME.lock + if [ -e "$lock" ]; then + [ "$VERBOSE" -gt 0 ] && echo "$lock already exists" + return 1 + fi + + if ! touch "$lock"; then + echo "Can't create $lock" 1>&2 + rm "$lock" + return 1 + fi + + owncloudcmd -n --non-interactive "$1" "$2" 2>&1 | perl -ne 'print "$1 $2 $3\n" iand next; if /OCC::(\S+).*?"(.*?)" . "(.*?)" "(.*?)"/; print' + + rm "$lock" + return 0 +} + +owncloud_all() { + [ -z "$*" ] && return 1 + IFS=$'\n' + for dir in `eval ls -1d "$*" 2>/dev/null`; do + user=`ls -ld "$dir" |awk '{print $3}'` + cd "$dir" || continue + + [ "$VERBOSE" -gt 0 ] && echo "$user: $dir" + su - "$user" -c "$NAME" | sed "s/^/$user /" + + done +} + dir_mounted() { mount -l | awk '$3 == "'$1'" { exit 1 }' && return 1 return 0 @@ -115,34 +152,4 @@ verbose() { echo "VERBOSE: $msg" >&2 } - -owncloud_sync() { - lock="~/$NAME.lock" - if [ -e "$lock" ]; then - [ "$VERBOSE" -gt 0 ] && echo "$lock already exists" - return 1 - fi - if ! touch "$lock"; then - [ "$VERBOSE" -gt 0 ] && echo "Can't create $lock" - rm "$lock" - return 1 - fi - # /OCC::(.*?) created for "(*.?)" . "(.*?)/" - echo owncloudcmd -n --non-interactive "$1" "$2" 2>&1 | perl -ne 'print "$1 $2 $3\n" iand next; if /OCC::(\S+).*?"(.*?)" . "(.*?)" "(.*?)"/; print' - rm "$lock" - return 0 -} - -owncloud_all() { - [ -z "$*" ] && return 1 - IFS=$'\n' - for dir in `eval ls -1d "$*" 2>/dev/null`; do - user=`ls -ld "$dir" |awk '{print $3}'` - cd "$dir" || continue - - [ "$VERBOSE" -gt 0 ] && echo "$user: $dir" - su - "$user" -c "$NAME" | sed "s/^/$user /" - - done -} main -- 2.47.3