这个脚本和配置文件充分考虑了可移植性,其中的路径部分全部使用环境变量,保证在不同机器上顺利可用。
下面是我的配置文件
请用 aria2.conf.template 作为文件名保存
下面是 Linux 加载时用的 shdir=${HOME}/Downloads
log=${HOME}/.aria2/aria2.log
check-integrity=true
continue=true
max-connection-per-server=2
remote-time=true
check-certificate=false
referer=*
bt-enable-lpd=true
bt-load-saved-metadata=true
bt-max-peers=0
bt-save-metadata=true
enable-dht=true
enable-dht6=true
max-overall-upload-limit=200K
enable-rpc=true
rpc-allow-origin-all=true
rpc-listen-all=true
rpc-save-upload-metadata=true
allow-overwrite=true
daemon=true
file-allocation=none
force-save=true
log-level=notice
parameterized-uri=true
quiet=true
save-session=${HOME}/.aria2/aria2.session
input-file=${HOME}/.aria2/aria2.session
#!/bin/sh
SHELL_FOLDER=~/.aria2
if [ ! -d ${SHELL_FOLDER} ]; then
mkdir ${SHELL_FOLDER}
fi
if [ ! -f ${SHELL_FOLDER}/aria2.session ]; then
touch ${SHELL_FOLDER}/aria2.session
fi
cat $(dirname $(readlink -f "$0"))/aria2.conf.template | envsubst > ${SHELL_FOLDER}/aria2.conf
if [ -f ${SHELL_FOLDER}/aria2.conf ]; then
aria2c --conf-path=${SHELL_FOLDER}/aria2.conf
else
echo Not Found ! ${SHELL_FOLDER}/aria2.conf
fi
下面是 Windows 用的 .cmd 后缀的批处理文件
Windows 版本用户记得下载个 AriaNg.html 放到目录中,这样双击批处理就可以同时打开管理 Web 界面!(rpc不要用http协议链接,选用 websocket 链接)
@echo off
setlocal enabledelayedexpansion
IF NOT EXIST %UserProFile%\.aria2 MD %UserProFile%\.aria2
IF NOT EXIST %UserProFile%\.aria2\aria2.session echo.>%UserProFile%\.aria2\aria2.session
START "" AriaNg.html
echo # > %UserProFile%\.aria2\aria2.conf
for /f "delims=" %%i in (%~dp0%aria2.conf.template) do (
set "mystr=%%i"
set mystr=!mystr:${Home}=%UserProFile%!
echo !mystr! >> %UserProFile%\.aria2\aria2.conf
)
echo createobject("wscript.shell").run "aria2c.exe --conf-path=%UserProFile%\.aria2\aria2.conf",0 > %Temp%\aria2.vbs
netstat -an | find ":6800" | find "LISTENING" || cscript.exe %Temp%\aria2.vbs
del %Temp%\aria2.vbs
希望给懒得折腾的玩家提供方便!