コマンドでのGoogleDriveの使用方法

このページでは主にUbuntu環境において,コマンドラインでのGoogleDriveのマウント方法を紹介する.

google-drive-ocamlfuseのインストール

sudo add-apt-repository ppa:alessandro-strada/ppa
sudo apt-get update
sudo apt-get install google-drive-ocamlfuse
google-drive-ocamlfuse
mkdir ~/GoogleDrive
google-drive-ocamlfuse ~/GoogleDrive

Auto Mount

USERNAMEは適宜変更する.

mount用bashファイル作成

mkdir ~/bin
sudo vim ~/bin/google-drive-ocamlfuse-start.sh

~/bin/google-drive-ocamlfuse-start.shに次の内容を記述する.

#! /usr/bin/bash

directory=/home/USERNAME/GoogleDrive

if [ -n "$(ls $directory)" ]; then
       fusermount -uz $directory
fi

google-drive-ocamlfuse $directory
sudo chmod 777 ~/bin/google-drive-ocamlfuse-start.sh

systemctlのUnit作成

sudo vim /etc/systemd/system/google-drive-ocamlfuse-start.service

/etc/systemd/system/google-drive-ocamlfuse-start.serviceに次の内容を記述する.

[Unit]
Description=Auto Mount Google Drive
Documentation=
After=networking.service

[Service]
Type=oneshot
User=USERNAME
Group=USERNAME
TimeoutStartSec=0
#Restart=on-success
#ExecStartPre=
ExecStart=/home/USERNAME/bin/google-drive-ocamlfuse-start.sh
#SyslogIdentifier=Diskutilization
#ExecStop=
RemainAfterExit=yes

[Install]
WantedBy=default.target
sudo chmod 777 /etc/systemd/system/google-drive-ocamlfuse-start.service
sudo systemctl daemon-reload
sudo systemctl start google-drive-ocamlfuse-start.service
sudo systemctl enable google-drive-ocamlfuse-start.service
Updated : 2024/04/29 00:39:50