声明
自己Google Workspace
里面存了挺多东西的,最近需要一个Serverless
平台搭建的Google Drive
分享平台,同时支持使用SA
账号进行授权(因为Google Drive
限制单号每天750G
的流量传输),最后找到了gdir
。
该项目使用的本地/VPS环境
仅用于配置gdir
,配置完成之后正常使用gdir
便不需要了,要进行更改用户权限等操作时需要。
理论来说备份设置只需要把整个gdir
项目文件夹打包即可。
感谢gdir项目以及HE-SB大佬的教程
可能有人要问既然都有教程了为什么我还要自己再写一个呢?原因有二
1.大佬的原项目有部分代码更改没有同步+我的一个兄弟不是很会英语,只能自己汉化一下了(其实涉及的文件部分也不多,感兴趣的可以自己去 dist/static/app.js 里面修改)
2.自己搭gdir的时候踩了一些坑,想着万一以后重新搭的时候又出现这些问题岂不是直接寄,于是这个教程就出现了。
gdir
特点:
1.支持多用户权限控制。
2.支持SA
账号从而能够突破Google
官方的限制
3.可以进行搜索
4.各种信息丢gist
上面加密存储的
最后贴一贴自己稍微改了改的github链接
废话不多说,咱直接开干!
1.前置需求
(1) 环境依赖
脚本自动安装环境依赖
gdir
项目作者写了个一键脚本来方便大家安装本节的【Git】和【Golang toolchain】这两部分,适用于 CentOS,Debian,Ubuntu,ArchLinux,MacOS
系统,只需执行下面这一条命令即可:
eval "$(curl -Lso- https://gist.githubusercontent.com/rixtox/05d5ecd0b067f055cddda436efc9035f/raw/gdir-env-setup.sh)"
如果大佬的脚本被删了的话就用我的备份脚本吧。
我的备份
eval "$(curl -Lso- https://raw.githubusercontent.com/Tea1me/gdir/master/env-install.sh)"
如果脚本自动安装没有问题的话就直接跳到下一节吧,不然还是手动安装吧(
手动安装环境依赖
Git
apt install -y git
或
yum install -y git
Golang toolchain
建议按照官方文档教程来进行安装,或者按照HE-SB大佬的教程来走,此处不再赘述。
(2) SA账号
获取SA
账号网上已经有太多教程此处也不再赘述,下述教程以把SA
账号放到/root/sa
文件夹来举例,这个文件夹可以不同。
如果你要使用个人账号的授权文件,那么请自行搜索如何获取。
(3) CF的Global API Key
打开Cloudflare的API网页,单击下方Global API Key
旁的view
即可查看(需要输入密码),以下以Global API Key
为avava
举例。
(4) GitHub 的 Personal access token
此处需要生成两个Token,Token A用于Github登录验证,Token B用于gdir
打开github的Token页面,点击右上角的Generate new token
Token A
我建议把权限全部选中。Token B
的Note
最好写一个能让自己认出是gdir
项目的备注,下方的权限只需gist
即可。
2.开始配置gdir
clone
项目(原版)
git clone https://github.com/workerindex/gdir.git
我的改版
git clone https://github.com/Tea1me/gdir.git
clone
完成之后进入gdir
目录
cd gdir && go run ./tools/setup
下方为部署过程中的情况
_ _
__ _ __| (_)_ _
/ _` / _` | | '_|
\__, \__,_|_|_|
|___/
//此处输入CF的邮箱
Your Cloudflare login Email:
Please visit https://dash.cloudflare.com/profile/api-tokens and get
//此处输入之前获取的Global API Key
your Global API Key:
//这里我建议新建(指选0)worker,因为我之前利用现有的出现过问题。
Your Cloudflare subdomain is: XXX.workers.dev
Your available Cloudflare Workers:
(1) a
(0) Create a new Worker (Default)
Choose one of above:
//这里输入你想要的Worker名字
Naming rule:
start with a letter
end with a letter or digit
include only letters, digits, underscore, and hyphen
be 63 characters or less
Please enter a name for your new Worker:
//下方输入之前获取的Token B
Please visit https://github.com/settings/tokens and generate a new
token with "gist" scope:
//下方选择是存放SA账号的gist位置,默认新建
Specify how you want to configure your Accounts Gist:
(1) Create a new Gist (default)
(2) Enter an existing Gist URL / ID
Please enter your choice:
//下方选择是存放用户信息的gist位置,默认新建
Specify how you want to configure your Users Gist:
(1) Create a new Gist (default)
(2) Enter an existing Gist URL / ID
Please enter your choice:
//下方是存放静态页面文件的gist位置,默认新建
Specify how you want to configure your Static Gist:
(1) Create a new Gist (default)
(2) Enter an existing Gist URL / ID
Please enter your choice:
//下方是gdir的密钥,默认随机生成
Specify how you want to configure your gdir secret key:
(1) Generate secure random value (default)
(2) Enter your own secret key (not recommended)
Please enter your choice:
//下方是更换SA的时间间隔,单位为秒,默认60秒
Please enter account candidates rotations interval (default 60):
//下方是每次更换SA账号时更换的SA账号数,默认为10个
Please enter account candidates size (default 10):
//下方输入SA账号所在的目录
Please follow https://github.com/xyou365/AutoRclone to generate
Accounts JSON directory:
.
.
.
.
.
.
//下方输入管理员账号的用户名
Add an admin user...
Please enter your admin user name:
//下方输入管理员账号的密码
Please enter your admin user password:
//下方选择连接Github的方式,如果需要频繁修改我推荐第二种(我自己也是),为了演示方便选择第一种,第二种方式连接Github网上也有教程。
//下方为SA账号的存放方式,默认HTTPS
Saving user to users/XZZZZZZZZZZZZ ...
Initializing Git repo in accounts...
Initialized empty Git repository in /root/gdir/accounts/.git/
Specify which protocol you want to configure your accounts Git repo:
(1) HTTPS (default)
(2) SSH (needs SSH key setup with GitHub)
Please enter your choice:
create mode XXX
//下方输入github的用户名,如我的为Tea1me
Username for 'https://gist.github.com':
//下方输入之前生成的Token A,用于登录验证
Password for 'https://Tea1me@gist.github.com':
.
.
.
Initializing Git repo in users...
Initialized empty Git repository in /root/gdir/users/.git/
//下方为用户账号的存放方式,默认HTTPS
Specify which protocol you want to configure your users Git repo:
(1) HTTPS (default)
(2) SSH (needs SSH key setup with GitHub)
Please enter your choice:
Deploying users to Gist...
//下方输入github的用户名,如我的为Tea1me
Username for 'https://gist.github.com':
//下方输入之前生成的Token A,用于登录验证
Password for 'https://Tea1me@gist.github.com':
.
.
.
//下方为网页静态的存放方式,默认HTTPS
Initialized empty Git repository in /root/gdir/static/.git/
Specify which protocol you want to configure your static Git repo:
(1) HTTPS (default)
(2) SSH (needs SSH key setup with GitHub)
Please enter your choice:
Deploying static to Gist...
//下方输入github的用户名,如我的为Tea1me
Username for 'https://gist.github.com':
//下方输入之前生成的Token A,用于登录验证
Password for 'https://Tea1me@gist.github.com':
.
.
.
Deploying Cloudflare Worker 111...
Your gdir is now live at https://111.XXX.workers.dev
Check here to create custom routes with your own domain names:
//进入Workers进行管理即可
https://developers.cloudflare.com/workers/about/routes/
3. 用户以及权限管理
该部分内容完全Copy自HE-SB大佬
在gdir
目录运行
刚配置好的管理员用户是可以显示所有有权限的团队盘的,会有一些不便,如果只想显示其中某一个或某几个盘,可以使用白名单模式,既可以修改现有用户的权限也可以新增用户来设置权限:
go run ./tools/adduser
Loading existing config from config.json
//下方输入需要更改/新建的用户名以及密码(如果是新建用户需要输入密码,非新建就不用了)
Username: test
Password: test
The user currently has global access to all drives.
//下方为想给予该用户盘的权限
1为按照当前权限不动
2为修改为白名单模式
3为修改为黑名单模式
以白名单模式举例
Please specify what do you want to do with it:
(1) Confirm (default)
(2) Convert to white-list access control list
(3) Convert to black-list access control list
Please enter your choice:
//下方输入该用户可访问的团队盘ID,如有多个用英文逗号隔开
(Use comma to separate between drive IDs.)
Enter white-list access control list of drives:
//确认下想展示的盘,在此处可以新增盘,移除已有的盘,
使用新的白名单列表来替换当前的,将列表转换为黑名单,
或关闭该用户的访问权限,输入1确认
The user currently has following drives in its white-list access list:
(1) XXXX
Please specify what do you want to do with it:
(1) Confirm (default)
(2) Append drives to the list
(3) Remove drives from the list
(4) Replace with a new list of drives
(5) Convert to black-list access control
(6) Disable access control on the user
Please enter your choice:
Saving user to users/XXXX ...
Deploying users to Gist...
//下方输入Github的用户以及Token A
Username for 'https://gist.github.com':
Password for 'https://Tea1me@gist.github.com':
Counting objects: 3, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 459 bytes | 459.00 KiB/s, done.
.
.
.
All done!
至此,用户/权限修改完成。
3.注意事项
**该部分也差不多抄自HE-SB作者的教程 **
1.配置时服务器所使用的用户权限问题
gdir
项目作者建议使用普通用户而非root
用户来配置gdir
,且项目 issues
中有位用户提到使用root
用户来配置,产生了很多报错,最后切换为普通用户配置就正常了(Failed to run setup · Issue #1 · workerindex/gdir)
。但我以及原教程作者经过本文的方法配置,全程使用root
用户也未见任何异常,推测是Node.js
或Golang
安装方法与本文不同导致的权限问题。
2.项目备份问题
VPS 或本地机器只是用来生成 CF Worker 的配置文件用,配置好后部署和数据传输都是走 CF。
接上条,如果确定以后不用再修改配置的话,本地的项目文件夹可以删掉;
但是不建议这样做,项目文件夹下存放有配置文件,Gist 中存放的只是加密后的内容,如果删了本地的项目文件夹,日后想要对用户进行增删改操作就很麻烦(你可能需要手动删掉旧的 Worker 和 Gist 项目,然后 clone gdir 项目重新配置);
部署成功后可以备份下项目文件夹下的 config.json 文件,迁移或重装了机器之后,如果要对已经部署好的 gdir 进行修改(比如添加用户,或修改目录可见范围等),只要先安装好依赖(Git 和 Golang),再重新将项目 clone 下来,将备份好的 config.json 放进项目文件夹内,执行 go run ./tools/adduser 就好了,不用从头开始部署到新的 Worker;
在项目路径下执行 git pull 来更新项目,如果确定自己的操作没问题,但是仍然报错的话,可以先更新试试看;
想到了再写,遇到问题欢迎在文章下方留言或去项目仓库给作者提Issues
,这样可以帮到更多的人。