.. google_drive: Google Drive ============ To integrate Google Drive with a Debian Linux instance running on Google Cloud Platform (GCP) use a tool called ``google-drive-ocamlfuse``. This tool allows to mount a Google Drive as a filesystem on the Linux instance. 1. Install ``google-drive-ocamlfuse`` ------------------------------------- Install required libraries for ``google-drive-ocamlfuse``: .. code:: python sudo apt-get install software-properties-common sudo apt-get install python3-launchpadlib Add the repository for ``google-drive-ocamlfuse``: .. code:: sudo add-apt-repository ppa:alessandro-strada/ppa The repository should contain the following 2 lines. Edit the repository: .. code:: sudo nano /etc/apt/sources.list.d/alessandro-strada-ubuntu-ppa-bookworm.list If necessary, add the following 2 lines in that repository: .. code:: deb http://ppa.launchpad.net/alessandro-strada/ppa/ubuntu xenial main deb-src http://ppa.launchpad.net/alessandro-strada/ppa/ubuntu xenial main If necessary, download key from keyservers directly into the trusted set of keys (see `Install 'google-drive-ocamlfuse' on Debian Stretch & Buster `__): .. code:: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AD5F235DF639B041 Install ``google-drive-ocamlfuse``: .. code:: sudo apt install google-drive-ocamlfuse | .. _chapter_authenticate_google-drive-ocamlfuse: 2. Authenticate ``google-drive-ocamlfuse`` with the Google Account ------------------------------------------------------------------ To authenticate ``google-drive-ocamlfuse`` without using a browser, use a headless authentication method provided by Google. a) Generate OAuth2 Credentials: - Go to the Google Cloud Console: https://console.cloud.google.com/. - Create a new project or select an existing one. - Navigate to the "APIs & Services" > "Credentials" section. - Click on "Create credentials" and select "OAuth client ID". - Choose "Desktop app" as the application type. - Click "Create" and note down the generated Client ID and Client Secret. b) Run the Authentication Command: - Open a terminal on your VM. - Run the following command to start the authentication process: .. code:: google-drive-ocamlfuse -headless -id -secret Replace ```` and ```` with the values obtained from the Google Cloud Console. - Example: .. code:: google-drive-ocamlfuse -headless -id 701070352033-7j2jmeotq77mtkg60dsc9q6hris4pvj3.apps.googleusercontent.com -secret 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 c) Follow the Authentication Flow: - The command will provide a URL and a verification code. - Copy the URL and open it in a browser on your local machine. - Sign in with your Google account if prompted and grant permission to the application. - After granting permission, you'll receive a verification code. d) Enter the Verification Code: - Copy the verification code provided by Google. - Paste the code into the terminal where the ``google-drive-ocamlfuse`` command is running. - Press Enter. e) Complete Authentication: - Once the verification code is entered, ``google-drive-ocamlfuse`` should complete the authentication process. - You should see a message indicating successful authentication. | 3. Set Google Drive API ----------------------- Set `Google Drive API `__ in the Google Cloud account for setting the API. | 4. Set mounting directory ------------------------- Create a directory where to mount the Google Drive and then mount it using google-drive-ocamlfuse: .. code:: cd /usr/local/logistics sudo mkdir google-drive Fix Permission issues if happened: .. code:: sudo chown $USER:$USER /usr/local/logistics/google-drive sudo chmod 777 /usr/local/logistics/google-drive | 5. Mount and umount Google Drive -------------------------------- Mount Google Drive: .. code:: google-drive-ocamlfuse /usr/local/logistics/google-drive Unmount Google Drive: .. code:: fusermount -u /usr/local/logistics/google-drive | 6. Mount automatically with crontab ----------------------------------- a) As a prerequisite allow option ``user_allow_other`` in ``fuse``, so that read/write access works on Google Drive: .. code:: sudo nano /etc/fuse.conf Set the following parameter in ``fuse.conf``: .. code:: # Allow non-root users to specify the allow_other or allow_root mount options. user_allow_other b) To mount Google Drive automatically on system boot, add a line to the crontab file: .. code:: crontab -e Add the following line to the end of the file with the path to the mount point: .. code:: # Mount google-drive with google-drive-ocamlfuse: @reboot /usr/bin/google-drive-ocamlfuse -label default -o allow_other -verbose /usr/local/logistics/google-drive Now, the Google Drive should be mounted automatically on system boot and persist through reboots.