]> pere.pagekite.me Git - homepage.git/blob - blog/data/2018-10-04-grive-google-drive-sync.txt
Generated.
[homepage.git] / blog / data / 2018-10-04-grive-google-drive-sync.txt
1 Title: Automatic Google Drive sync using grive in Debian
2 Tags: english, debian
3 Date: 2018-10-04 15:20
4
5 <p>A few days, I rescued a Windows victim over to Debian. To try to
6 rescue the remains, I helped set up automatic sync with Google Drive.
7 I did not find any sensible Debian package handling this
8 automatically, so I rebuild the grive2 source from
9 <a href="http://www.webupd8.org/">the Ubuntu UPD8 PPA</a> to do the
10 task and added a autostart desktop entry and a small shell script to
11 run in the background while the user is logged in to do the sync.
12 Here is a sketch of the setup for future reference.</p>
13
14 <p>I first created <tt>~/googledrive</tt>, entered the directory and
15 ran '<tt>grive -a</tt>' to authenticate the machine/user. Next, I
16 created a autostart hook in <tt>~/.config/autostart/grive.desktop</tt>
17 to start the sync when the user log in:</p>
18
19 <p><blockquote><pre>
20 [Desktop Entry]
21 Name=Google drive autosync
22 Type=Application
23 Exec=/home/user/bin/grive-sync
24 </pre></blockquote></p>
25
26 <p>Finally, I wrote the <tt>~/bin/grive-sync</tt> script to sync
27 ~/googledrive/ with the files in Google Drive.</p>
28
29 <p><blockquote><pre>
30 #!/bin/sh
31 set -e
32 cd ~/
33 cleanup() {
34 if [ "$syncpid" ] ; then
35 kill $syncpid
36 fi
37 }
38 trap cleanup EXIT INT QUIT
39 /usr/lib/grive/grive-sync.sh listen googledrive 2>&1 | sed "s%^%$0:%" &
40 syncpdi=$!
41 while true; do
42 if ! xhost >/dev/null 2>&1 ; then
43 echo "no DISPLAY, exiting as the user probably logged out"
44 exit 1
45 fi
46 if [ ! -e /run/user/1000/grive-sync.sh_googledrive ] ; then
47 /usr/lib/grive/grive-sync.sh sync googledrive
48 fi
49 sleep 300
50 done 2>&1 | sed "s%^%$0:%"
51 </pre></blockquote></p>
52
53 <p>Feel free to use the setup if you want. It can be assumed to be
54 GNU GPL v2 licensed (or any later version, at your leisure), but I
55 doubt this code is possible to claim copyright on.</p>
56
57 <p>As usual, if you use Bitcoin and want to show your support of my
58 activities, please send Bitcoin donations to my address
59 <b><a href="bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b</a></b>.</p>