forked from egeerardyn/grive-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ysgit/features/multiple-drives
Support multiple drives and command line parameters
- Loading branch information
Showing
2 changed files
with
21 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.grive_state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 |