--- /dev/null
+Title: Automatic Google Drive sync using grive in Debian
+Tags: english, debian
+Date: 2018-10-04 15:20
+
+<p>A few days, I rescued a Windows victim over to Debian. To try to
+rescue the remains, I helped set up automatic sync with Google Drive.
+I did not find any sensible Debian package handling this
+automatically, so I rebuild the grive2 source from
+<a href="http://www.webupd8.org/">the Ubuntu UPD8 PPA</a> to do the
+task and added a autostart desktop entry and a small shell script to
+run in the background while the user is logged in to do the sync.
+Here is a sketch of the setup for future reference.</p>
+
+<p>I first created <tt>~/googledrive</tt>, entered the directory and
+ran '<tt>grive -a</tt>' to authenticate the machine/user. Next, I
+created a autostart hook in <tt>~/.config/autostart/grive.desktop</tt>
+to start the sync when the user log in:</p>
+
+<p><blockquote><pre>
+[Desktop Entry]
+Name=Google drive autosync
+Type=Application
+Exec=/home/user/bin/grive-sync
+</pre></blockquote></p>
+
+<p>Finally, I wrote the <tt>~/bin/grive-sync</tt> script to sync
+~/googledrive/ with the files in Google Drive.</p>
+
+<p><blockquote><pre>
+#!/bin/sh
+set -e
+cd ~/
+cleanup() {
+ if [ "$syncpid" ] ; then
+ kill $syncpid
+ fi
+}
+trap cleanup EXIT INT QUIT
+/usr/lib/grive/grive-sync.sh listen googledrive 2>&1 | sed "s%^%$0:%" &
+syncpdi=$!
+while true; do
+ if ! xhost >/dev/null 2>&1 ; then
+ echo "no DISPLAY, exiting as the user probably logged out"
+ exit 1
+ fi
+ if [ ! -e /run/user/1000/grive-sync.sh_googledrive ] ; then
+ /usr/lib/grive/grive-sync.sh sync googledrive
+ fi
+ sleep 300
+done 2>&1 | sed "s%^%$0:%"
+</pre></blockquote></p>
+
+<p>Feel free to use the setup if you want. It can be assumed to be
+GNU GPL v2 licensed (or any later version, at your leisure), but I
+doubt this code is copyrightable at all.</p>
+
+<p>As usual, if you use Bitcoin and want to show your support of my
+activities, please send Bitcoin donations to my address
+<b><a href="bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b</a></b>.</p>