From b6835eac12ced826d3a9eea2141f97b5eeb7a76f Mon Sep 17 00:00:00 2001 From: Yossi Synett Date: Wed, 30 Oct 2013 10:21:30 +0200 Subject: [PATCH 1/3] support multiple gdrives --- grive-sync.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/grive-sync.sh b/grive-sync.sh index ef48d61..5fb11e1 100755 --- a/grive-sync.sh +++ b/grive-sync.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ############################################################################### # grive-sync # This script runs grive and greps the log output to create a @@ -18,8 +18,8 @@ I_HAVE_EDITED=0 # This needs to best set for notify-send if calling from cron DISPLAY=:0.0 -# Path to directory of your Google Drive -GRIVE_DIR="/home/myself/Grive" +# Path to directory of your Google Drives, separate multiple drives by ":" +GRIVE_DIRS="/home/myself/Grive/user@domain.com:/home/myself/Grive/user2@domain2.com" # Path to an icon for notify-osd #NOTIFY_ICON="/home/josh/.icons/google-drive.png" @@ -55,6 +55,12 @@ if ! type grive >/dev/null 2>&1; then exit 1 fi +grive_dirs_arr=(`echo $str | cut -d ":" --output-delimiter=" " -f 1-`) + +for key in "${!grive_dirs_arr[@]}"; do + +GRIVE_DIR="${ary[$key]}" + # GRIVE_DIR doesn't exist [ ! -d "${GRIVE_DIR}" ] && printf "${GRIVE_DIR} does not exist.\n" && exit 1 @@ -126,3 +132,5 @@ if ! $ps_bin aux|$grep_bin -q -e '[g]rive '; then # Remove the grive ouput log $rm_bin -f "${TMPLOG}" fi + +done From b36562f9b13b4ed4eeb67b0bfa6a1806c24aafbe Mon Sep 17 00:00:00 2001 From: Yossi Synett Date: Wed, 30 Oct 2013 10:26:04 +0200 Subject: [PATCH 2/3] get paths as input variable, set icons dir automatically --- grive-sync.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/grive-sync.sh b/grive-sync.sh index 5fb11e1..5a478ad 100755 --- a/grive-sync.sh +++ b/grive-sync.sh @@ -19,12 +19,14 @@ I_HAVE_EDITED=0 DISPLAY=:0.0 # Path to directory of your Google Drives, separate multiple drives by ":" -GRIVE_DIRS="/home/myself/Grive/user@domain.com:/home/myself/Grive/user2@domain2.com" +#GRIVE_DIRS="/home/myself/Grive/user@domain.com:/home/myself/Grive/user2@domain2.com" +GRIVE_DIRS="$1" # Path to an icon for notify-osd #NOTIFY_ICON="/home/josh/.icons/google-drive.png" +SCRIPT_PATH="`dirname \"$0\"`" NOTIFY_BIN=$(which notify-send) -NOTIFY_ICON="/home/myself/.icons/grive.png" +NOTIFY_ICON="$SCRIPT_PATH/icons/grive.png" GRIVE_BIN=$(which grive) From d4dcfa0db16a28101c21d61e0e70f4bb2643f10a Mon Sep 17 00:00:00 2001 From: Yossi Synett Date: Wed, 30 Oct 2013 11:22:20 +0200 Subject: [PATCH 3/3] Make it all work --- .gitignore | 1 + grive-sync.sh | 21 +++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..60f54bc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.grive_state diff --git a/grive-sync.sh b/grive-sync.sh index 5a478ad..2e37200 100755 --- a/grive-sync.sh +++ b/grive-sync.sh @@ -12,9 +12,6 @@ # Feel free to do whatever you want with it. ############################################################################### -# Change this to 1 once you've changed the variables -I_HAVE_EDITED=0 - # This needs to best set for notify-send if calling from cron DISPLAY=:0.0 @@ -24,7 +21,7 @@ GRIVE_DIRS="$1" # Path to an icon for notify-osd #NOTIFY_ICON="/home/josh/.icons/google-drive.png" -SCRIPT_PATH="`dirname \"$0\"`" +SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" NOTIFY_BIN=$(which notify-send) NOTIFY_ICON="$SCRIPT_PATH/icons/grive.png" @@ -33,7 +30,7 @@ GRIVE_BIN=$(which grive) ############################################################################### # You don't need to edit below here unless you really want to ############################################################################### -[ "$I_HAVE_EDITED" -eq "0" ] && printf "You need to configure $0\n" && exit 1 +[ -z "$GRIVE_DIRS" ] && printf "Syntax: grive-sync.sh \"':' SEPARATED LIST OF FOLDERS TO SYNCHRONIZE\"\n" && exit 1 ps_bin=$(which ps) rm_bin=$(which rm) @@ -57,11 +54,11 @@ if ! type grive >/dev/null 2>&1; then exit 1 fi -grive_dirs_arr=(`echo $str | cut -d ":" --output-delimiter=" " -f 1-`) +IFS=':' read -ra grive_dirs_arr <<< "$GRIVE_DIRS" for key in "${!grive_dirs_arr[@]}"; do -GRIVE_DIR="${ary[$key]}" +GRIVE_DIR="${grive_dirs_arr[$key]}" # GRIVE_DIR doesn't exist [ ! -d "${GRIVE_DIR}" ] && printf "${GRIVE_DIR} does not exist.\n" && exit 1 @@ -85,14 +82,14 @@ if ! $ps_bin aux|$grep_bin -q -e '[g]rive '; then _downloads=$($grep_bin -c "${DOWNLOAD_MSG}" "${TMPLOG}") # Setup the notify-osd message - notify="" + notify="Finished synchronizing $GRIVE_DIR\n" if [ $_ldeletions -gt 0 ]; then # If it's only one file, show the filename if [ $_ldeletions -eq 1 ]; then _filename=$(get_filename "${REMOVEL_MSG}") - notify="$_filename removed from local" + notify="${notify}$_filename removed from local" else - notify="${_ldeletions} removed from local" + notify="${notify}${_ldeletions} removed from local" fi fi @@ -100,9 +97,9 @@ if ! $ps_bin aux|$grep_bin -q -e '[g]rive '; then [ ! -z "$notify" ] && notify="${notify}\n" if [ $_rdeletions -eq 1 ]; then _filename=$(get_filename "${REMOVER_MSG}") - notify="$_filename removed from remote" + notify="${notify}$_filename removed from remote" else - notify="${_rdeletions} removed from remote" + notify="${notify}${_rdeletions} removed from remote" fi fi