1、安装Aria2
这里一切从简,直接采用大佬的一键安装脚本,安装过程不再赘述
wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/aria2.sh && chmod +x aria2.sh && bash aria2.sh
安装Aria2以后根据自己的实际情况修改Aria2的配置文件,一般修改下载目录和RPC密码
即可,如果出现下载完成以后下载目录内有同名的.aria2
文件,可以将配置文件中的如下部分设置为false
以后重启Aria2
PS:较新的版本开启后会在任务完成后依然保留.aria2文件
force-save=false
2、部署AriaNG
AriaNG为静态文件,本文采用宝塔面板直接新建静态网站。域名解析等问题不再赘述。
完成以后打开域名,点击左侧的AriaNG设置
,在右侧上部选择RPC
进行相关设置,若您的AriaNG与Aira2在统一服务器上只需输入RPC密码即可。我这里AriaNG与Aria2并不在同一服务器上,因此需要重新填写参数。
完成后可以看到左侧的Aria2状态
为绿色-已连接
现在可以新建个下载人物测试一下啦
这个步骤应该是整个过程中简单一步了
3、 部署自动上传Onedrive工具
3.1 安装Onedrive自动上传工具
既然是一切从简,这里我们依然采用大佬的一键脚本
wget --no-check-certificate -q -O /tmp/OneDrive.sh "https://raw.githubusercontent.com/0oVicero0/OneDrive/master/OneDrive.sh" && bash /tmp/OneDrive.s
3.2 Onedrive账号认证
运行命令onedrive -a
,将返回的网址复制到浏览器打开,再登陆你的OneDrive for Business
账号,登陆成功后复制地址栏中的code的字段
(就是code=
后面至&
前面),粘贴到SSH
客户端里,敲回车键即可。
如果返回以下字段:It seems like we have a refresh token, so we are ready to go
,那就恭喜你,设置成功!
提示:
如果你遇到bash: onedrive: command not found错误,则需要找到/usr/local/etc/OneDrive文件夹,修改onedrive和onedrive-d脚本,在第二行都加上export PATH=/usr/local/bin:$PATH代码,再保存就行了。
3.3 Aria2自动上传
这里需要自己新建一个脚本,内容如下:
#!/bin/bash
GID="$1";
FileNum="$2";
File="$3";
MaxSize="15728640"
RemoteDIR=""; #上传到Onedrive的路径,默认为根目录,如果要上传到指定目录,方法看文章最后面。
LocalDIR="/home/www/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
if [[ $(dirname "$File") == $(readlink -f $LocalDIR) ]]; then
ONEDRIVE="onedrive";
else
ONEDRIVE="onedrive-d";
fi
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
if [[ -n "$RemoteDIR" ]]; then
Option=" -f $RemoteDIR";
else
Option="";
fi
EXEC="$(command -v $ONEDRIVE)";
if [[ -z "$EXEC" ]]; then return; fi
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" -ge "$MaxSize" ]]; then
echo -ne "\033[33m$File \033[0mtoo large to spik.\n";
return;
fi
eval "${EXEC}${Option}" \'"${FileLoad}"\';
if [[ $? == '0' ]]; then
rm -rf "$FileLoad";
fi
fi
fi
IFS=$IFS_BAK
}
LoadFile;
使用
1、使用命令
onedrive --help
#####################################################################
Usage: onedrive [OPTIONS] file1 [file2...]
onedrive-d folder
Options:
-d, --debug Enable debug mode
-a, --authorize Run authorization process
-f, --folder Upload files into this remote folder
-c, --creat Creat remote folder."
Directory names are separated with a slash, e.g.
rootFolder/subFolder
Do NOT use a trailing slash!
-h, --help Show this help
-r, --rename Rename the files during upload
For each file you specify you MUST also specify
the remote filename as the subsequent parameter
Be especially careful with globbing!
-s, --silent Silent mode for use in crontab scripts.
Return only exit code.
-ls,--list Show the itmes in this directory.
-l, --link Show the file share link.
#####################################################################
2、命令示范
如果我们要上传/root
文件夹里面的moerats.txt
,使用命令:
#此命令默认上传到OneDrive根目录
onedrive '/root/moerats.txt'
#如果上传到指定文件夹,就需要加-f参数
onedrive -f RATS '/root/moerats.txt' #上传到OneDrive根目录的RATS文件夹
onedrive -f RATS/RATS '/root/moerats.txt' #上传到OneDrive根目录RATS文件夹里的RATS文件夹
如果我们要将/root
文件夹及里面的文件夹和文件一起上传,使用命令:
#此命令默认上传到OneDrive根目录
onedrive-d '/root'
#如果上传到指定文件夹,就需要加-f参数
onedrive-d -f RATS '/root' #上传到OneDrive根目录的RATS文件夹
onedrive-d -f RATS/RATS '/root' #上传到OneDrive根目录RATS文件夹里的RATS文件夹
如果我们想直接查看OneDrive
网盘目录的文件,使用命令:
#此命令只查看根目录文件
onedrive -l
#如果我们要查看根目录root文件夹里的文件
onedrive -l /root