Skip to content

Instantly share code, notes, and snippets.

@cxyzzz
Created March 14, 2020 23:30
Show Gist options
  • Select an option

  • Save cxyzzz/a2057d8ca4035a81cde65643566497c5 to your computer and use it in GitHub Desktop.

Select an option

Save cxyzzz/a2057d8ca4035a81cde65643566497c5 to your computer and use it in GitHub Desktop.
Termux aria2c 启动脚本,包含更新 tracker,启动 AriaNg
#!/system/bin/sh
export LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib
export PATH=/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/usr/bin/applets
CONF=/sdcard/ADM/.config/Aria2/aria2.conf
NG=/sdcard/ADM/.config/AriaNg-1.1.4
start_service() {
if [[ "$(pidof 'aria2c')" == "" ]]; then
aria2c --conf-path="$CONF"
echo -e "\e[0;31m Aria2 启动成功 ● \e[0m"
echo -e "\e[0;31m 进程 ID: $(pidof 'aria2c') \e[0m"
elif [[ "$(pidof 'aria2c')" != "" ]]; then
echo -e "\e[0;31m Aria2 已运行 ● \e[0m"
echo -e "\e[0;31m 进程 ID: $(pidof 'aria2c') \e[0m"
exit
else
echo -e "\e[0;36m Aria2 启动失败 ○ \e[0m"
fi
if [[ "$(pidof 'httpd')" == "" ]]; then
httpd -h /sdcard/ADM/.config/AriaNg-1.1.4
echo -e "\e[0;31m AriaNg 启动成功 ● \e[0m"
echo -e "\e[0;31m 进程 ID: $(pidof 'httpd') \e[0m"
elif [[ "$(pidof 'httpd')" != "" ]]; then
echo -e "\e[0;31m AriaNg 已运行 ● \e[0m"
echo -e "\e[0;31m 进程 ID: $(pidof 'httpd') \e[0m"
exit
else
echo -e "\e[0;36m AriaNg 启动失败 ○ \e[0m"
fi
echo "自动打开浏览器。。"
termux-open-url "http://localhost:8080"
}
stop_service() {
if [[ "$(pidof 'aria2c')" != "" ]]; then
kill -9 $(pidof 'aria2c')
echo -e "\e[0;31m Aria2 已关闭 ○ \e[0m"
else
echo -e "\e[0;36m Aria2 未能关闭 ● \e[0m"
fi
if [[ "$(pidof 'httpd')" != "" ]]; then
kill -9 $(pidof 'httpd')
echo -e "\e[0;31m AriaNg 已关闭 ○ \e[0m"
else
echo -e "\e[0;36m AriaNg 未能关闭 ● \e[0m"
fi
}
auto_service() {
if [[ "$(pidof 'aria2c')" != "" ]]; then
stop_service
else
start_service
fi
}
check_service() {
if [[ "$(pidof 'aria2c')" == "" ]]; then
echo -e "\e[0;31m Aria2 未运行 ○ \e[0m"
else
echo -e "\e[0;31m Aria2 已运行 ● \e[0m"
echo -e "\e[0;31m 进程 ID: $(pidof 'aria2c') \e[0m"
echo -e "\e[0;31m 配置文件路径:$CONF \e[0m"
fi
if [[ "$(pidof 'httpd')" == "" ]]; then
echo -e "\e[0;31m AriaNg 未运行 ○ \e[0m"
else
echo -e "\e[0;31m AriaNg 已运行 ● \e[0m"
echo -e "\e[0;31m 进程 ID: $(pidof 'httpd') \e[0m"
echo -e "\e[0;31m 文件路径:$NG \e[0m"
fi
}
update_tracker() {
list=`wget -qO- https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt | awk NF`
list1=`wget -qO- https://gitee.com/banbendalao/hosts_optimize_tracker_links/raw/master/tracker.txt`
list2=`wget -qO- https://newtrackon.com/api/live | awk NF`
list3=`wget -qO- https://trackerslist.com/all_aria2.txt`
list4=`wget -qO- http://github.itzmx.com/1265578519/OpenTracker/master/tracker.txt`
lists=`echo $list $list1 $list2 $list3 $list4 | tr ' ' '\n' | tr ',' "\n" | sort -u | tr '\n' ','`
if [ -z "`grep "bt-tracker" $CONF`" ]; then
sed -i 'bt-tracker='${lists} $CONF
echo add......
else
sed -i "s@bt-tracker.*@bt-tracker=$lists@g" $CONF
echo update......
fi
}
case $1 in
'start')
start_service
;;
'stop')
stop_service
;;
'auto')
auto_service
;;
'status')
check_service
;;
'restart')
stop_service
start_service
;;
'update')
stop_service
update_tracker
start_service
;;
*)
if [[ -z ${1} ]]; then
aria2c --help
echo -e "\e[0;31m aria2 {status|start|stop|restart|update|*}"
else
aria2c $*
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment