在 VPS 中使用 RClone 挂载 OneDrive 和 SharePoint

SharePoint 原本是用来创建网站,与他人共享文档和信息用途的东西。

不过鉴于其巨大的储存空间,我们可以拿来搭建列表程序,或者 RClone 挂载后当做存储盘使用(≖ᴗ≖)✧

这里以 【同济校友邮箱附带的世纪互联账号】 举例,使用 RClone 分别挂载 OneDrive 和 SharePoint。

搭建环境:
Oracle 测试机 1C8G
Debian 10 (4.19.0-16-amd64)

先用 Windows 配置一下 RClone,因为 VPS 不方便登录账号授权获取 Token。。。

RClone Windowns 64bit下载链接

解压至一个没有中文的路径,然后打开 CMD (命令提示符);
将解压后的文件中的 rclone.exe 拖入 CMD 窗口中,并在后面空格一下再补充输入 config

正片开始

本地 Windows 中的挂载

以下显示的内容有省略,留意输入的命令即可。

rclone config

n -> 创建新配置
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n

Test -> 自定义名字

name> Test

26 -> 选择 OneDrive (可能随着版本变化而发生改变,以选择OneDrive为准)

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
.
.
26 / Microsoft OneDrive
\ "onedrive"
.
.
Storage> 26

abc123ABC -> 输入你创建的应用的客户端ID | client_id6

** See help for onedrive backend at: https://rclone.org/onedrive/ **
OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> abc123ABC

def456DEF -> 输入你创建的应用的 密钥 |client_secret

OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> def456DEF

4 -> 选择世纪互联版

Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
  \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
region> 4

n -> 默认即可

Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n

y -> 此处请确认你的应用回调地址设置为 http://localhost:53682/

Remote config
Make sure your Redirect URL is set to "http://localhost:53682/" in your custom config.
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> y

如果此时你是在一台 VPS 上进行的配置,到这大概率就卡壳了。
选 Y ,弹不出浏览器去登录,
选 N ,提供的命令又没法跳转到世纪互联去授权,
所以建议大家先在 Windows 上进行配置,然后再导入到 VPS 中。

这里如果有什么好的解决方案,请评论告诉我,谢谢~

If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=LsjWfsfpYCdkYMRxZVx6qw
Log in and authorize rclone for access
Waiting for code...

到这会弹出默认浏览器让你进行登录,使用需要被挂载的账号进行登录授权即可。
(我记得还会让选择啥啥啥代替IT组织授权,选其他会报错。报错之后重试一下就行了)

此处可以复制给出的链接到浏览器隐身模式中打开,登录你需要挂载 RClone 的世纪互联账号登录并授权。以免使用其他账号错误授权。

授权成功后,CMD 界面会提示 Got code,继续...

挂载 OneDrive 则选择 1 | 挂载 SharePoint 则选择 4

Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)
   \ "url"
 4 / Search for a Sharepoint site
   \ "search"
 5 / Type in driveID (advanced)
   \ "driveid"
 6 / Type in SiteID (advanced)
   \ "siteid"
 7 / Sharepoint server-relative path (advanced, e.g. /teams/hr)
   \ "path"
Your choice> 1 or 4

以下根据你挂载的类型不同而不同

选择挂载 OneDrive

Your choice> 1

OneDrive 只有一块盘,列出的 ID 中选 0 即可

Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=你的 OneDrive ID
Chose drive to use:> 0

没问题,y 继续前进

Found drive 'root' of type 'business', URL: 你的 OneDrive URL
Is that okay?
y) Yes (default)
n) No
y/n> y

选择挂载 SharePoint

Your choice> 4

在这里搜索你创建的 SharePoint 站点名称

What to search for> spTest

搜索到你的站点后,选择对应序号即可

Found 1 sites, please select the one you want to use:
0: spTest (你的站点 URL) id=你的站点 site_id
Chose drive to use:> 0
Found 1 drives, please select the one you want to use:
0: 文档 (documentLibrary) id= 又是一个 ID
Chose drive to use:> 0    // SharePoint 文件默认储存在 '文档' 文件夹内,也是挂载的根目录

没问题,y 继续前进

Found drive 'root' of type 'documentLibrary', URL: https://universitytongji.sharepoint.cn/teams/syoukor/Shared%20Documents
Is that okay?
y) Yes (default)
n) No
y/n> y

获取 token

通过上一轮的挂载后,CMD 界面中将返回一大串参数,我们需要从中提取出需要的东西。

[Test]
type = onedrive
client_id = 你的 client id
client_secret = 你的 client secret
region = cn
token = {"access_token":"举例*****内容","token_type":"Bearer","refresh_token":"举例*****内容","expiry":"2021-05-03T17:10:33.0233333+08:00"}
drive_id = 你的 drive id
drive_type = 挂载 OneDrive -> business | SharePoint -> documentLibrary

token = {...}
这一串里 花括号的内容 便是我们需要的东西,请将它 完整复制
包括花括号!

例:

{"access_token":"abcdef","token_type":"Bearer","refresh_token":"abcdef","expiry":"2021-05-03T17:10:33.0233333+08:00"}

Tips:请不要泄露你的 client_idclient_secret 以及上面的 token

VPS 中的挂载

VPS 中的挂载与 Windows 无异,只是一步之差。

首先也要安装RClone

使用官方提供的一键安装脚本安装 RClone
apt install curl sudo -y && curl https://rclone.org/install.sh | sudo bash

然后重复上文中 在Win中挂载 的内容。
直到...

Remote config
Make sure your Redirect URL is set to "http://localhost:53682/" in your     custom config.
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> n    // 此处有所不同!!!

不同之处在于到了这一步选择 n
然后填入你获取到的 token

result> {"access_token":"abcdef","token_type":"Bearer","refresh_token":"abcdef","expiry":"2021-05-03T17:10:33.0233333+08:00"}

处理完这里,后续步骤与在 Windows 中挂载方式无异。