Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a few useful scripts for auto upload and periodic download sync #273

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions scripts/crontab.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This example runs grive on /home/USER/gdrive
# See man crontab for format
# This line runs at 5 after the hour and 35 after the hour

5,35 * * * * /usr/bin/grive -p /home/USER/gdrive
52 changes: 52 additions & 0 deletions scripts/grive-incron
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# Allow grive to be called from incron
# if your path is /home/User/gdrivef and this file is in /usr/local/bin then use the following incrontab line:
# /home/User/gdrive IN_CREATE,IN_DELETE,IN_CLOSE_WRITE,IN_MOVE /usr/local/bin/grive-incron $# /home/User/gdrive

# grive-incron a bash script to allow automatic push to gdrive from a directory
# It is made to be called by # incron
#
# Copyright (C) 2014 Al Williams ([email protected])
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

PIDFILE=/tmp/grive-incron.lock

if [ $# != 2 ]
then
>&2 echo Call from incron: \$# directory
exit 1
fi
if [ "$1" == .grive -o "$1" == .grive_state ]
then
exit 0 # ignore grive housekeeping files
fi
# Don't run multiple copies at once

DLY=1

while true
do
while [ -f "$PIDFILE" ] && kill -0 `cat "$PIDFILE"` 2>/dev/null
do
sleep $DLY
DLY=$((DLY+1))
DLY=$((DLY % 10 )) # no more than 10 seconds
done
if ! kill -0 `cat "$PIDFILE" 2>/dev/null` 2>/dev/null
then
rm -f "$PIDFILE"
fi
if (set -o noclobber; echo $$>"$PIDFILE" ) >/dev/null
then
trap 'rm -f "$PIDFILE"' INT TERM EXIT
break
fi
done
grive -p "$2"
rm -f "$PIDFILE"
trap - INT TERM EXIT
exit 0
3 changes: 3 additions & 0 deletions scripts/incron.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Fix path below (2 places) and location of grive-incron script
/home/USER/gdrive IN_CREATE,IN_DELETE,IN_CLOSE_WRITE,IN_MOVE /usr/bin/grive-incron $# /home/USER/gdrive

40 changes: 40 additions & 0 deletions scripts/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
This directory contains a simple script that allows calling
grive from incron. This will cause any changes you make
to the local directory to automatically call grive to
update Google Drive. You can copy the script to a location on your
path:

sudo cp grive-incron /usr/local/bin

To make this work, you also need to insert the contents of incrontab.txt
into your incrontab (after changing the paths to suit your
installation).

To do this run:
incrontab -e

Then use the editor that appears to insert the line with your custom
paths. You can ignore lines that start with # -- they are just comments
although you can paste them into the incrontab if you like.

To get the reverse, you can do a similar command in your crontab (see
crontab.txt). The example syncs at 5 and 35 minutes after each hour
but you can customize that by changing the crontab line.

crontab -e

will bring up an editor. Copy the line without the # in front from
crontab.txt after fixing it for your specific path names. You can
skip the # lines or include them, as before.

You probably don't want to do a crontab sync every minute because
grive takes some time to run. The grive-incron script stalls if
another copy of it or grive is running for the current user to
prevent overrun, but the crontab entry has on such protection. If you
prefer, you could use the same script with a dummy file name in crontab.
Then your crontab line would look something like this:

5,35 * * * * /usr/local/bin/grive-incron DUMMY /home/USER/gdrive

The word DUMMY is just a placeholder. It does not have to refer to a real
file.