• Google Drive and Kubuntu

    05 May 2016
    Tags: cloud 

    Google Drive is a nice service but it unfortunately doesn't support Kubuntu natively. Below is an optimal setup for secure and easy Google Drive usage under Kubuntu Linux 16.04

    1. Download Grive2

    Grive2 provides a simple tool to sync your Google Drive. Open the konsole app and run the following command to begin.

    sudo add-apt-repository ppa:nilarimogard/webupd8 && sudo apt-get update && sudo apt-get install grive

    2. Setup a Grive Sync folder

    Create a folder to sync your Google Drive with. In the example below I am creating a folder called Google Drive in my encrypted home directory.

    mkdir ~/Google\ Drive

    Kubuntu supports encrypted home directories for extra security so that was an ideal location for my Google Drive.

    3. Setup Grive

    Run the following commands to enter your new folder and setup Grive.

    cd ~/Google\ Drive
    grive -a

    Grive will provide you with a link to authorize it to access your Google Drive. Open this link, then copy/paste the token it provides into your console. Now wait for Grive to sync.

    3. Automate Grive

    Unfortunately Grive will not automatically sync and things will become outdated. Forunately this can be solved with a simple script. Open kate and copy/paste the text from below.

    # Check if gedit is running
    if pgrep "grive" > /dev/null
      echo "Sync already running"
      today=$(date +"%Y%m%d")
      lastsync=$(cat /home/glen/lastsync)
      difference=`expr $today - $lastsync`
      power=$(cat /sys/class/power_supply/ADP0/online)
      # if over a day or if on AC power
      if [ "$difference" -gt "0" ] || [ "$power" -eq "1" ]
        # check if Google Drive can be accessed
        if wget -O /dev/null -q https://drive.google.com;
          grive -p /home/glen/Google\ Drive/
          echo $today > /home/glen/lastsync
          kdialog --passivepopup 'Google drive sync failed and sync is out of date' 3600

    Be sure to replace glen with your username and save this script in your home directory with the name googledrivesync.

    This script will first check if Grive is already syncing, so it doesn't attempt to run twice. Then it checks if Grive is more than one day out of sync. It also checks to see if you are on AC power. This is important if you don't want to drain your laptop's battery. Note the device /sys/class/power_supply/ADP0/online could be different on your PC.

    This script will only sync if Google Drive is accessable and it will popup a KDE notification if it is unable to sync when it attempts to.

    Next save a file called lastsync in your home directory. Open the file with kate and type the current date in exactly this format YYYYMMDD, for example 20160505. This file will store the last date you synced and the script will use it to know if it is a day behind syncing.

    4. Schedule the script

    First make sure the script is executable by running the follow command.

    chmod +x ~/googledrivesync

    Now run crontab -e and select nano (do not use sudo, you want this to run in your user's crontab). Copy and paste the text below into crontab to set the script to run hourly.

    0 * * * * /home/glen/googledrivesync

    Again remember to replace glen with your username.

    5. Setup CryFS

    Google Drive is not encrypted and there might be some things you want to securely store. A good solution is CryFS. It works similar to EncFS but is much more secure. EncFS has several unpatched security issues at the moment. Run the following command to setup CryFS.

    sudo wget -O - https://www.cryfs.org/install.sh | sudo bash 

    Setup a CryFS folder with the following command. I am choosing to call my folder private and my encrypted folder private. Be sure to substitute glen with your username.

    cryfs /home/glen/Google\ Drive/private /home/glen/private

    Accept the defaults and choose a strong password. You now have a secure folder called private within your home directory. When you store files in this folder it will automatically create encrypted entries in /home/username/Google Drive/private. Do not touch the folder in your Google Drive. Only work in the mounted folder under your home drive. You can learn more about how CryFS works at www.cryfs.org.

    6. Automount CryFS

    This is only recommended if you have an encrypted home folder. This will allow you to automatically mount your CryFS folder on login. First open kate and type your CryFS password. Now save this file under your encrypted home folder as .cryfs. This will create a hidden file with your CryFS password. Now open ~/.profile with kate. Add the following command to the bottom of the .profile file and save it.

    cat /home/glen/.cryfs | cryfs /home/glen/Google\ Drive/private/ /home/glen/private/

    Be sure to change glen to your username and be sure to change the paths if you chose different ones. Now your private files will be encrypted and synced with Google Drive. Your encrypted drive will also mount on login and your password will be stored in your encrypted home folder.


    You now have a Google Drive folder that will sync every hour on AC power or at least once a day. A notification will pop-up if you become more than one day out of sync. You also have an encrypted private folder for securely storing documents in the cloud.