Aria2+Rclone+云盘挂载Google Drive ( onedrive同理 )

445次阅读
没有评论

共计 5370 个字符,预计需要花费 14 分钟才能阅读完成。

先安装 Aria2 后再进行以下步骤

安装 Rclone (挂载)

yum -y install unzip
curl https://rclone.org/install.sh | sudo bash

配置 Rclone,大致如下

[root@well ~]# rclone config
2018/11/25 09:31:54 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Rats  #随便填,后面要用到
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Box
   \ "box"
 5 / Cache a remote
   \ "cache"
 6 / Dropbox
   \ "dropbox"
 7 / Encrypt/Decrypt a remote
   \ "crypt"
 8 / FTP Connection
   \ "ftp"
 9 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
10 / Google Drive
   \ "drive"
11 / Hubic
   \ "hubic"
12 / Local Disk
   \ "local"
13 / Microsoft Azure Blob Storage
   \ "azureblob"
14 / Microsoft OneDrive
   \ "onedrive"
15 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
16 / Pcloud
   \ "pcloud"
17 / QingCloud Object Storage
   \ "qingstor"
18 / SSH/SFTP Connection
   \ "sftp"
19 / Webdav
   \ "webdav"
20 / Yandex Disk
   \ "yandex"
21 / http Connection
   \ "http"
Storage> 10  #选择 10,Google Drive
Google Application Client Id - leave blank normally.
client_id>  #留空
Google Application Client Secret - leave blank normally.
client_secret>  #留空
Service Account Credentials JSON file path - needed only if you want use SA instead of interactive login.
service_account_file>
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> n  #选择 n
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth....  #复制到浏览器打开,获取验证码
Log in and authorize rclone for access
Enter verification code>  #填入上面获取到的验证码
Configure this as a team drive?
y) Yes
n) No
y/n> y  #选择 y
Fetching team drive list...
No team drives found in your account--------------------
[Rats]
client_id =
client_secret =
service_account_file =
token = {"access_token":" 你的 "}
team_drive =
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  #选择 y
Current remotes:

Name                 Type
====                 ====
Rats                 drive

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  #选择 q 退出

#最后输入 Name
请输入你刚刚输入的 Name:

完成后挂载为磁盘

# 新建本地文件夹,路径自己定
mkdir -p /data/GoogleDrive

# 挂载为磁盘
rclone mount codesofun:share /data/GoogleDrive --allow-other --allow-non-empty --vfs-cache-mode writes &

#格式为[name]:[google drive dir] [mount dir]
#[name]就是配置文件是输入的 name,例如我的就是 ct
#[google drive dir] 这个是谷歌云盘的目录,根目录的花直接空开就可以了
#[mount dir]就是本地挂载位置,/data/GoogleDrive

Fatal error: failed to mount FUSE fs: fusermount: exec: “fusermount”: executable file not found in $PATH

没有安装 fuse , 自行安装就可以了 yum -y install fuse

挂载完成后看看效果

[root@well ~]# df -h
Filesystem       Size  Used Avail Use% Mounted on
/dev/vda1         20G  1.3G   15G   7% /
devtmpfs         234M     0  234M   0% /dev
tmpfs            244M     0  244M   0% /dev/shm
tmpfs            244M  8.5M  236M   4% /run
tmpfs            244M     0  244M   0% /sys/fs/cgroup
tmpfs             49M     0   49M   0% /run/user/0
codesofun:share   15G  3.8G   12G  26% /data/GoogleDrive

设置开机自动挂载谷歌云

wget https://blog.codesofun.com/scripts/rcloned && vim rcloned
#然后修改文件内如下内容
NAME=""  #[name]
REMOTE=''  #[google drive dir]
LOCAL=''  #[mount dir]

设置自启动

mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
vim /etc/rc.d/rc.local #在末尾加入 bash /etc/init.d/rcloned start
chmod +x /etc/rc.d/rc.local

bash /etc/init.d/rcloned status

这时候可以在 VPS 上测试一下了!

cd /data/GoogleDrive
touch codesofun.txt

在 Google Drive 刷新看看

编写 googledrive 的自动上传脚本

这个时候我们使用 aria2 去下载文件,下载成功后触发一个脚本让它将文件移动到 Rclone 同步的文件夹内,这样在 Google Drive 就会自动有这个文件啦,实现自动上传并删除原文件。
新建一个名为 rcloneupload.sh 的脚本。

vim /root/rcloneupload.sh
#!/bin/bash

GID="$1";
FileNum="$2";
File="$3";
MinSize="5"  #限制最低上传大小,默认 5k
MaxSize="157286400"  #限制最高文件大小(单位 k),默认 15G
RemoteDIR="/data/GoogleDrive/";  #rclone 挂载的本地文件夹,最后面保留 /
LocalDIR="/data/Download/";  #Aria2 下载目录,最后面保留 /

if [[-z $(echo "$FileNum" |grep -o '[0-9]*' |head -n1) ]]; then FileNum='0'; fi
if [["$FileNum" -le '0']]; then exit 0; fi
if [["$#" != '3']]; then exit 0; fi

function LoadFile(){
  IFS_BAK=$IFS
  IFS=$'\n'
  if [[! -d "$LocalDIR"]]; then return; fi
  if [[-e "$File"]]; then
    FileLoad="${File/#$LocalDIR}"
    while true
      do
        if [["$FileLoad" == '/']]; then return; fi
        echo "$FileLoad" |grep -q '/';
        if [["$?" == "0"]]; then
          FileLoad=$(dirname "$FileLoad");
        else
          break;
        fi;
      done;
    if [["$FileLoad" == "$LocalDIR"]]; then return; fi
    EXEC="$(command -v mv)"
    if [[-z "$EXEC"]]; then return; fi
    Option=" -f";
    cd "$LocalDIR";
    if [[-e "$FileLoad"]]; then
      ItemSize=$(du -s "$FileLoad" |cut -f1 |grep -o '[0-9]*' |head -n1)
      if [[-z "$ItemSize"]]; then return; fi
      if [["$ItemSize" -le "$MinSize"]]; then
        echo -ne "\033[33m$FileLoad \033[0mtoo small to spik.\n";
        return;
      fi
      if [["$ItemSize" -ge "$MaxSize"]]; then
        echo -ne "\033[33m$FileLoad \033[0mtoo large to spik.\n";
        return;
      fi
      eval "${EXEC}${Option}" \'"${FileLoad}"\' "${RemoteDIR}";
      if [[$? == '0']]; then
        rm -rf "$FileLoad";
      fi
    fi
  fi
  IFS=$IFS_BAK
}
LoadFile;

保存后给予执行权限

chmod +x /root/rcloneupload.sh

然后再到 Aria2 配置文件中加上一行 on-download-complete=/root/rcloneupload.sh 即可,后面为脚本的路径。重启 Aria2 生效。

vim /root/.aria2/aria2.conf
on-download-complete=/root/rcloneupload.sh
/etc/init.d/aria2 restart

以上是 google drive 中的配置 (原理相似),
现在开始配 onedrive 配置:

vim /root/upload2one.sh
#!/bin/bash
path=$3
downloadpath='/Download'
if [$2 -eq 0]
        then
                exit 0
fi
while true; do  #提取下载文件根路径,如把 /root/downloads/a/b/c/d.jpg 变成 /root/downloads/a
filepath=$path
path=${path%/*};
if ["$path" = "$downloadpath"] && [$2 -eq 1]  #如果下载的是单个文件
    then
    /www/server/php/56/bin/php /www/wwwroot/ 你的 ip 或者域名 /one.php upload:file "$filepath" /upload/
    rm -rf "$filepath"
    exit 0
elif ["$path" = "$downloadpath"]   #文件夹
    then
    /www/server/php/56/bin/php /www/wwwroot/ 你的 ip 或者域名 /one.php upload:folder "$filepath"/ /upload/"${filepath##*/}"/
    rm -rf "$filepath"/
    exit 0
fi
done

记得把文中 ” 你的 ip 或者域名 ” 换成你的 one.php 文件在 VPS 中的正确路径(和网站存放目录相同)
修改 aria2 配置文件

去编辑 vim /root/.aria2/.aria2.conf

同时最后加上一句:下载完成后执行自动上传脚本。

on-download-complete=/root/upload2one.sh

保存
然后再连上 ssh:RcloneRclone

chmod +x /root/upload2one.sh

赋予权限后,

./aria2.sh

输入 6
重启 aria2

正文完
 
alecctv
版权声明:本站原创文章,由 alecctv 2019-05-25发表,共计5370字。
转载说明:除特殊说明外本站文章皆由ooly.cc发布,转载请注明出处。
评论(没有评论)
验证码