DEV Community

Arseny Zinchenko
Arseny Zinchenko

Posted on • Originally published at rtfm.co.ua on

Google Drive: using via terminal on Linux Debian 9 with insync-headless

I’d like to attach a Google Drive with my Calibre books library to a Debian host because to run the Calibre Web application, as Nextcloud with a big data not too much stable and I have around 5 GB of books (see the Calibre Web: home in-browser online-library with Nextcloud storage and Moon+ Reader on Android post).

After some ingestion over existing clients, I decided to use the Insync (15 days trial, 30 USD cost for one user).

The latest version can easily be installed from a repository – but it doesn’t support CLI anymore.

So, to install it add a key:

root@rtfm-do-production:/opt# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ACCAF35C
Executing: /tmp/apt-key-gpghome.mCNEtjtItQ/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys ACCAF35C
gpg: key A684470CACCAF35C: 1 signature not checked due to a missing key
gpg: key A684470CACCAF35C: public key "Insynchq Inc <services@insynchq.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
Enter fullscreen mode Exit fullscreen mode

Create a /etc/apt/sources.list.d/insync.list file:

deb http://apt.insync.io/debian stretch non-free contrib
Enter fullscreen mode Exit fullscreen mode

And install it:

root@rtfm-do-production:/opt# apt update && apt -y install insync
Enter fullscreen mode Exit fullscreen mode

insync-headless

But there is another story with the insync-headless, which actually provides CLI – its support was dropped in the latest versions, see the (LINUX) Headless and CLI community support for more details.

Still, you can use the older version, particularly 1.5.7.

Download its package:

root@rtfm-do-production:/tmp# wget https://d2t3ff60b2tol4.cloudfront.net/builds/insync-headless_1.5.7.37371-wheezy_amd64.deb
Enter fullscreen mode Exit fullscreen mode

Install it:

root@rtfm-do-production:/tmp# dpkg -i insync-headless_1.5.7.37371-wheezy_amd64.deb
Enter fullscreen mode Exit fullscreen mode

Start the service:

root@rtfm-do-production:/tmp# insync-headless start
Enter fullscreen mode Exit fullscreen mode

In your browser navigate to the https://insynchq.com/auth and log in with your Google used for Insync, and get your auth-code:

Authenticate your CLI application using the code above:

root@rtfm-do-production:/tmp# insync-headless add_account -a 4/z***MIA
Enter fullscreen mode Exit fullscreen mode

Synchronization will be started once you’ll add an account:

root@rtfm-do-production:/tmp# ls -l /root/user@gmail.com/
total 1928
-rw-r--r--   1 root root     210 Jun  4  2019 Apartments.gdsheet
-rw-r--r--   1 root root     171 Oct  1  2015 Blank Flowchart.gdlink
drwxr-xr-x 113 root root    4096 Apr 23 16:07 CALIBRE
drwxr-xr-x 309 root root   16384 Apr 23 16:07 CloudCalibre
-rw-r--r--   1 root root     206 May 23  2016 DEGREE_Word.gddoc
...
Enter fullscreen mode Exit fullscreen mode

To check its status use:

root@rtfm-do-production:/tmp# insync-headless get_sync_progress
Downloading
Jenkins_ The Definitive Guide - John Ferguson Smart.pdf (0% of 24.6 MB)
The Docker Book - James Turnbull.pdf (0% of 5.6 MB)
Utro novoi ery - Aleksei Doronin.fb2 (0% of 1.2 MB)
metadata.opf (0% of 3.3 KB)
1060 files queued
Enter fullscreen mode Exit fullscreen mode

@ and a directory name

But here is one small caveat: because the path to the folder containing your Google Drive data will have your email in its name with the @ – some applications, like Calibre Web, for example, won’t accept it as a valid pathname.

To solve this we can use well-know crunch – our lovely symlinks:

root@rtfm-do-production:/tmp# ln -s /root/user@gmail.com/CloudCalibre/ /opt/calibre/books
Enter fullscreen mode Exit fullscreen mode

Check it:

root@rtfm-do-production:/tmp# ll /opt/calibre/books/ | head -5
total 2776
drwxr-xr-x  3 root root    4096 Apr 23 16:05 A. A. Orlov
drwxr-xr-x  9 root root    4096 Apr 23 16:06 A. Avramienko
drwxr-xr-x  3 root root    4096 Apr 23 16:06 A. Bielash
drwxr-xr-x  3 root root    4096 Apr 23 16:06 A. B_iuli
Enter fullscreen mode Exit fullscreen mode

See more commands and documentation here>>>.

Similar posts

Top comments (0)