ccaa.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #!/bin/bash
  2. ##### 一键安装File Browser + Aria2 + AriaNg #####
  3. ##### 作者:xiaoz.me #####
  4. ##### 更新时间:2020-02-27 #####
  5. #导入环境变量
  6. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin
  7. export PATH
  8. #CDN域名设置
  9. if [ $1 = 'cdn' ]
  10. then
  11. aria2_url='http://soft.xiaoz.top/linux/aria2-1.35.0-linux-gnu-64bit-build1.tar.bz2'
  12. filebrowser_url='http://soft.xiaoz.top/linux/linux-amd64-filebrowser.tar.gz'
  13. master_url='https://github.com/helloxz/ccaa/archive/master.zip'
  14. ccaa_web_url='http://soft.xiaoz.top/linux/ccaa_web.tar.gz'
  15. else
  16. aria2_url='https://github.com/q3aql/aria2-static-builds/releases/download/v1.35.0/aria2-1.35.0-linux-gnu-64bit-build1.tar.bz2'
  17. filebrowser_url='https://github.com/filebrowser/filebrowser/releases/download/v2.0.16/linux-amd64-filebrowser.tar.gz'
  18. master_url='https://github.com/helloxz/ccaa/archive/master.zip'
  19. ccaa_web_url='http://soft.xiaoz.org/linux/ccaa_web.tar.gz'
  20. fi
  21. #安装前的检查
  22. function check(){
  23. echo '-------------------------------------------------------------'
  24. if [ -e "/etc/ccaa" ]
  25. then
  26. echo 'CCAA已经安装,若需要重新安装,请先卸载再安装!'
  27. echo '-------------------------------------------------------------'
  28. exit
  29. else
  30. echo '检测通过,即将开始安装。'
  31. echo '-------------------------------------------------------------'
  32. fi
  33. }
  34. #安装之前的准备
  35. function setout(){
  36. if [ -e "/usr/bin/yum" ]
  37. then
  38. yum -y install curl gcc make bzip2 gzip wget unzip tar
  39. else
  40. #更新软件,否则可能make命令无法安装
  41. sudo apt-get update
  42. sudo apt-get install -y curl make bzip2 gzip wget unzip sudo
  43. fi
  44. #创建临时目录
  45. cd
  46. mkdir ./ccaa_tmp
  47. #创建用户和用户组
  48. groupadd ccaa
  49. useradd -M -g ccaa ccaa -s /sbin/nologin
  50. }
  51. #安装Aria2
  52. function install_aria2(){
  53. #进入临时目录
  54. cd ./ccaa_tmp
  55. #yum -y update
  56. #安装aria2静态编译版本,来源于https://github.com/q3aql/aria2-static-builds/
  57. wget -c ${aria2_url}
  58. tar jxvf aria2-1.35.0-linux-gnu-64bit-build1.tar.bz2
  59. cd aria2-1.35.0-linux-gnu-64bit-build1
  60. make install
  61. cd
  62. }
  63. #安装File Browser文件管理器
  64. function install_file_browser(){
  65. cd ./ccaa_tmp
  66. #下载File Browser
  67. wget ${filebrowser_url}
  68. #解压
  69. tar -zxvf linux-amd64-filebrowser.tar.gz
  70. #移动位置
  71. mv filebrowser /usr/sbin
  72. cd
  73. }
  74. #处理配置文件
  75. function dealconf(){
  76. cd ./ccaa_tmp
  77. #下载CCAA项目
  78. wget ${master_url}
  79. #解压
  80. unzip master.zip
  81. #复制CCAA核心目录
  82. mv ccaa-master/ccaa_dir /etc/ccaa
  83. #创建aria2日志文件
  84. touch /var/log/aria2.log
  85. #upbt增加执行权限
  86. chmod +x /etc/ccaa/upbt.sh
  87. chmod +x ccaa-master/ccaa
  88. cp ccaa-master/ccaa /usr/sbin
  89. cd
  90. }
  91. #自动放行端口
  92. function chk_firewall(){
  93. if [ -e "/etc/sysconfig/iptables" ]
  94. then
  95. iptables -I INPUT -p tcp --dport 6080 -j ACCEPT
  96. iptables -I INPUT -p tcp --dport 6081 -j ACCEPT
  97. iptables -I INPUT -p tcp --dport 6800 -j ACCEPT
  98. iptables -I INPUT -p tcp --dport 6998 -j ACCEPT
  99. iptables -I INPUT -p tcp --dport 51413 -j ACCEPT
  100. service iptables save
  101. service iptables restart
  102. elif [ -e "/etc/firewalld/zones/public.xml" ]
  103. then
  104. firewall-cmd --zone=public --add-port=6080/tcp --permanent
  105. firewall-cmd --zone=public --add-port=6081/tcp --permanent
  106. firewall-cmd --zone=public --add-port=6800/tcp --permanent
  107. firewall-cmd --zone=public --add-port=6998/tcp --permanent
  108. firewall-cmd --zone=public --add-port=51413/tcp --permanent
  109. firewall-cmd --reload
  110. elif [ -e "/etc/ufw/before.rules" ]
  111. then
  112. sudo ufw allow 6080/tcp
  113. sudo ufw allow 6081/tcp
  114. sudo ufw allow 6800/tcp
  115. sudo ufw allow 6998/tcp
  116. sudo ufw allow 51413/tcp
  117. fi
  118. }
  119. #删除端口
  120. function del_post() {
  121. if [ -e "/etc/sysconfig/iptables" ]
  122. then
  123. sed -i '/^.*6080.*/'d /etc/sysconfig/iptables
  124. sed -i '/^.*6081.*/'d /etc/sysconfig/iptables
  125. sed -i '/^.*6800.*/'d /etc/sysconfig/iptables
  126. sed -i '/^.*6998.*/'d /etc/sysconfig/iptables
  127. sed -i '/^.*51413.*/'d /etc/sysconfig/iptables
  128. service iptables save
  129. service iptables restart
  130. elif [ -e "/etc/firewalld/zones/public.xml" ]
  131. then
  132. firewall-cmd --zone=public --remove-port=6080/tcp --permanent
  133. firewall-cmd --zone=public --remove-port=6081/tcp --permanent
  134. firewall-cmd --zone=public --remove-port=6800/tcp --permanent
  135. firewall-cmd --zone=public --remove-port=6998/tcp --permanent
  136. firewall-cmd --zone=public --remove-port=51413/tcp --permanent
  137. firewall-cmd --reload
  138. elif [ -e "/etc/ufw/before.rules" ]
  139. then
  140. sudo ufw delete 6080/tcp
  141. sudo ufw delete 6081/tcp
  142. sudo ufw delete 6800/tcp
  143. sudo ufw delete 6998/tcp
  144. sudo ufw delete 51413/tcp
  145. fi
  146. }
  147. #添加服务
  148. function add_service() {
  149. if [ -d "/etc/systemd/system" ]
  150. then
  151. cp /etc/ccaa/services/* /etc/systemd/system
  152. systemctl daemon-reload
  153. fi
  154. }
  155. #设置账号密码
  156. function setting(){
  157. cd
  158. cd ./ccaa_tmp
  159. echo '-------------------------------------------------------------'
  160. read -p "设置下载路径(请填写绝对地址,默认/data/ccaaDown):" downpath
  161. read -p "Aria2 RPC 密钥:(字母或数字组合,不要含有特殊字符):" secret
  162. #如果Aria2密钥为空
  163. while [ -z "${secret}" ]
  164. do
  165. read -p "Aria2 RPC 密钥:(字母或数字组合,不要含有特殊字符):" secret
  166. done
  167. #如果下载路径为空,设置默认下载路径
  168. if [ -z "${downpath}" ]
  169. then
  170. downpath='/data/ccaaDown'
  171. fi
  172. #获取ip
  173. osip=$(curl -4s https://api.ip.sb/ip)
  174. #执行替换操作
  175. mkdir -p ${downpath}
  176. sed -i "s%dir=%dir=${downpath}%g" /etc/ccaa/aria2.conf
  177. sed -i "s/rpc-secret=/rpc-secret=${secret}/g" /etc/ccaa/aria2.conf
  178. #替换filebrowser读取路径
  179. sed -i "s%ccaaDown%${downpath}%g" /etc/ccaa/config.json
  180. #替换AriaNg服务器链接
  181. sed -i "s/server_ip/${osip}/g" /etc/ccaa/AriaNg/index.html
  182. #更新tracker
  183. bash /etc/ccaa/upbt.sh
  184. #安装AriaNg
  185. wget ${ccaa_web_url}
  186. tar -zxvf ccaa_web.tar.gz
  187. cp ccaa_web /usr/sbin/
  188. chmod +x /usr/sbin/ccaa_web
  189. #启动服务
  190. nohup sudo -u ccaa aria2c --conf-path=/etc/ccaa/aria2.conf > /var/log/aria2.log 2>&1 &
  191. #nohup caddy -conf="/etc/ccaa/caddy.conf" > /etc/ccaa/caddy.log 2>&1 &
  192. nohup sudo -u ccaa /usr/sbin/ccaa_web > /var/log/ccaa_web.log 2>&1 &
  193. #运行filebrowser
  194. nohup sudo -u ccaa filebrowser -c /etc/ccaa/config.json > /var/log/fbrun.log 2>&1 &
  195. #重置权限
  196. chown -R ccaa:ccaa /etc/ccaa/
  197. chown -R ccaa:ccaa ${downpath}
  198. #注册服务
  199. add_service
  200. echo '-------------------------------------------------------------'
  201. echo "大功告成,请访问: http://${osip}:6080/"
  202. echo 'File Browser 用户名:ccaa'
  203. echo 'File Browser 密码:admin'
  204. echo 'Aria2 RPC 密钥:' ${secret}
  205. echo '帮助文档: https://dwz.ovh/ccaa (必看)'
  206. echo '-------------------------------------------------------------'
  207. }
  208. #清理工作
  209. function cleanup(){
  210. cd
  211. rm -rf ccaa_tmp
  212. #rm -rf *.conf
  213. #rm -rf init
  214. }
  215. #卸载
  216. function uninstall(){
  217. wget -O ccaa-uninstall.sh https://raw.githubusercontent.com/helloxz/ccaa/master/uninstall.sh
  218. bash ccaa-uninstall.sh
  219. }
  220. #选择安装方式
  221. echo "------------------------------------------------"
  222. echo "Linux + File Browser + Aria2 + AriaNg一键安装脚本(CCAA)"
  223. echo "1) 安装CCAA"
  224. echo "2) 卸载CCAA"
  225. echo "3) 更新bt-tracker"
  226. echo "q) 退出!"
  227. read -p ":" istype
  228. case $istype in
  229. 1)
  230. check
  231. setout
  232. chk_firewall
  233. install_aria2 && \
  234. install_file_browser && \
  235. dealconf && \
  236. setting && \
  237. cleanup
  238. ;;
  239. 2)
  240. uninstall
  241. ;;
  242. 3)
  243. bash /etc/ccaa/upbt.sh
  244. ;;
  245. q)
  246. exit
  247. ;;
  248. *) echo '参数错误!'
  249. esac