脚本内容:
自动安装和设置下载路径并设置开机自动启动服务
默认下载路径为 /home/当前登录用户名/Downloads
#!/bin/sh #开始安装 aria2 usr=`whoami` file="/etc/aria2" file_session=/etc/aria2/aria2.session file_conf=/etc/aria2/aria2.conf userpath=~/Downloads if [ ! -d "$file" ]; then echo "正在安装 aria2 " sudo apt-get -y install aria2 echo "创建目录 $file" sudo mkdir $file echo "创建文件 $file_session" sudo touch $file_session echo "创建文件 $file_conf" sudo touch $file_conf sudo chmod 777 $file_session sudo chmod 777 $file_conf echo "写入默认配置信息..." sudo echo "#=========文件保存目录自行修改">> $file_conf sudo echo "#username根据实际情况修改">> $file_conf sudo echo "dir=$userpath">> $file_conf sudo echo "disable-ipv6=true">> $file_conf sudo echo "">> $file_conf sudo echo "#打开rpc的目的是为了给web管理端用">> $file_conf sudo echo "enable-rpc=true">> $file_conf sudo echo "rpc-allow-origin-all=true">> $file_conf sudo echo "rpc-listen-all=true">> $file_conf sudo echo "#rpc-listen-port=6800">> $file_conf sudo echo "#断点续传">> $file_conf sudo echo "continue=true">> $file_conf sudo echo "input-file=$file_session">> $file_conf sudo echo "save-session=$file_session">> $file_conf sudo echo "">> $file_conf sudo echo "#最大同时下载任务数">> $file_conf sudo echo "max-concurrent-downloads=20">> $file_conf sudo echo "save-session-interval=120">> $file_conf sudo echo "">> $file_conf sudo echo "# Http/FTP 相关">> $file_conf sudo echo "connect-timeout=120">> $file_conf sudo echo "#lowest-speed-limit=10K">> $file_conf sudo echo "#同服务器连接数">> $file_conf sudo echo "max-connection-per-server=10">> $file_conf sudo echo "#max-file-not-found=2">> $file_conf sudo echo "#最小文件分片大小, 下载线程数上限取决于能分出多少片, 对于小文件重要">> $file_conf sudo echo "min-split-size=10M">> $file_conf sudo echo "#单文件最大线程数, 路由建议值: 5">> $file_conf sudo echo "split=10">> $file_conf sudo echo "check-certificate=false">> $file_conf sudo echo "#http-no-cache=true">> $file_conf fi #开始安装服务 aria2ser=/etc/init.d/aria2c if [ ! -d "$aria2ser" ]; then echo "开始安装 aria2c 服务" echo "创建文件 $aria2ser" sudo touch $aria2ser sudo chmod 777 $aria2ser echo "写入服务配置信息" sudo echo "#!/bin/sh">> $aria2ser sudo echo "### BEGIN INIT INFO">> $aria2ser sudo echo "# Provides: aria2">> $aria2ser sudo echo '# Required-Start: $remote_fs $network'>> $aria2ser sudo echo '# Required-Stop: $remote_fs $network'>> $aria2ser sudo echo "# Default-Start: 2 3 4 5">> $aria2ser sudo echo "# Default-Stop: 0 1 6">> $aria2ser sudo echo "# Short-Description: Aria2 Downloader">> $aria2ser sudo echo "### END INIT INFO">> $aria2ser sudo echo " ">> $aria2ser sudo echo 'case "$1" in'>> $aria2ser sudo echo "start)">> $aria2ser sudo echo " ">> $aria2ser sudo echo 'echo -n "Starting aria2c"'>> $aria2ser sudo echo "sudo -u $usr aria2c --conf-path=$file_conf -D">> $aria2ser # sudo echo "sudo aria2c --conf-path=$file_conf -D">> $aria2ser sudo echo "#sudo -u后面的是你正在使用的用户名">> $aria2ser sudo echo ";;">> $aria2ser sudo echo "stop)">> $aria2ser sudo echo " ">> $aria2ser sudo echo 'echo -n "Shutting down aria2c "'>> $aria2ser sudo echo "sudo killall aria2c">> $aria2ser sudo echo ";;">> $aria2ser sudo echo "restart)">> $aria2ser sudo echo " ">> $aria2ser sudo echo "sudo killall aria2c">> $aria2ser sudo echo "sudo -u $usr aria2c --conf-path=$file_conf -D">> $aria2ser sudo echo "#同上面的一样,根据自己的用户名。">> $aria2ser sudo echo ";;">> $aria2ser sudo echo "esac">> $aria2ser sudo echo "exit">> $aria2ser sudo chmod 755 $aria2ser echo "重载 systemctl 配置" sudo systemctl daemon-reload echo "设置开机启动项" sudo update-rc.d aria2c defaults echo "安装完成" fi