Saturday, May 14, 2016

Adding Google Drive to my Linux Box

GRIVE Installation and scripting

I have been digging around to see if there is a Google Drive service available for my Linux box.  I preferred to have something like what I have on the high end laptop (windows 10) in that it looks like a drive and I can manipulate the files in any way I want and updates GDRIVE immediately.  So far there is nothing like that in LINUX, but, there is a package called GRIVE.  I read up the documentation on the package and saw that it was something that I could use for now.  I installed the package, followed the instructions to link the app to my GMAIL account and then did a synchronize.  The first run took several minutes while it downloaded all of the files and folders, but, when I run again the synchronize took only a few seconds.  While this isn't perfect it does allow me to access my GDRIVE files, make updates and then sync the changes.

I always like to automate my tasks if I have to run it more than once.  For jobs scheduled on a regular basis I prefer CRONTAB, for things not on a regular schedule I prefer a folder with scripts or links to do the job.  For GRIVE I wrote two very simple BASH scripts to automate my synchronizing my GDRIVE files.  The first one displays to the user what will be done and give them the option to continue or quit.  The second calls the first from an XTERM window where I set up the font to a readable size.  I dropped a link to the second script to my desktop and ran it.  The script is very simple, possibly over-kill, but, I like to automate things so one click does the work for me.  I ran the script this morning as I had two new images (for this blog entry) and it synchronized my files in several seconds.  There is a lot more to the script that what you see, but, it is just setting up the color variables and getting the system time.  I don't need to use the time yet, but, it is part of my normal BASH skeleton script.

Screen shots

BASH script to sync to Google Drive using GRIVE

What the BASH script presents to me when run

Full BASH script to run GRIVE

#! /bin/sh
# ANSI Colors
#  Version:
#    - Version 1.0.0 2016/05/15
#    - Copyright 2016 Thomas Traynor.
#    - Program is distributed under the terms of the GNU General Public License
#    -       
#    - Release Notes:
#  Notes:
# ------------------------------------------------------------

zSetANSI() {

# Foreground colors:
    uFGBK="\033[30m";   #Black
    uFGLRD="\033[31m";  #Low  Red
    uFGHRD="\033[91m";  #High Red
    uFGLGR="\033[32m";  #Low  Green
    uFGHGR="\033[92m";  #High Green
    uFGLYW="\033[33m";  #Low  Yellow
    uFGHYW="\033[93m";  #High Yellow
    uFGLBU="\033[34m";  #Low  Blue
    uFGHBU="\033[94m";  #High Blue
    uFGLMG="\033[35m";  #Low  Magenta
    uFGHMG="\033[95m";  #High Magenta
    uFGLCY="\033[36m";  #Low  Cyan
    uFGHCY="\033[96m";  #High Cyan
    uFGHGY="\033[37m";  #High Gray
    uFGLGY="\033[90m";  #Low  Gray
    uFGWT="\033[97m";   #White

# Background colors:  
    uBGBK="\033[40m";   #Black
    uBGLRD="\033[41m";  #Low  Red
    uBGHRD="\033[101m"; #High Red
    uBGLGR="\033[42m";  #Low  Green
    uBGHGR="\033[102m"; #High Green
    uBGLYW="\033[43m";  #Low  Yellow
    uBGHYW="\033[103m"; #High Yellow
    uBGLBU="\033[44m";  #Low  Blue
    uBGHBU="\033[104m"; #High Blue
    uBGLMG="\033[45m";  #Low  Magenta
    uBGHMG="\033[105m"; #High Magenta
    uBGLCY="\033[46m";  #Low  Cyan
    uBGHCY="\033[106m"; #High Cyan
    uBGLGY="\033[47m";  #Low  Gray
    uBGHGY="\033[107m"; #High Gray

# Underline:
# Blink:
# Reset all:  

#  Get the system clock and set to a variable.

zGetDATE() {

# System date.  For all date options type date --h on command line.

    uSYSYY=$(date +%Y);
    uSYSMM=$(date +%m);
    uSYSDY=$(date +%d);
    uSYSHH=$(date +%H);
    uSYSMIN=$(date +%M);
    uSYSSEC=$(date +%S);
    uSYSJDT=$(date +%j);
    uSYSWK=$(date +%W);
    uSYSDOW=$(date +%w);
    uSYSDAY=$(date +%A)  
    uSYSMTH=$(date +%B)

# ============================================================
# ============================================================


# Define the working variable for return codes:

# Get current directory name
uDir=$( cd "$( dirname "$0" )" && pwd);


# Get process ID

#  Now echo out the stuff to the console:

echo ;
echo -e "${uFGHRD}Syncronize with Google Drive${uFGRESET}";
echo ;

cd ~/GoogleDrive

echo -e "${uFGLGR}This could take a while syncronizing the files."
echo -e "If you want to continue press ${uBGLGR}${uFGBLINK}${uFGBK}[ENTER]${uFGRESET}"
echo -e "${uFGLGR}otherwise ${uBGLGR}${uFGBLINK}${uFGBK}[CTRL-C]${uFGRESET}${uFGLGR}."
echo -e "${UFGRESET}"
read uLINE

echo ;
echo -e "${uFGHRD}Syncronize Finished${uFGRESET}";
echo -e "${uFGLGR}press ${uBGLGR}${uFGBLINK}${uFGBK}[ENTER]${uFGRESET}${uFGLGR} to finish update"
read uLINE

No comments: