HAVE you ever wanted to use your Google Drive like a ... well, a normal folder? If you're on Windows or Mac, you're in luck because Google offers a free desktop utility for exactly that purpose.
If you're on Linux however, there is no official utility from Google. There are a couple of paid or freemium options which could do the job, but there's also an open source option, written in OCaml, and since I like OCaml, I'll be talking about that here.
The tool in question is named google-drive-ocamlfuse and it is a single command that, when run, 'mounts' (attaches) your Google Drive as a filesystem (effectively, a directory on your computer).
Google-drive-ocamlfuse is distributed in operating system packages for Ubuntu and a couple of other Linuxes--check the wiki page for details. However, it is not distributed for the OS I use, Fedora, so I will walk through the installation process using opam, the operating system-agnostic OCaml package manager.
But, before we proceed, you need to be aware of something--google-drive-ocamlfuse (let's call it gdfuse for short) uses a proxy ('gaeproxy') deployed on Google App Engine to request access tokens from Google on your behalf. You can check the code here: https://github.com/astrada/google-drive-ocamlfuse/blob/3bbc4d054fbd7a7cdef36c17d88a5316183fd403/src/gaeProxy.ml#L6
It's up to you whether you feel comfortable with this proxy acting on your behalf. In my opinion it's similar to other third-party applications that you grant access to carry out some functions for you. If you decide to revoke the access later, you can do so here: https://myaccount.google.com/permissions?hl=en&pli=1
Having said that, if you decide to go ahead, here's how to install it. First, you'll need the opam package manager, as mentioned above. If you don't already have it, follow the installation instructions to set it up. Important--also need to actually initialize opam before it actually starts working, and switch to a recent OCaml version so that you're reasonably up-to-date.
Once that's done, run the following to get a list of non-OCaml software dependencies needed for gdfuse to work:
opam install depext opam depext google-drive-ocamlfuse
This will actually offer to run
yum install ... and install the packages immediately, however I declined because I prefer to use dnf, Fedora's new package manager that replaces yum:
sudo dnf install fuse-devel libcurl-devel pkgconfig sqlite-devel
(Depext may actually give you a slightly different list than the one I have here, so take care to install the exact packages for your system.)
Then, you can install gdfuse itself:
opam install google-drive-ocamlfuse
Then, authorize it with Google:
This step launches the authorization page in your browser and prompts you through the process. Once done, gdfuse will report that it authorized:
$ google-drive-ocamlfuse Access token retrieved correctly.
Now, we need to set up gdfuse so that it automatically mounts Google Drive on system boot and unmounts it on shutdown.
To set up the automation, we will use systemd, the standard Linux service manager. The trick is to think of gdfuse as a regular Linux service. It will start up on system boot, at which point it will mount the Google Drive; and it will shut down on system shutdown, at which point it will unmount the Drive.
First, we need to create the directory which will serve as the mount point. In other words, the actual directory where all the Google Drive files will appear. I chose:
Next, set up a systemd service definition file for gdfuse with the correct mount/unmount commands:
# ~/.config/systemd/user/gdfuse.service [Unit] Description=google-drive-ocamlfuse - mount Google Drive as a filesystem After=network-online.target Wants=network-online.target [Service] ExecStart=/home/YOURNAME/.opam/default/bin/google-drive-ocamlfuse -f /home/YOURNAME/GoogleDrive ExecStop=/usr/bin/fusermount -u /home/YOURNAME/GoogleDrive [Install] WantedBy=multi-user.target
(Be sure to replace
YOURNAME with your username.)
A few noteworthy points:
Wants=properties are used to ensure that gdfuse only starts up after the network is up. Check the documentation for more details on that.
ExecStart=property makes sure to start gdfuse in foreground mode (with the
-fflag), so that systemd can take control of the process.
ExecStop=property ensures the Drive is unmounted on system shutdown.
WantedBy=property ensures this service will actually get started on system boot.
Now, the standard systemd service installation and startup:
systemctl enable --now --user gdfuse
And voila, the service should be started and Google Drive mounted as a filesystem. You can check the service status:
$ systemctl status --user gdfuse ● gdfuse.service - google-drive-ocamlfuse - mount Google Drive as a filesystem Loaded: loaded (/home/yawar/.config/systemd/user/gdfuse.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2021-02-17 21:13:37 EST; 1h 21min ago Main PID: 478354 (google-drive-oc) Tasks: 3 (limit: 18878) Memory: 14.4M CPU: 2.703s CGroup: /email@example.com/gdfuse.service └─478354 /home/yawar/.opam/default/bin/google-drive-ocamlfuse -f /home/yawar/GoogleDrive
And the filesystem:
$ df -h ... google-drive-ocamlfuse 15G 1.6G 14G 11% /home/yawar/GoogleDrive
And the files themselves:
$ ls ~/GoogleDrive
Now, your Google Drive will be synchronized with any file changes you make in