ccaa.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #!/bin/bash
  2. ##### 一键安装Caddy + Aria2 + AriaNg #####
  3. ##### 作者:xiaoz.me #####
  4. ##### 更新时间:2019-05-15 #####
  5. #导入环境变量
  6. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin
  7. export PATH
  8. #安装之前的准备
  9. function setout(){
  10. if [ -e "/usr/bin/yum" ]
  11. then
  12. yum -y install curl gcc gcc+ make bzip2
  13. else
  14. #更新软件,否则可能make命令无法安装
  15. sudo apt-get update
  16. sudo apt-get install -y curl make
  17. fi
  18. }
  19. #安装Aria2
  20. function install_aria2(){
  21. #yum -y update
  22. #安装aria2静态编译版本,来源于https://github.com/q3aql/aria2-static-builds/
  23. wget -c http://soft.xiaoz.org/linux/aria2-1.34.0-linux-gnu-64bit-build1.tar.bz2
  24. tar jxvf aria2-1.34.0-linux-gnu-64bit-build1.tar.bz2
  25. cd aria2-1.34.0-linux-gnu-64bit-build1
  26. make install
  27. cd ..
  28. }
  29. #安装caddy
  30. function install_caddy(){
  31. #一键安装https://caddyserver.com/download/linux/amd64?plugins=http.filemanager&license=personal&telemetry=off
  32. #curl https://getcaddy.com | bash -s personal http.filemanager
  33. #安装caddy
  34. wget http://soft.xiaoz.org/linux/caddy_v0.11.0_linux_amd64_custom_personal.tar.gz -O caddy.tar.gz
  35. tar -zxvf caddy.tar.gz
  36. mv caddy /usr/sbin/
  37. chmod +x /usr/sbin/caddy
  38. #添加服务
  39. #mv init/linux-systemd/caddy.service /lib/systemd/system
  40. #chmod +x /lib/systemd/system/caddy.service
  41. #开机启动
  42. #systemctl enable caddy.service
  43. }
  44. #处理配置文件
  45. function dealconf(){
  46. #创建目录和文件
  47. mkdir -p /etc/ccaa/
  48. touch /etc/ccaa/aria2.session
  49. touch /etc/ccaa/aria2.log
  50. touch /etc/ccaa/caddy.log
  51. cp aria2.conf /etc/ccaa/
  52. cp caddy.conf /etc/ccaa/
  53. cp upbt.sh /etc/ccaa/
  54. chmod +x /etc/ccaa/upbt.sh
  55. chmod +x ccaa
  56. cp ccaa /usr/sbin
  57. }
  58. #自动放行端口
  59. function chk_firewall(){
  60. if [ -e "/etc/sysconfig/iptables" ]
  61. then
  62. iptables -I INPUT -p tcp --dport 6080 -j ACCEPT
  63. iptables -I INPUT -p tcp --dport 6800 -j ACCEPT
  64. iptables -I INPUT -p tcp --dport 6998 -j ACCEPT
  65. iptables -I INPUT -p tcp --dport 51413 -j ACCEPT
  66. service iptables save
  67. service iptables restart
  68. elif [ -e "/etc/firewalld/zones/public.xml" ]
  69. then
  70. firewall-cmd --zone=public --add-port=6080/tcp --permanent
  71. firewall-cmd --zone=public --add-port=6800/tcp --permanent
  72. firewall-cmd --zone=public --add-port=6998/tcp --permanent
  73. firewall-cmd --zone=public --add-port=51413/tcp --permanent
  74. firewall-cmd --reload
  75. elif [ -e "/etc/ufw/before.rules" ]
  76. then
  77. sudo ufw allow 6080/tcp
  78. sudo ufw allow 6800/tcp
  79. sudo ufw allow 6998/tcp
  80. sudo ufw allow 51413/tcp
  81. fi
  82. }
  83. #删除端口
  84. function del_post() {
  85. if [ -e "/etc/sysconfig/iptables" ]
  86. then
  87. sed -i '/^.*6080.*/'d /etc/sysconfig/iptables
  88. sed -i '/^.*6800.*/'d /etc/sysconfig/iptables
  89. sed -i '/^.*6998.*/'d /etc/sysconfig/iptables
  90. sed -i '/^.*51413.*/'d /etc/sysconfig/iptables
  91. service iptables save
  92. service iptables restart
  93. elif [ -e "/etc/firewalld/zones/public.xml" ]
  94. then
  95. firewall-cmd --zone=public --remove-port=6080/tcp --permanent
  96. firewall-cmd --zone=public --remove-port=6800/tcp --permanent
  97. firewall-cmd --zone=public --remove-port=6998/tcp --permanent
  98. firewall-cmd --zone=public --remove-port=51413/tcp --permanent
  99. firewall-cmd --reload
  100. elif [ -e "/etc/ufw/before.rules" ]
  101. then
  102. sudo ufw delete 6080/tcp
  103. sudo ufw delete 6800/tcp
  104. sudo ufw delete 6998/tcp
  105. sudo ufw delete 51413/tcp
  106. fi
  107. }
  108. #设置账号密码
  109. function setting(){
  110. echo '-------------------------------------------------------------'
  111. read -p "设置下载路径(请填写绝对地址,默认/data/ccaaDown):" downpath
  112. read -p "Aria2 RPC 密钥:(字母或数字组合,不要含有特殊字符):" secret
  113. #如果Aria2密钥为空
  114. while [ -z "${secret}" ]
  115. do
  116. read -p "Aria2 RPC 密钥:(字母或数字组合,不要含有特殊字符):" secret
  117. done
  118. read -p "设置Caddy用户名:" caddyuser
  119. while [ -z "${caddyuser}" ]
  120. do
  121. read -p "设置Caddy用户名:" caddyuser
  122. done
  123. read -p "设置Caddy密码:" caddypass
  124. while [ -z "${caddypass}" ]
  125. do
  126. read -p "设置Caddy密码:" caddypass
  127. done
  128. #如果下载路径为空,设置默认下载路径
  129. if [ -z "${downpath}" ]
  130. then
  131. downpath='/data/ccaaDown'
  132. fi
  133. #执行替换操作
  134. mkdir -p ${downpath}
  135. sed -i "s%dir=%dir=${downpath}%g" /etc/ccaa/aria2.conf
  136. sed -i "s/rpc-secret=/rpc-secret=${secret}/g" /etc/ccaa/aria2.conf
  137. sed -i "s/username/${caddyuser}/g" /etc/ccaa/caddy.conf
  138. sed -i "s/password/${caddypass}/g" /etc/ccaa/caddy.conf
  139. #sed -i "s%/home%${downpath}%g" /etc/ccaa/caddy.conf
  140. sed -i "s%/admin%/admin ${downpath}%g" /etc/ccaa/caddy.conf
  141. #更新tracker
  142. bash ./upbt.sh
  143. #安装AriaNg
  144. wget http://soft.xiaoz.org/website/AriaNg.zip
  145. unzip AriaNg.zip
  146. cp -a AriaNg /etc/ccaa
  147. #启动服务
  148. nohup aria2c --conf-path=/etc/ccaa/aria2.conf > /etc/ccaa/aria2.log 2>&1 &
  149. nohup caddy -conf="/etc/ccaa/caddy.conf" > /etc/ccaa/caddy.log 2>&1 &
  150. #获取ip
  151. osip=$(curl -4s https://api.ip.sb/ip)
  152. echo '-------------------------------------------------------------'
  153. echo "大功告成,请访问: http://${osip}:6080/"
  154. echo '用户名:' ${caddyuser}
  155. echo '密码:' ${caddypass}
  156. echo 'Aria2 RPC 密钥:' ${secret}
  157. echo '帮助文档: https://dwz.ovh/ccaa (必看)'
  158. echo '-------------------------------------------------------------'
  159. }
  160. #清理工作
  161. function cleanup(){
  162. rm -rf *.zip
  163. rm -rf *.gz
  164. rm -rf *.txt
  165. rm -rf aria2-1.34*
  166. #rm -rf *.conf
  167. rm -rf init
  168. }
  169. #卸载
  170. function uninstall(){
  171. #停止所有服务
  172. kill -9 $(pgrep 'aria2c')
  173. kill -9 $(pgrep 'caddy')
  174. #删除服务
  175. #systemctl disable caddy.service
  176. #rm -rf /lib/systemd/system/caddy.service
  177. #删除文件
  178. rm -rf /etc/ccaa
  179. rm -rf /usr/sbin/caddy
  180. rm -rf /usr/sbin/ccaa
  181. rm -rf /usr/bin/aria2c
  182. rm -rf aria2-1.*
  183. rm -rf AriaNg*
  184. rm -rf /usr/share/man/man1/aria2c.1
  185. rm -rf /etc/ssl/certs/ca-certificates.crt
  186. #删除端口
  187. del_post
  188. echo "------------------------------------------------"
  189. echo '卸载完成!'
  190. echo "------------------------------------------------"
  191. }
  192. #选择安装方式
  193. echo "------------------------------------------------"
  194. echo "Linux + Caddy + Aria2 + AriaNg一键安装脚本(CCAA)"
  195. echo "1) 安装CCAA"
  196. echo "2) 卸载CCAA"
  197. echo "3) 更新bt-tracker"
  198. echo "q) 退出!"
  199. read -p ":" istype
  200. case $istype in
  201. 1)
  202. setout
  203. install_aria2 && \
  204. install_caddy && \
  205. dealconf && \
  206. chk_firewall && \
  207. setting && \
  208. cleanup
  209. ;;
  210. 2)
  211. uninstall
  212. ;;
  213. 3)
  214. bash ./upbt.sh
  215. ;;
  216. q)
  217. exit
  218. ;;
  219. *) echo '参数错误!'
  220. esac