ubuntu 18.10 安裝 rclone onedrive

安裝Rclone

Rclone網站︰https://rclone.org/

這邊推薦使用官方腳本安裝

1
curl https://rclone.org/install.sh | sudo bash

如果使用snap安裝可能會出現一些問題

新增OneDrive到Rclone

如果rclone有安裝成功,輸入rclone config可以看到以下內容
現在要新增一個設定,所以輸入n後按Enter

1
2
3
4
5
6
hsuan@ubuntu:~$ rclone config
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n

之後輸入設定的名字,這邊以OneDrive為範例

1
name> OneDrive

按下Enter之後,會出現目前rclone所支援的網路硬碟列表, 您需要通過輸入相應的數字來選擇Microsoft OneDrive選項(現在為18,但將來可能會更改):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
1 / A stackable unification remote, which can appear to merge the contents of several remotes
\ "union"
2 / Alias for a existing remote
\ "alias"
3 / Amazon Drive
\ "amazon cloud drive"
4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
\ "s3"
5 / Backblaze B2
\ "b2"
6 / Box
\ "box"
7 / Cache a remote
\ "cache"
8 / Dropbox
\ "dropbox"
9 / Encrypt/Decrypt a remote
\ "crypt"
10 / FTP Connection
\ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
\ "google cloud storage"
12 / Google Drive
\ "drive"
13 / Hubic
\ "hubic"
14 / JottaCloud
\ "jottacloud"
15 / Local Disk
\ "local"
16 / Mega
\ "mega"
17 / Microsoft Azure Blob Storage
\ "azureblob"
18 / Microsoft OneDrive
\ "onedrive"
19 / OpenDrive
\ "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ "swift"
21 / Pcloud
\ "pcloud"
22 / QingCloud Object Storage
\ "qingstor"
23 / SSH/SFTP Connection
\ "sftp"
24 / Webdav
\ "webdav"
25 / Yandex Disk
\ "yandex"
26 / http Connection
\ "http"
Storage> 18

接下來兩個步驟,按Enter鍵就好,不用輸入任何信息,因為無需輸入Microsoft App Client ID或Secret:

1
2
3
4
5
6
7
8
Microsoft App Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>

是否要編輯進階配置,這邊輸入n

1
2
3
4
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n

是否使用自動配置,這邊如果是是用圖形界面的話可以輸入y,使用文字界面的話就輸入n手動提供權限

1
2
3
4
5
6
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> y

在預設瀏覽器會打開一個新的分頁,請登入OneDrive帳號,並允許Rclone的訪問權限。
Rclone會在本機的端口53682運行web服務,以取得身份驗證token。如果有防火牆可能要暫時取消阻擋。

選擇OneDrive的帳戶類型,輸入1,以對應OneDrive的Persional或Business帳戶。

1
2
3
4
5
6
7
8
9
10
11
12
Choose a number from below, or type in an existing value
1 / OneDrive Personal or Business
\ "onedrive"
2 / Root Sharepoint site
\ "sharepoint"
3 / Type in driveID
\ "driveid"
4 / Type in SiteID
\ "siteid"
5 / Search a Sharepoint site
\ "search"
Your choice> 1

接下來會列出該帳號所擁有的Onedrive列表,請根據需求做選擇。

1
2
3
Found 1 drives, please select the one you want to use:
0: (personal) id=9b42f86057109d0a
Chose drive to use:> 0

之後會看到以下文字,輸入y在按Enter繼續

1
2
3
4
5
Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=9b42f86057109d0a
Is that okay?
y) Yes
n) No
y/n> y

確認設定是否正確(token請勿提供給他人),正確請輸入y

1
2
3
4
5
6
7
8
9
10
11
--------------------
[OneDrive]
type = onedrive
token = {"access_token":"EwCAA8l6BAAURSN/FHlDW5xN7VtKKzxfQSG7KP8xH","expiry":"2019-04-16T06:15:59.363270812+08:00"}
drive_id = 9b42f86057109d0a
drive_type = personal
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

最後輸入q離開rclone設定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Current remotes:

Name Type
==== ====
OneDrive onedrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

掛載OneDrive目錄

建議在家目錄中建立一個OneDrive資料家

1
mkdir OneDrive

要使用Rclone掛載Microsoft OneDrive,請使用以下命令:

1
rclone --vfs-cache-mode writes mount OneDrive: ~/OneDrive

其中Onedrive是在Rclone設定的名稱,~/OneDrive是本機所要掛載的資料夾

根據Rclone的文件說明,如果掛載時沒有使用--vfs-cache-mode ,許多程序無法使用Rclone所掛載的檔案。

開機時自動掛載OneDrive

測試失敗
使用初始應用程式→加入

名稱(N):

1
Rclone OneDrive Mount

指令(M):

1
sh -c "rclone --vfs-cache-mode writes mount OneDrive : ~/OneDrive"

參考資料

Rclone:玩轉Google Drive & One Drive
How To Mount OneDrive In Linux Using Rclone (Supports Business And Personal Accounts)
在Debian/Ubuntu上使用rclone挂载OneDrive网盘