Skip to content

Gdrive installation

Q-engineering edited this page Aug 14, 2023 · 17 revisions

output image


👉 If you use our image it's already installed.

Gdrive is a command-line tool for managing your Google Gdrive from the Raspberry Pi.
It is already installed. Please continue with the Google authorization.

If you want to install Gdrive on another RPi, follow the steps below.
Start with the installation of Rust.

$ curl https://sh.rustup.rs -sSf | sh

Select the default option 1 and once completed, check the installation.

$ rustc --version
$ cargo --version

The next step is building gdrive.
Start by checking the size of swap memory ($ free -m). It needs to be 2 GByte or more.
If required, enlarge the space by the the following commands.

$ sudo nano /etc/dphys-swapfile
# set CONF_SWAPSIZE=2048 
# save with <Ctrl><X>, <Y>, <Enter>

Now, with sufficient memory available, build the gdrive executable.

$ git clone https://github.com/glotlabs/gdrive.git
$ cd ~/gdrive
$ cargo build --release
$ sudo cp ./target/release/gdrive /usr/local/bin

Authorization key

The next step is getting the authorization key from Google. With the key in place, you can access your Gdrive.
The key is only valid for the current Raspberry Pi and will be stored at /home/pi/.config/gdrive3
output image
Note that everyone with access to this file has access to your Gdrive. Be careful.

👉The whole procedure involves many steps. Follow the guide carefully.

1 Create a Google account.

Of course, you need a Google account to access Google Drive.
It is best to create a new account. You don't want your personal information exposed as the access keys are not that well protected in the Raspberry Pi.
You must activate your account with the so-called 2-step verification, otherwise, Google will not allow access to the content.
See also the email wiki.

2 Start with making a new project in Google Cloud Console.

output image

output image

Or
output image

3 Give the project a name, like YoloCam.

output image
Wait a few second until the project is created by Google.

4 Select your project.

output image

5 Go to Google Drive Api under marketplace.

output image

6 Enable the Google Drive Api.

output image

7 Select the menu option credentials and click configure consent screen.

output image

8 Select external and click create.

output image

9 Give a name and email adresses.

The first email address is always your Gmail. Other addresses are not possible.
The second one can be any valid email address. Google notifies you when the project changes.
If you want, you can upload a logo, it's not required.
output image

10 Add a scope.

output image

11 Select ..auth/drive and ..auth/drive.metadata.readonly.

output image
output image

12 Save and continue.

output image

13 Give the user email address.

output image

14 Save and continue.

output image

15 Select OAuth client ID.

Click menu item Credentials - Create credentials - OAuth client ID
output image

16 Select Desktop app, give a name and create.

output image

17 Client ID and secret.

Copy-paste the client ID and secret, or download the JSON file. You will need them soon.
output image

18 Publish the app.

Click the OAuth Consent Screen menu option and publish the app to prevent it from expiring in 7 days.
output image
output image

19 Ignore the verification.

The Gdrive software works perfectly without verifying the app.
output image

20 Start Gdrive.

In the Raspberry Pi terminal, issue the command gdrive account add.
You prompted to provide the client ID and client secret. Enter those received at step 16.
Then right-click on the URL and select Open URL from the context menu. Chromium opens.
output image

21 Activate the app.

After the 2-step verification of your Google account, you will see a screen warning that the app is not verified.
Click on the "Advanced" section and activate the app.
output image

22 Select services.

Grant your app to access the two Google Drive services you selected in step 10.
output image

23 Success.

output image

No desktop.

If your Raspberry Pi does not have a desktop (OS Lite), you can not access your Google account via a browser.
The workaround is to use another Raspberry Pi with a browser first and then transfer the OAuth information to your desktop-less Rpi.

$ gdrive account list
$ gdrive account export <YourAccountName>
# on the other Raspberry Pi without browser capacities.
$ gdrive account import <gdrive_export-YourAccountName.tar>

output image

Testing.

Now your gdrive is up and running. You can test it with the $ gdrive files list command.
output image

Credentials: Petter Rasmussen