Skip to content

Commit

Permalink
Merge pull request #1 from ysgit/features/multiple-drives
Browse files Browse the repository at this point in the history
Support multiple drives and command line parameters
  • Loading branch information
ysgit committed Oct 30, 2013
2 parents 92fca51 + d4dcfa0 commit 981b970
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.grive_state
33 changes: 20 additions & 13 deletions grive-sync.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
###############################################################################
# grive-sync
# This script runs grive and greps the log output to create a
Expand All @@ -12,26 +12,25 @@
# 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

# 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/[email protected]:/home/myself/Grive/[email protected]"
GRIVE_DIRS="$1"

# Path to an icon for notify-osd
#NOTIFY_ICON="/home/josh/.icons/google-drive.png"
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NOTIFY_BIN=$(which notify-send)
NOTIFY_ICON="/home/myself/.icons/grive.png"
NOTIFY_ICON="$SCRIPT_PATH/icons/grive.png"

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)
Expand All @@ -55,6 +54,12 @@ if ! type grive >/dev/null 2>&1; then
exit 1
fi

IFS=':' read -ra grive_dirs_arr <<< "$GRIVE_DIRS"

for key in "${!grive_dirs_arr[@]}"; do

GRIVE_DIR="${grive_dirs_arr[$key]}"

# GRIVE_DIR doesn't exist
[ ! -d "${GRIVE_DIR}" ] && printf "${GRIVE_DIR} does not exist.\n" && exit 1

Expand All @@ -77,24 +82,24 @@ 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

if [ $_rdeletions -gt 0 ]; 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

Expand Down Expand Up @@ -126,3 +131,5 @@ if ! $ps_bin aux|$grep_bin -q -e '[g]rive '; then
# Remove the grive ouput log
$rm_bin -f "${TMPLOG}"
fi

done

0 comments on commit 981b970

Please sign in to comment.