CentOS 7 使用 google-drive-ocamlfuse 掛載 Google Drive 雲端硬碟

在 CentOS 7 命令列介面 (CLI) 使用 google-drive-ocamlfuse 來自動掛載 Google Drive 雲端硬碟,並說明如何申請 Google Drive API 來允許 google-drive-ocamlfuse (外部軟體) 使用。
安裝
相關軟體
yum install -y wget git
yum install -y hg
yum install -y sqlite-devel fuse fuse-devel libcurl-devel zlib-devel m4
OPAM
yum install -y ocaml ocamldoc ocaml-camlp4-devel
wget https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh -O - | sh -s /usr/local/bin/
opam init
# ... 以上省略 ...
Do you want OPAM to modify ~/.bash_profile and ~/.ocamlinit?
(default is 'no', use 'f' to name a file other than ~/.bash_profile)
[N/y/f] y
# ... 以下省略 ...
google-drive-ocamlfuse
opam install -y google-drive-ocamlfuse
export DISPLAY=:0.0
source ~/.bash_profile
Google Drive API
瀏覽器開啟 Google Developers Console。
建立與啟用












取得用戶端資訊
取得「用戶端 ID」與「用戶端密碼」。


連結
替換用戶端資訊如下:
- 用戶端 ID:client-ID。
- 用戶端密碼:client-secret。
google-drive-ocamlfuse -headless -label me -id client-ID -secret client-secret
Please, open the following URL in a web browser:
# 使用瀏覽器開啟網址
https://accounts.google.com/o/oauth2/auth?client_id=xxxx-xxxx.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&access_type=offline&approval_prompt=force


# 將上圖取得的授權碼貼上
Please enter the verification code: 4/AADxxxxxoTT_RIPl-pf19QfxxxxxFiJDq8KtuxxxxxbEoj7lD4xxxxx
Access token retrieved correctly.
掛載 Google Drive
建立要掛載的目錄並掛載:
mkdir google-drive
google-drive-ocamlfuse -label me google-drive/
確認是否正確掛載:
df -h
檔案系統 容量 已用 可用 已用% 掛載點
/dev/mapper/centos-root 6.2G 1.9G 4.4G 30% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 1014M 125M 890M 13% /boot
tmpfs 100M 0 100M 0% /run/user/0
google-drive-ocamlfuse 15G 11G 4.3G 72% /root/google-drive
查看掛載的檔案:
ll google-drive/
總計 6721
-rw-r--r--. 1 root root 1789331 5月 25 2017 20170525_091206.jpg
-rw-r--r--. 1 root root 2401614 5月 25 2017 20170525_091232.jpg
drwxr-xr-x. 2 root root 4096 5月 4 2015 code
-r--r--r--. 1 root root 10700 10月 30 2017 intro.htm.odt
drwxr-xr-x. 2 root root 4096 2月 16 2015 smalljacky-notepad
drwxr-xr-x. 2 root root 4096 2月 28 2017 UpdraftPlus
drwxr-xr-x. 2 root root 4096 5月 14 2015 個人
drwxr-xr-x. 2 root root 4096 11月 8 2015 暫存
drwxr-xr-x. 2 root root 4096 10月 16 2015 產業人才投資
drwxr-xr-x. 2 root root 4096 11月 21 2016 英文學習
設定開機自動掛載:
echo -e "\n# Auto Google Drive\ngoogle-drive-ocamlfuse -label me google-drive/" >> ~/.bash_profile
參考

本著作係採用創用 CC 姓名標示-相同方式分享 3.0 台灣 授權條款授權.