diff --git a/scripts/clash.sh b/scripts/clash.sh index ab7d610..8f85478 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -2,114 +2,105 @@ # Copyright (C) Juewuy getconfig(){ -#系统类型 -if [ -f /bin/opkg ];then - host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) -else - host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g'|head -n 1) - [ -z "$host" ] && host=127.0.0.1 -fi -#服务器地址 -[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash -#文件路径 -[ -z "$clashdir" ] && clashdir=$(dirname $(readlink -f "$0")) && echo "export clashdir=\"$clashdir\"" >> /etc/profile -ccfg=$clashdir/mark -yaml=$clashdir/config.yaml -#检查/读取标识文件 -[ ! -f $ccfg ] && echo '#标识clash运行状态的文件,不明勿动!' > $ccfg -source $ccfg -#检查mac地址记录 -[ ! -f $clashdir/mac ] && touch $clashdir/mac -#dashboard目录位置 -[ -d /www/clash ] && dbdir=/www/clash && hostdir=/clash -[ -d $clashdir/ui ] && dbdir=$clashdir/ui && hostdir=":$db_port/ui" -#开机自启相关 -if [ -f /etc/rc.common ];then - if [ -n "$(find /etc/rc.d -name '*clash')" ];then - autostart=enable_rc + #服务器缺省地址 + [ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash + #文件路径 + [ -z "$clashdir" ] && clashdir=$(dirname $(readlink -f "$0")) && echo "export clashdir=\"$clashdir\"" >> /etc/profile + ccfg=$clashdir/mark + yaml=$clashdir/config.yaml + #检查/读取标识文件 + [ ! -f $ccfg ] && echo '#标识clash运行状态的文件,不明勿动!' > $ccfg + source $ccfg + #设置默认端口 + [ -z "$mix_port" ] && mix_port=7890 + [ -z "$redir_port" ] && redir_port=7892 + [ -z "$db_port" ] && db_port=9999 + [ -z "$dns_port" ] && dns_port=1053 + #检查mac地址记录 + [ ! -f $clashdir/mac ] && touch $clashdir/mac + #获取本机host地址 + if [ -f /bin/opkg ];then + host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) else - autostart=disable_rc + host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g'|head -n 1) + [ -z "$host" ] && host=127.0.0.1 fi -else - if [ -n "$(systemctl list-unit-files clash.service 2>&1 | grep -o enable)" ];then - autostart=enable_sys + #dashboard目录位置 + [ -d /www/clash ] && dbdir=/www/clash && hostdir=/clash + [ -d $clashdir/ui ] && dbdir=$clashdir/ui && hostdir=":$db_port/ui" + #开机自启相关 + if [ -f /etc/rc.common ];then + [ -n "$(find /etc/rc.d -name '*clash')" ] && autostart=enable_rc || autostart=disable_rc else - autostart=disable_sys + [ -n "$(systemctl is-enabled clash.service 2>&1 | grep enable)" ] && autostart=enable_sys || autostart=disable_sys fi -fi -if [ "$start_old" = "已开启" ];then - auto="\033[33m已设置保守模式!\033[0m" - auto1="\033[36m设为\033[0m常规模式启动" -elif [ "$autostart" = "enable_rc" -o "$autostart" = "enable_sys" ]; then - auto="\033[32m已设置开机启动!\033[0m" - auto1="\033[36m禁用\033[0mclash开机启动" -else - auto="\033[31m未设置开机启动!\033[0m" - auto1="\033[36m允许\033[0mclash开机启动" -fi -#获取默认端口 -[ -z "$mix_port" ] && mix_port=7890 -[ -z "$redir_port" ] && redir_port=7892 -[ -z "$db_port" ] && db_port=9999 -[ -z "$dns_port" ] && dns_port=1053 -#获取运行模式 -if [ -z "$redir_mod" ];then - sed -i "2i\redir_mod=Redir模式" $ccfg - redir_mod=Redir模式 -fi -#获取运行状态 -PID=$(pidof clash) -if [ -n "$PID" ];then - run="\033[32m正在运行($redir_mod)\033[0m" - VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'` - #获取运行时长 - if [ -n "$start_time" ]; then - time=$((`date +%s`-start_time)) - day=$((time/86400)) - #day=$(expr $time / 86400) - if [ "$day" = "0" ]; then - day="" - else - day="$day""天" + #开机自启描述 + if [ "$start_old" = "已开启" ];then + auto="\033[33m已设置保守模式!\033[0m" + auto1="\033[36m设为\033[0m常规模式启动" + elif [ "$autostart" = "enable_rc" -o "$autostart" = "enable_sys" ]; then + auto="\033[32m已设置开机启动!\033[0m" + auto1="\033[36m禁用\033[0mclash开机启动" + else + auto="\033[31m未设置开机启动!\033[0m" + auto1="\033[36m允许\033[0mclash开机启动" + fi + #获取运行模式 + if [ -z "$redir_mod" ];then + sed -i "2i\redir_mod=Redir模式" $ccfg + redir_mod=Redir模式 + fi + #获取运行状态 + PID=$(pidof clash) + if [ -n "$PID" ];then + run="\033[32m正在运行($redir_mod)\033[0m" + VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'` + #获取运行时长 + if [ -n "$start_time" ]; then + time=$((`date +%s`-start_time)) + day=$((time/86400)) + [ "$day" = "0" ] && day='' || day="$day天" + time=`date -u -d @${time} +%H小时%M分%S秒` fi - time=`date -u -d @${time} +%H小时%M分%S秒` + else + run="\033[31m没有运行($redir_mod)\033[0m" + #检测系统端口占用 + checkport fi -else - run="\033[31m没有运行($redir_mod)\033[0m" - #检测系统端口占用 - checkport -fi -#输出状态 - -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[30;46m欢迎使用ShellClash!\033[0m 版本:$versionsh_l" -echo -e "Clash服务"$run","$auto"" -if [ -n "$PID" ];then - echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m,已运行:\033[46;30m"$day"\033[44;37m"$time"\033[0m" -fi -echo -e "TG群:\033[36;4mhttps://t.me/clashfm\033[0m" -echo ----------------------------------------------- -#检查定时任务配置文件 -if [ -z "$cronpath" ];then - [ -d /etc/crontabs/ ] && cronpath="/etc/crontabs/root" - [ -d /var/spool/cron/ ] && cronpath="/var/spool/cron/root" - [ -d /var/spool/cron/crontabs/ ] && cronpath="/var/spool/cron/crontabs/root" - [ -d /etc/storage/cron/crontabs ] && cronpath="/etc/storage/cron/crontabs/admin" - [ -n "$cronpath" ] && sed -i "1i\cronpath=\'$cronpath\'" $ccfg -fi -#检查新手引导 -if [ -z "$userguide" ];then - read -p "检测到首次运行,是否启动新手引导?(1/0) > " res + #检查定时任务配置文件 + if [ -z "$cronpath" ];then + [ -d /etc/crontabs/ ] && cronpath="/etc/crontabs/root" + [ -d /var/spool/cron/ ] && cronpath="/var/spool/cron/root" + [ -d /var/spool/cron/crontabs/ ] && cronpath="/var/spool/cron/crontabs/root" + [ -d /etc/storage/cron/crontabs ] && cronpath="/etc/storage/cron/crontabs/admin" + [ -n "$cronpath" ] && sed -i "1i\cronpath=\'$cronpath\'" $ccfg + fi + #输出状态 + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[30;46m欢迎使用ShellClash!\033[0m 版本:$versionsh_l" + echo -e "Clash服务"$run","$auto"" + if [ -n "$PID" ];then + echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m,已运行:\033[46;30m"$day"\033[44;37m"$time"\033[0m" + fi + echo -e "TG群:\033[36;4mhttps://t.me/clashfm\033[0m" echo ----------------------------------------------- - sed -i "1i\userguide=1" $ccfg - [ "$res" = 1 ] && source $clashdir/getdate.sh && userguide -fi + #检查新手引导 + if [ -z "$userguide" ];then + read -p "检测到首次运行,是否启动新手引导?(1/0) > " res + echo ----------------------------------------------- + sed -i "1i\userguide=1" $ccfg + [ "$res" = 1 ] && source $clashdir/getdate.sh && userguide + fi +} +echoerrornum(){ + echo ----------------------------------------------- + echo -e "\033[31m请输入正确的数字!\033[0m" } start_over(){ [ $? -eq 1 ] && exit echo -e "\033[32mclash服务已启动!\033[0m" - if [ -n "$dbdir" ];then - echo -e "请使用\033[30;47m http://$host$dbdir \033[0m管理内置规则" + if [ -n "$hostdir" ];then + echo -e "请使用\033[30;47m http://$host$hostdir \033[0m管理内置规则" else echo -e "可使用\033[30;47m http://clash.razord.top \033[0m管理内置规则" echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m $db_port \033[0m" @@ -161,12 +152,11 @@ setport(){ echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - elif [[ $num == 1 ]]; then + echoerrornum + elif [ "$num" = 1 ]; then xport=mix_port inputport - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then echo ----------------------------------------------- echo -e "格式必须是\033[32m 用户名:密码 \033[0m的形式,注意用小写冒号分隔!" echo -e "请尽量不要使用特殊符号!可能会产生未知错误!" @@ -188,16 +178,16 @@ setport(){ fi fi setport - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then xport=redir_port inputport - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then xport=dns_port inputport - elif [[ $num == 5 ]]; then + elif [ "$num" = 5 ]; then xport=db_port inputport - elif [[ $num == 6 ]]; then + elif [ "$num" = 6 ]; then read -p "请输入面板访问密码(输入0删除密码) > " secret if [ -n "$secret" ]; then sed -i "/secret*/"d $ccfg @@ -233,10 +223,9 @@ setdns(){ echo ----------------------------------------------- read -p "请输入对应数字 > " num if [ -z "$num" ]; then - echo ----------------------------------------------- - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum clashadv - elif [[ $num == 1 ]]; then + elif [ "$num" = 1 ]; then read -p "请输入新的DNS > " dns_nameserver dns_nameserver=$(echo $dns_nameserver | sed 's/|/\,\ /') if [ -n "$dns_nameserver" ]; then @@ -244,7 +233,7 @@ setdns(){ sed -i "1i\dns_nameserver=\'$dns_nameserver\'" $ccfg echo -e "\033[32m设置成功!!!\033[0m" fi - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then read -p "请输入新的DNS > " dns_fallback dns_fallback=$(echo $dns_nameserver | sed 's/|/\,\ /') if [ -n "$dns_fallback" ]; then @@ -252,13 +241,13 @@ setdns(){ sed -i "1i\dns_fallback=\'$dns_fallback\'" $ccfg echo -e "\033[32m设置成功!!!\033[0m" fi - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then dns_nameserver="" dns_fallback="" sed -i "/dns_nameserver*/"d $ccfg sed -i "/dns_fallback*/"d $ccfg echo -e "\033[33mDNS配置已重置!!!\033[0m" - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then echo ----------------------------------------------- echo -e "\033[31m仅限搭配其他DNS服务(比如dnsmasq、smartDNS)时使用!\033[0m" sed -i "/dns_no*/"d $ccfg @@ -321,139 +310,6 @@ clashstart(){ fi start_over } -clashlink(){ -#获取订阅规则 -if [ -z "$rule_link" ]; then - sed -i "4i\rule_link=1" $ccfg - rule_link=1 -fi -#获取后端服务器地址 -if [ -z "$server_link" ]; then - sed -i "5i\server_link=1" $ccfg - server_link=1 -fi -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[30;47m 欢迎使用导入配置文件功能!\033[0m" -echo ----------------------------------------------- -echo -e " 1 在线导入\033[36m订阅\033[0m并生成Clash配置文件" -echo -e " 2 在线导入\033[33mClash\033[0m配置文件" -echo -e " 3 设置\033[31m节点过滤\033[0m关键字 \033[47;30m$exclude\033[0m" -echo -e " 4 设置\033[32m节点筛选\033[0m关键字 \033[47;30m$include\033[0m" -echo -e " 5 选取\033[33mClash配置规则\033[0m在线模版" -echo -e " 6 选择在线生成服务器-subconverter" -echo -e " 7 \033[36m还原\033[0m之前的配置文件" -echo -e " 8 \033[33m手动更新\033[0m配置文件" -echo -e " 9 设置\033[36m自动更新\033[0m配置文件" -echo ----------------------------------------------- -echo -e " 0 返回上级菜单" -read -p "请输入对应数字 > " num -if [ -z "$num" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - clashsh -elif [[ $num == 1 ]];then - if [ -n "$Url" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[33m检测到已记录的订阅链接:\033[0m" - echo -e "\033[4;32m$Url\033[0m" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - read -p "清空链接/追加导入?[1/0] > " res - if [ "$res" = '1' ]; then - Url="" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m链接已清空!\033[0m" - fi - fi - source $clashdir/getdate.sh - getlink - -elif [[ $num == 2 ]];then - if [ -n "$Url" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[33m检测到已记录的订阅链接:\033[0m" - echo -e "\033[4;32m$Url\033[0m" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - read -p "清空链接/追加导入?[1/0] > " res - if [ "$res" = '1' ]; then - Url="" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m链接已清空!\033[0m" - fi - fi - source $clashdir/getdate.sh - getlink2 - -elif [[ $num == 3 ]];then - source $clashdir/getdate.sh - linkfilter - clashlink - -elif [[ $num == 4 ]];then - source $clashdir/getdate.sh - linkfilter2 - clashlink - -elif [[ $num == 5 ]];then - source $clashdir/getdate.sh - linkconfig - clashlink - -elif [[ $num == 6 ]];then - source $clashdir/getdate.sh - linkserver - clashlink - -elif [[ $num == 7 ]];then - yamlbak=$yaml.bak - if [ ! -f "$yaml".bak ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m没有找到配置文件的备份!\033[0m" - else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e 备份文件共有"\033[32m`wc -l < $yamlbak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < $yaml`\033[0m"行内容 - read -p "确认还原配置文件?此操作不可逆![1/0] > " res - if [ "$res" = '1' ]; then - mv $yamlbak $yaml - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[32m配置文件已还原!请手动重启clash服务!\033[0m" - else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m操作已取消!返回上级菜单!\033[0m" - fi - fi - clashsh - -elif [[ $num == 8 ]];then - if [ -z "$Url" -a -z "$Https" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m没有找到你的订阅链接!请先输入链接!\033[0m" - sleep 2 - clashlink - else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[33m当前系统记录的订阅链接为:\033[0m" - echo -e "\033[4;32m$Url\033[0m" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - read -p "确认更新配置文件?[1/0] > " res - if [ "$res" = '1' ]; then - $clashdir/start.sh getyaml - start_over - exit; - fi - clashlink - fi - -elif [[ $num == 9 ]];then - clashcron - -elif [[ $num == 0 ]];then - clashsh -else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - exit; -fi -} macfilter(){ add_mac(){ echo ----------------------------------------------- @@ -512,6 +368,7 @@ macfilter(){ [ -f /var/lib/dhcp/dhcpd.leases ] && dhcpdir='/var/lib/dhcp/dhcpd.leases' [ -f /var/lib/dhcpd/dhcpd.leases ] && dhcpdir='/var/lib/dhcpd/dhcpd.leases' [ -f /tmp/dhcp.leases ] && dhcpdir='/tmp/dhcp.leases' + ###### echo -e "\033[30;47m请在此添加或移除设备\033[0m" if [ -n "$(cat $clashdir/mac)" ]; then echo ----------------------------------------------- @@ -529,21 +386,20 @@ macfilter(){ echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then - echo ----------------------------------------------- - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum clashcfg - elif [[ $num == 0 ]]; then + elif [ "$num" = 0 ]; then clashcfg - elif [[ $num == 1 ]]; then + elif [ "$num" = 1 ]; then :>$clashdir/mac echo ----------------------------------------------- echo -e "\033[31m设备列表已清空!\033[0m" macfilter - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then add_mac - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then del_mac - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then echo ----------------------------------------------- cat $dhcpdir | awk '{print $2}' > $clashdir/mac echo -e "\033[32m已经将所有设备全部添加进过滤列表!\033[0m" @@ -551,42 +407,12 @@ macfilter(){ sleep 1 macfilter else - echo ----------------------------------------------- - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum macfilter fi } clashcfg(){ -#获取设置默认显示 -[ -z "$skip_cert" ] && skip_cert=已开启 -[ -z "$common_ports" ] && common_ports=已开启 -[ -z "$dns_mod" ] && dns_mod=redir_host -[ -z "$dns_over" ] && dns_over=已开启 -if [ -z "$(cat $clashdir/mac)" ]; then - mac_return=未开启 -else - mac_return=已启用 -fi -# -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[30;47m欢迎使用功能设置菜单:\033[0m" -echo -e "\033[32m修改配置后请手动重启clash服务!\033[0m" -echo ----------------------------------------------- -echo -e " 1 切换Clash运行模式: \033[36m$redir_mod\033[0m" -echo -e " 2 切换DNS运行模式: \033[36m$dns_mod\033[0m" -echo -e " 3 跳过本地证书验证: \033[36m$skip_cert\033[0m ————解决节点证书验证错误" -echo -e " 4 只代理常用端口: \033[36m$common_ports\033[0m ————用于屏蔽P2P流量" -echo -e " 5 过滤局域网mac地址: \033[36m$mac_return\033[0m ————列表内设备不走代理" -echo -e " 6 不使用本地DNS服务: \033[36m$dns_over\033[0m ————防止redir-host模式的dns污染" -echo ----------------------------------------------- -echo -e " 9 \033[32m重启\033[0mclash服务" -echo -e " 0 返回上级菜单 \033[0m" -echo ----------------------------------------------- -read -p "请输入对应数字 > " num -if [[ $num -le 9 ]] > /dev/null 2>&1; then - if [[ $num == 0 ]]; then - clashsh - elif [[ $num == 1 ]]; then + set_redir_mod(){ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "当前代理模式为:\033[47;30m $redir_mod \033[0m;Clash核心为:\033[47;30m $clashcore \033[0m" echo -e "\033[33m切换模式后需要手动重启clash服务以生效!\033[0m" @@ -606,14 +432,13 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then echo " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum clashcfg - elif [[ $num == 0 ]]; then + elif [ "$num" = 0 ]; then clashcfg - elif [[ $num == 1 ]]; then + elif [ "$num" = 1 ]; then redir_mod=Redir模式 - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then if [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m当前核心不支持开启Tun模式!请先切换clash核心!!!\033[0m" @@ -621,14 +446,14 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi redir_mod=Tun模式 dns_mod=fake-ip - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then if [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m当前核心不支持开启Tun模式!请先切换clash核心!!!\033[0m" clashcfg fi redir_mod=混合模式 - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then redir_mod=纯净模式 echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[32m已经设置为纯净模式!\033[0m" @@ -641,8 +466,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then source $clashdir/getdate.sh && setpac fi else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum clashcfg fi sed -i '/redir_mod*/'d $ccfg @@ -651,9 +475,8 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then sed -i "1i\dns_mod=$dns_mod" $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[36m已设为 $redir_mod !!\033[0m" - clashcfg - - elif [[ $num == 2 ]]; then + } + set_dns_mod(){ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "当前DNS运行模式为:\033[47;30m $dns_mod \033[0m" echo -e "\033[33m切换模式后需要手动重启clash服务以生效!\033[0m" @@ -665,19 +488,17 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then echo " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum clashcfg - elif [[ $num == 0 ]]; then + elif [ "$num" = 0 ]; then clashcfg - elif [[ $num == 1 ]]; then + elif [ "$num" = 1 ]; then dns_mod=fake-ip - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then dns_mod=redir_host redir_mod=Redir模式 else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum clashcfg fi sed -i '/dns_mod*/'d $ccfg @@ -686,9 +507,44 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then sed -i "1i\redir_mod=$redir_mod" $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" + } + + #获取设置默认显示 + [ -z "$skip_cert" ] && skip_cert=已开启 + [ -z "$common_ports" ] && common_ports=已开启 + [ -z "$dns_mod" ] && dns_mod=redir_host + [ -z "$dns_over" ] && dns_over=已开启 + [ -z "$(cat $clashdir/mac)" ] && mac_return=未开启 || mac_return=已启用 + # + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[30;47m欢迎使用功能设置菜单:\033[0m" + echo -e "\033[32m修改配置后请手动重启clash服务!\033[0m" + echo ----------------------------------------------- + echo -e " 1 切换Clash运行模式: \033[36m$redir_mod\033[0m" + echo -e " 2 切换DNS运行模式: \033[36m$dns_mod\033[0m" + echo -e " 3 跳过本地证书验证: \033[36m$skip_cert\033[0m ————解决节点证书验证错误" + echo -e " 4 只代理常用端口: \033[36m$common_ports\033[0m ————用于屏蔽P2P流量" + echo -e " 5 过滤局域网mac地址: \033[36m$mac_return\033[0m ————列表内设备不走代理" + echo -e " 6 不使用本地DNS服务: \033[36m$dns_over\033[0m ————防止redir-host模式的dns污染" + echo ----------------------------------------------- + echo -e " 9 \033[32m重启\033[0mclash服务" + echo -e " 0 返回上级菜单 \033[0m" + echo ----------------------------------------------- + read -p "请输入对应数字 > " num + if [ -z "$num" ]; then + echoerrornum + clashsh + elif [ "$num" = 0 ]; then + clashsh + elif [ "$num" = 1 ]; then + set_redir_mod + clashcfg + + elif [ "$num" = 2 ]; then + set_dns_mod clashcfg - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then sed -i '/skip_cert*/'d $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$skip_cert" = "未开启" ] > /dev/null 2>&1; then @@ -702,7 +558,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi clashcfg - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then sed -i '/common_ports*/'d $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$common_ports" = "未开启" ] > /dev/null 2>&1; then @@ -716,10 +572,10 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi clashcfg - elif [[ $num == 5 ]]; then + elif [ "$num" = 5 ]; then macfilter - elif [[ $num == 6 ]]; then + elif [ "$num" = 6 ]; then sed -i '/dns_over*/'d $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$dns_over" = "未开启" ] > /dev/null 2>&1; then @@ -736,49 +592,45 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi clashcfg - elif [[ $num == 9 ]]; then + elif [ "$num" = 9 ]; then clashstart clashsh else - echo -e "\033[31m暂未支持的选项!\033[0m" - clashcfg + echoerrornum + clashsh fi -else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - clashsh -fi -exit; } clashadv(){ -#获取设置默认显示 -[ -z "$modify_yaml" ] && modify_yaml=未开启 -[ -z "$ipv6_support" ] && ipv6_support=未开启 -[ -z "$start_old" ] && start_old=未开启 -[ -z "$local_proxy" ] && local_proxy=未开启 -# -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[30;47m欢迎使用进阶模式菜单:\033[0m" -echo -e "\033[33m如您不是很了解clash的运行机制,请勿更改!\033[0m" -echo -e "\033[32m修改配置后请手动重启clash服务!\033[0m" -echo ----------------------------------------------- -echo -e " 1 使用自定义配置: \033[36m$modify_yaml\033[0m ————不使用内置规则修饰config.yaml" -echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性功能,可能不稳定" -echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务" -echo -e " 4 代理本机流量: \033[36m$local_proxy\033[0m ————使用环境变量或者PAC配置本机代理" -echo -e " 5 手动指定clash运行端口及秘钥" -echo -e " 6 手动配置内置DNS服务" -echo ----------------------------------------------- -echo -e " 8 \033[31m重置\033[0m配置文件" -echo -e " 9 \033[32m重启\033[0mclash服务" -echo -e " 0 返回上级菜单 \033[0m" -echo ----------------------------------------------- -read -p "请输入对应数字 > " num -if [[ $num -le 9 ]] > /dev/null 2>&1; then - if [[ $num == 0 ]]; then + #获取设置默认显示 + [ -z "$modify_yaml" ] && modify_yaml=未开启 + [ -z "$ipv6_support" ] && ipv6_support=未开启 + [ -z "$start_old" ] && start_old=未开启 + [ -z "$local_proxy" ] && local_proxy=未开启 + # + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[30;47m欢迎使用进阶模式菜单:\033[0m" + echo -e "\033[33m如您不是很了解clash的运行机制,请勿更改!\033[0m" + echo -e "\033[32m修改配置后请手动重启clash服务!\033[0m" + echo ----------------------------------------------- + echo -e " 1 使用自定义配置: \033[36m$modify_yaml\033[0m ————不使用内置规则修饰config.yaml" + echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性功能,可能不稳定" + echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务" + echo -e " 4 代理本机流量: \033[36m$local_proxy\033[0m ————使用环境变量或者PAC配置本机代理" + echo -e " 5 手动指定clash运行端口及秘钥" + echo -e " 6 手动配置内置DNS服务" + echo ----------------------------------------------- + echo -e " 8 \033[31m重置\033[0m配置文件" + echo -e " 9 \033[32m重启\033[0mclash服务" + echo -e " 0 返回上级菜单 \033[0m" + echo ----------------------------------------------- + read -p "请输入对应数字 > " num + if [ -z "$num" ]; then + echoerrornum + clashsh + elif [ "$num" = 0 ]; then clashsh - elif [[ $num == 1 ]]; then + elif [ "$num" = 1 ]; then sed -i '/modify_yaml*/'d $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$modify_yaml" = "未开启" ] > /dev/null 2>&1; then @@ -795,7 +647,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi clashadv - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then sed -i '/ipv6_support*/'d $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$ipv6_support" = "未开启" ] > /dev/null 2>&1; then @@ -811,7 +663,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi clashadv - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then sed -i '/start_old*/'d $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$start_old" = "未开启" ] > /dev/null 2>&1; then @@ -829,32 +681,33 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi clashadv - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then sed -i '/local_proxy*/'d $ccfg echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$local_proxy" = "未开启" ] > /dev/null 2>&1; then sed -i "1i\local_proxy=已开启" $ccfg local_proxy=已开启 - $clashdir/start.sh set_proxy $mix_port $dbdir + $clashdir/start.sh set_proxy $mix_port $hostdir echo -e "\033[32m已经成功配置本机代理~\033[0m" echo -e "\033[36m如未生效,请重新启动终端或重新连接SSH!\033[0m" else sed -i "1i\local_proxy=未开启" $ccfg local_proxy=未开启 $clashdir/start.sh unset_proxy - echo -e "\033[33m已经停用本机代理规则!!\033[0m" + echo -e "\033[33m已经停用本机代理规则!!\033[0m" + echo -e "\033[36m如未生效,请重新启动终端或重新连接SSH!\033[0m" fi sleep 1 clashadv - elif [[ $num == 5 ]]; then + elif [ "$num" = 5 ]; then setport clashadv - elif [[ $num == 6 ]]; then + elif [ "$num" = 6 ]; then setdns clashadv - elif [[ $num == 8 ]]; then + elif [ "$num" = 8 ]; then read -p "确认重置配置文件?(1/0) > " res if [ "$res" = "1" ];then echo "versionsh_l=$versionsh_l" > $ccfg @@ -865,292 +718,185 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi clashadv - elif [[ $num == 9 ]]; then + elif [ "$num" = 9 ]; then clashstart + sleep 1 clashsh else - echo -e "\033[31m暂未支持的选项!\033[0m" + echoerrornum clashsh fi -else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - clashsh -fi -} -checkupdate(){ -if [ -z "$release_new" ];then - if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then - release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 --connect-timeout 5 -m 5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') - update_url=$update_url@$release_new - fi - curl -skL --connect-timeout 5 -m 5 $update_url/bin/version > /tmp/clashversion - source /tmp/clashversion - [ -z "$release_new" ] && release_new=$versionsh -fi -} -update(){ -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[33m正在检查更新!\033[0m" -checkupdate -[ "$clashcore" = "clash" ] && clash_n=$clash_v || clash_n=$clashpre_v -echo -e "\033[30;47m欢迎使用更新功能:\033[0m" -echo ----------------------------------------------- -echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh\033[0m" -echo -e " 2 切换\033[33mclash核心 \033[33m$clashv\033[0m > \033[32m$clash_n\033[0m" -echo -e " 3 更新\033[32mGeoIP数据库 \033[33m$Geo_v\033[0m > \033[32m$GeoIP_v\033[0m" -echo -e " 4 安装本地\033[35mDashboard\033[0m面板" -echo -e " 5 生成本地PAC文件(需先安装本地面板)" -echo ----------------------------------------------- -echo -e " 7 切换\033[36m安装源\033[0m地址" -echo -e " 8 鸣谢" -echo -e " 9 \033[31m卸载\033[34mShellClash\033[0m" -echo -e " 0 返回上级菜单" -echo ----------------------------------------------- -read -p "请输入对应数字 > " num -if [[ $num -le 9 ]] > /dev/null 2>&1; then - if [[ $num == 0 ]]; then - clashsh - - elif [[ $num == 1 ]]; then - source $clashdir/getdate.sh - getsh - - elif [[ $num == 2 ]]; then - source $clashdir/getdate.sh - getcore - - elif [[ $num == 3 ]]; then - source $clashdir/getdate.sh - getgeo - update - - elif [[ $num == 4 ]]; then - source $clashdir/getdate.sh - getdb - - elif [[ $num == 5 ]]; then - source $clashdir/getdate.sh - setpac - update - - elif [[ $num == 7 ]]; then - source $clashdir/getdate.sh - setserver - - elif [[ $num == 8 ]]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "感谢:\033[32mClash \033[0m作者\033[36m Dreamacro\033[0m 项目地址:\033[32mhttps://github.com/Dreamacro/clash\033[0m" - echo -e "感谢:\033[32msubconverter \033[0m作者\033[36m tindy2013\033[0m 项目地址:\033[32mhttps://github.com/tindy2013/subconverter\033[0m" - echo -e "感谢:\033[32malecthw提供的GeoIP数据库\033[0m 项目地址:\033[32mhttps://github.com/alecthw/mmdb_china_ip_list\033[0m" - echo -e "感谢:\033[32m更多的帮助过我的人!\033[0m" - update - - elif [[ $num == 9 ]]; then - read -p "确认卸载ShellClash?(警告:该操作不可逆!)[1/0] " res - if [ "$res" = '1' ]; then - $clashdir/start.sh stop - rm -rf $clashdir - rm -rf /etc/init.d/clash - rm -rf /etc/systemd/system/clash.service - rm -rf /usr/lib/systemd/system/clash.service - rm -rf /www/clash - sed -i '/alias clash=*/'d /etc/profile - sed -i '/export clashdir=*/'d /etc/profile - sed -i '/http*_proxy/'d /etc/profile - sed -i '/HTTP*_PROXY/'d /etc/profile - source /etc/profile > /dev/null 2>&1 - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo 已卸载ShellClash相关文件!有缘再会! - exit - fi - echo -e "\033[31m操作已取消!\033[0m" - exit; - else - echo -e "\033[31m暂未支持的选项!\033[0m" - update - fi -else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - clashsh -fi -exit; } clashcron(){ setcron(){ - echo ----------------------------------------------- - echo -e " 正在设置:\033[32m$cronname\033[0m定时任务" - echo -e " 输入 1-7 对应\033[33m每周相应天\033[0m运行" - echo -e " 输入 8 设为\033[33m每天定时\033[0m运行" - echo -e " 输入 1,3,6 代表\033[36m每周1,3,6\033[0m运行(注意用小写逗号分隔)" - echo ----------------------------------------------- - echo -e " 输入 9 \033[31m删除定时任务\033[0m" - echo -e " 输入 0 返回上级菜单" - echo ----------------------------------------------- - read -p "请输入对应数字 > " num - if [ -z "$num" ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - clashcron - elif [[ $num == 0 ]]; then - clashcron - elif [[ $num == 9 ]]; then - sed -i /$cronname/d $cronpath - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m定时任务:$cronname已删除!\033[0m" - clashcron - elif [[ $num == 8 ]]; then - week='*' - week1=每天 - echo 已设为每天定时运行! - else - week=$num - week1=每周$week - echo 已设为每周 $num 运行! - fi - #设置具体时间 - echo ----------------------------------------------- - read -p "请输入小时(0-23) > " num - if [ -z "$num" ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - setcron - elif [ $num -gt 23 ] || [ $num -lt 0 ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - setcron - else - hour=$num - fi - echo ----------------------------------------------- - read -p "请输入分钟(0-60) > " num - if [ -z "$num" ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - setcron - elif [ $num -gt 60 ] || [ $num -lt 0 ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - setcron - else - min=$num - fi - echo ----------------------------------------------- - echo 将在$week1的$hour点$min分$cronname(旧的任务会被覆盖) - read -p "是否确认添加定时任务?(1/0) > " res - if [ "$res" = '1' ]; then + echo ----------------------------------------------- + echo -e " 正在设置:\033[32m$cronname\033[0m定时任务" + echo -e " 输入 1-7 对应\033[33m每周相应天\033[0m运行" + echo -e " 输入 8 设为\033[33m每天定时\033[0m运行" + echo -e " 输入 1,3,6 代表\033[36m每周1,3,6\033[0m运行(注意用小写逗号分隔)" + echo ----------------------------------------------- + echo -e " 输入 9 \033[31m删除定时任务\033[0m" + echo -e " 输入 0 返回上级菜单" + echo ----------------------------------------------- + read -p "请输入对应数字 > " num + if [ -z "$num" ]; then + echoerrornum + clashcron + elif [ "$num" = 0 ]; then + clashcron + elif [ "$num" = 9 ]; then sed -i /$cronname/d $cronpath - echo "$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname" >> $cronpath echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m定时任务已添加!!!\033[0m" - chmod 600 $cronpath #修改权限 + echo -e "\033[31m定时任务:$cronname已删除!\033[0m" + clashcron + elif [ "$num" = 8 ]; then + week='*' + week1=每天 + echo 已设为每天定时运行! + else + week=$num + week1=每周$week + echo 已设为每周 $num 运行! fi - clashcron + #设置具体时间 + echo ----------------------------------------------- + read -p "请输入小时(0-23) > " num + if [ -z "$num" ]; then + echoerrornum + setcron + elif [ $num -gt 23 ] || [ $num -lt 0 ]; then + echoerrornum + setcron + else + hour=$num + fi + echo ----------------------------------------------- + read -p "请输入分钟(0-60) > " num + if [ -z "$num" ]; then + echoerrornum + setcron + elif [ $num -gt 60 ] || [ $num -lt 0 ]; then + echoerrornum + setcron + else + min=$num + fi + echo ----------------------------------------------- + echo 将在$week1的$hour点$min分$cronname(旧的任务会被覆盖) + read -p "是否确认添加定时任务?(1/0) > " res + if [ "$res" = '1' ]; then + sed -i /$cronname/d $cronpath + echo "$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname" >> $cronpath + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m定时任务已添加!!!\033[0m" + chmod 600 $cronpath #修改权限 + fi + clashcron } checkcron(){ - if [ -z "$cronpath" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[33m找不到定时任务配置文件,无法添加添加定时任务!" - echo -e "\033[0m请手动指定定时任务配置文件,文件位置可以通过【crontab -e】命令查看\033[0m" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - read -p "请输入crontab文件路径(输入回车返回主菜单) > " path - if [ -z "$path" ];then - clashsh - elif [ -f $path ];then - cronpath=$path - sed -i '/cronpath*/'d $ccfg - sed -i "1i\cronpath=\'$cronpath\'" $ccfg - else - echo -e "\033[33m输入的路径不正确,请重新输入!\033[0m" - checkcron + if [ -z "$cronpath" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[33m找不到定时任务配置文件,无法添加添加定时任务!" + echo -e "\033[0m请手动指定定时任务配置文件,文件位置可以通过【crontab -e】命令查看\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + read -p "请输入crontab文件路径(输入回车返回主菜单) > " path + if [ -z "$path" ];then + clashsh + elif [ -f $path ];then + cronpath=$path + sed -i '/cronpath*/'d $ccfg + sed -i "1i\cronpath=\'$cronpath\'" $ccfg + else + echo -e "\033[33m输入的路径不正确,请重新输入!\033[0m" + checkcron + fi fi - fi } -#定时任务菜单 -checkcron #检测定时任务文件 -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[30;47m欢迎使用定时任务功能:\033[0m" -echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" -echo ----------------------------------------------- -echo -e "\033[33m已添加的定时任务:\033[36m" -cat $cronpath | grep -oE ' #.*' -echo -e "\033[0m"----------------------------------------------- -echo -e " 1 设置\033[33m定时重启\033[0mclash服务" -echo -e " 2 设置\033[31m定时停止\033[0mclash服务" -echo -e " 3 设置\033[32m定时开启\033[0mclash服务" -echo -e " 4 设置\033[33m定时更新\033[0m订阅并重启服务" -echo ----------------------------------------------- -echo -e " 0 返回上级菜单" -read -p "请输入对应数字 > " num -if [ -z "$num" ]; then + #定时任务菜单 + checkcron #检测定时任务文件 echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - clashsh - -elif [[ $num == 0 ]]; then - clashsh - -elif [[ $num == 1 ]]; then - cronname=重启clash服务 - cronset="$clashdir/start.sh restart" - setcron -elif [[ $num == 2 ]]; then - cronname=停止clash服务 - cronset="$clashdir/start.sh stop" - setcron -elif [[ $num == 3 ]]; then - cronname=开启clash服务 - cronset="$clashdir/start.sh start" - setcron -elif [[ $num == 4 ]]; then - cronname=更新订阅链接 - cronset="$clashdir/start.sh getyaml" - setcron - -else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - clashsh -fi + echo -e "\033[30;47m欢迎使用定时任务功能:\033[0m" + echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" + echo ----------------------------------------------- + echo -e "\033[33m已添加的定时任务:\033[36m" + cat $cronpath | grep -oE ' #.*' + echo -e "\033[0m"----------------------------------------------- + echo -e " 1 设置\033[33m定时重启\033[0mclash服务" + echo -e " 2 设置\033[31m定时停止\033[0mclash服务" + echo -e " 3 设置\033[32m定时开启\033[0mclash服务" + echo -e " 4 设置\033[33m定时更新\033[0m订阅并重启服务" + echo ----------------------------------------------- + echo -e " 0 返回上级菜单" + read -p "请输入对应数字 > " num + if [ -z "$num" ]; then + echoerrornum + clashsh + + elif [ "$num" = 0 ]; then + clashsh + + elif [ "$num" = 1 ]; then + cronname=重启clash服务 + cronset="$clashdir/start.sh restart" + setcron + elif [ "$num" = 2 ]; then + cronname=停止clash服务 + cronset="$clashdir/start.sh stop" + setcron + elif [ "$num" = 3 ]; then + cronname=开启clash服务 + cronset="$clashdir/start.sh start" + setcron + elif [ "$num" = 4 ]; then + cronname=更新订阅链接 + cronset="$clashdir/start.sh getyaml" + setcron + + else + echoerrornum + clashsh + fi } clashsh(){ -############################# -getconfig -############################# -echo -e " 1 \033[32m启动/重启\033[0mclash服务" -echo -e " 2 clash\033[33m功能设置\033[0m" -echo -e " 3 \033[31m停止\033[0mclash服务" -echo -e " 4 $auto1" -echo -e " 5 设置\033[33m定时任务\033[0m$cronoff" -echo -e " 6 导入\033[32m配置文件\033[0m" -echo -e " 7 clash\033[31m进阶设置\033[0m" -echo -e " 8 \033[35m测试菜单\033[0m" -echo -e " 9 \033[36m更新/卸载\033[0m" -echo ----------------------------------------------- -echo -e " 0 \033[0m退出脚本\033[0m" -read -p "请输入对应数字 > " num -if [[ $num -le 9 ]] > /dev/null 2>&1; then - if [[ $num == 0 ]]; then + ############################# + getconfig + ############################# + echo -e " 1 \033[32m启动/重启\033[0mclash服务" + echo -e " 2 clash\033[33m功能设置\033[0m" + echo -e " 3 \033[31m停止\033[0mclash服务" + echo -e " 4 $auto1" + echo -e " 5 设置\033[33m定时任务\033[0m$cronoff" + echo -e " 6 导入\033[32m配置文件\033[0m" + echo -e " 7 clash\033[31m进阶设置\033[0m" + echo -e " 8 \033[35m测试菜单\033[0m" + echo -e " 9 \033[36m更新/卸载\033[0m" + echo ----------------------------------------------- + echo -e " 0 \033[0m退出脚本\033[0m" + read -p "请输入对应数字 > " num + if [ -z "$num" ];then + echoerrornum exit; - - elif [[ $num == 1 ]]; then - + + elif [ "$num" = 0 ]; then + exit; + + elif [ "$num" = 1 ]; then clashstart - exit; + sleep 1 + clashsh - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then clashcfg - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then $clashdir/start.sh stop echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31mClash服务已停止!\033[0m" echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ exit; - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ "$start_old" = "已开启" ];then sed -i "/start_old*/d" $ccfg @@ -1174,31 +920,25 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi clashsh - elif [[ $num == 5 ]]; then + elif [ "$num" = 5 ]; then clashcron - elif [[ $num == 6 ]]; then - clashlink + elif [ "$num" = 6 ]; then + source $clashdir/getdate.sh && clashlink - elif [[ $num == 7 ]]; then + elif [ "$num" = 7 ]; then clashadv - elif [[ $num == 8 ]]; then + elif [ "$num" = 8 ]; then source $clashdir/getdate.sh && testcommand - elif [[ $num == 9 ]]; then - update + elif [ "$num" = 9 ]; then + source $clashdir/getdate.sh && update else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum + exit; fi - exit 1 -else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" -fi -exit 1 } [ -z "$1" ] && clashsh diff --git a/scripts/getdate.sh b/scripts/getdate.sh index 025aad3..1af6174 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -1,6 +1,17 @@ #!/bin/bash # Copyright (C) Juewuy +webget(){ + [ -n "$(pidof clash)" ] && export http_proxy="http:/127.0.0.1:$mix_port" #设置临时http代理 + if curl --version > /dev/null 2>&1;then + result=$(curl -w %{http_code} --connect-timeout 5 -# -kLo $1 $2) + elif wget --version > /dev/null 2>&1;then + wget -q --show-progress --no-check-certificate --timeout=5 -O $1 $2 + [ $? -eq 0 ] && result="200" + else + echo 找不到curl或者wget,无法下载,请先安装相应依赖! + fi +} linkconfig(){ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" @@ -21,12 +32,11 @@ linkconfig(){ echo ----------------------------------------------- echo 0 返回上级菜单 read -p "请输入对应数字 > " num - if [ -z "$num" ] || [[ $num -gt 13 ]];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - elif [[ "$num" = "0" ]];then + if [ -z "$num" ] || [ "$num" -gt 13 ];then + echoerrornum + elif [ "$num" = 0 ];then echo - elif [[ $num -le 13 ]];then + elif [ "$num" -le 13 ];then #将对应标记值写入mark sed -i '/rule_link*/'d $ccfg sed -i "4i\rule_link="$num"" $ccfg @@ -48,12 +58,11 @@ linkserver(){ echo ----------------------------------------------- echo 0 返回上级菜单 read -p "请输入对应数字 > " num - if [ -z "$num" ] || [[ $num -gt 5 ]];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" - elif [[ "$num" = 0 ]];then + if [ -z "$num" ] || [ "$num" -gt 5 ];then + echoerrornum + elif [ "$num" = 0 ];then echo - elif [[ $num -le 5 ]];then + elif [ "$num" -le 5 ];then #将对应标记值写入mark sed -i '/server_link*/'d $ccfg sed -i "4i\server_link="$num"" $ccfg @@ -169,8 +178,7 @@ linkset(){ fi linkset else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum linkset fi clashlink @@ -196,7 +204,7 @@ getlink(){ url=`echo ${url/*\&url\=/""}` #将clash完整链接还原成单一链接 url=`echo ${url/\&config\=*/""}` #将clash完整链接还原成单一链接 url=`echo ${url//\&/\%26}` #将分隔符 & 替换成urlcode:%26 - if [[ "$test" != "" ]];then + if [ -n "$test" ];then if [ -z "$Url" ];then Url="$url" else @@ -205,7 +213,7 @@ getlink(){ i=$((i+1)) elif [ -z "$url" ];then [ -n "$Url" ] && linkset - elif [[ $url == 0 ]];then + elif [ "$url" = 0 ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m已撤销并删除所有已输入的链接!!!\033[0m" Url="" @@ -248,7 +256,7 @@ getlink2(){ start_over exit; fi - elif [[ $Https == 0 ]];then + elif [ "$Https" = 0 ];then clashlink else echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -257,8 +265,133 @@ getlink2(){ clashlink fi } +clashlink(){ + #获取订阅规则 + if [ -z "$rule_link" ]; then + sed -i "4i\rule_link=1" $ccfg + rule_link=1 + fi + #获取后端服务器地址 + if [ -z "$server_link" ]; then + sed -i "5i\server_link=1" $ccfg + server_link=1 + fi + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[30;47m 欢迎使用导入配置文件功能!\033[0m" + echo ----------------------------------------------- + echo -e " 1 在线导入\033[36m订阅\033[0m并生成Clash配置文件" + echo -e " 2 在线导入\033[33mClash\033[0m配置文件" + echo -e " 3 设置\033[31m节点过滤\033[0m关键字 \033[47;30m$exclude\033[0m" + echo -e " 4 设置\033[32m节点筛选\033[0m关键字 \033[47;30m$include\033[0m" + echo -e " 5 选取\033[33mClash配置规则\033[0m在线模版" + echo -e " 6 选择在线生成服务器-subconverter" + echo -e " 7 \033[36m还原\033[0m之前的配置文件" + echo -e " 8 \033[33m手动更新\033[0m配置文件" + echo -e " 9 设置\033[36m自动更新\033[0m配置文件" + echo ----------------------------------------------- + echo -e " 0 返回上级菜单" + read -p "请输入对应数字 > " num + if [ -z "$num" ];then + echoerrornum + clashsh + elif [ "$num" = 1 ];then + if [ -n "$Url" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[33m检测到已记录的订阅链接:\033[0m" + echo -e "\033[4;32m$Url\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + read -p "清空链接/追加导入?[1/0] > " res + if [ "$res" = '1' ]; then + Url="" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m链接已清空!\033[0m" + fi + fi + getlink + + elif [ "$num" = 2 ];then + if [ -n "$Url" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[33m检测到已记录的订阅链接:\033[0m" + echo -e "\033[4;32m$Url\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + read -p "清空链接/追加导入?[1/0] > " res + if [ "$res" = '1' ]; then + Url="" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m链接已清空!\033[0m" + fi + fi + getlink2 + + elif [ "$num" = 3 ];then + linkfilter + clashlink + + elif [ "$num" = 4 ];then + linkfilter2 + clashlink + + elif [ "$num" = 5 ];then + linkconfig + clashlink + + elif [ "$num" = 6 ];then + linkserver + clashlink + + elif [ "$num" = 7 ];then + yamlbak=$yaml.bak + if [ ! -f "$yaml".bak ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m没有找到配置文件的备份!\033[0m" + else + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e 备份文件共有"\033[32m`wc -l < $yamlbak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < $yaml`\033[0m"行内容 + read -p "确认还原配置文件?此操作不可逆![1/0] > " res + if [ "$res" = '1' ]; then + mv $yamlbak $yaml + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[32m配置文件已还原!请手动重启clash服务!\033[0m" + else + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m操作已取消!返回上级菜单!\033[0m" + fi + fi + clashsh + + elif [ "$num" = 8 ];then + if [ -z "$Url" -a -z "$Https" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m没有找到你的订阅链接!请先输入链接!\033[0m" + sleep 2 + clashlink + else + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[33m当前系统记录的订阅链接为:\033[0m" + echo -e "\033[4;32m$Url\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + read -p "确认更新配置文件?[1/0] > " res + if [ "$res" = '1' ]; then + $clashdir/start.sh getyaml + start_over + exit; + fi + clashlink + fi + + elif [ "$num" = 9 ];then + clashcron + + elif [ "$num" = 0 ];then + clashsh + else + echoerrornum + clashsh + fi +} gettar(){ - result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl) + result=$(curl -w %{http_code} -skLo /tmp/clashfm.tar.gz $tarurl) [ "$result" != "200" ] && echo "文件下载失败!" && exit 1 #解压 echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -362,18 +495,17 @@ getcore(){ echo 0 返回上级菜单 read -p "请输入对应数字 > " num if [ -z "$num" ]; then - echo ----------------------------------------------- - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum update - elif [[ $num == 0 ]]; then + elif [ "$num" = 0 ]; then update - elif [[ $num == 1 ]]; then + elif [ "$num" = 1 ]; then clashcore=clash version=$clash_v - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then clashcore=clashpre version=$clashpre_v - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then cpucore_list="armv5 armv7 armv8 386 amd64 mipsle-softfloat mipsle-hardfloat mips-softfloat" echo ----------------------------------------------- echo -e "\033[31m仅适合脚本无法正确识别核心或核心无法正常运行时使用!\033[0m" @@ -390,8 +522,7 @@ getcore(){ fi getcore else - echo ----------------------------------------------- - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum update fi #生成链接 @@ -406,7 +537,7 @@ getcore(){ echo -e "| \033[0m如长时间没有数据请用ctrl+c退出 |" echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m" #获取在线clash核心文件 - result=$(curl -w %{http_code} -kLo /tmp/clash.new $corelink) + result=$(curl -w %{http_code} -#kLo /tmp/clash.new $corelink) if [ "$result" != "200" ];then echo ----------------------------------------------- echo -e "\033[31m核心文件下载失败!\033[0m" @@ -434,7 +565,7 @@ getgeo(){ if [ "$res" = '1' ]; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo 正在从服务器获取数据库文件………… - result=$(curl -w %{http_code} -kLo /tmp/Country.mmdb $update_url/bin/Country.mmdb) + result=$(curl -w %{http_code} -#kLo /tmp/Country.mmdb $update_url/bin/Country.mmdb) if [ "$result" != "200" ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m文件下载失败!\033[0m" @@ -482,7 +613,7 @@ getdb(){ fi update else - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum update fi echo ----------------------------------------------- @@ -523,7 +654,7 @@ getdb(){ dblink="${update_url}/bin/${db_type}.tar.gz" echo ----------------------------------------------- echo 正在连接服务器获取安装文件………… - result=$(curl -w %{http_code} -kLo /tmp/clashdb.tar.gz $dblink) + result=$(curl -w %{http_code} -#kLo /tmp/clashdb.tar.gz $dblink) if [ "$result" != "200" ];then echo ----------------------------------------------- echo -e "\033[31m文件下载失败!\033[0m" @@ -544,8 +675,8 @@ getdb(){ fi [ "$dbdir" != "/www/clash" ] && $clashdir/start.sh restart #写入配置文件 - sed -i '/dbdir*/'d $ccfg - sed -i "1i\dbdir=\'$hostdir\'" $ccfg + sed -i '/hostdir*/'d $ccfg + sed -i "1i\hostdir=\'$hostdir\'" $ccfg echo ----------------------------------------------- echo -e "\033[32m面板安装成功!\033[0m" echo -e "\033[36m请使用\033[32;4mhttp://$host$hostdir\033[0;36m访问面板\033[0m" @@ -592,7 +723,7 @@ setpac(){ echo -e "PAC地址:\033[32mhttp://$host$dbdir/pac\033[0m" echo "使用教程:https://baike.baidu.com/item/PAC/16292100" sleep 2 - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then rm -rf $dbdir/pac echo ----------------------------------------------- echo -e "\033[33mPAC文件已清除!\033[0m" @@ -612,16 +743,15 @@ setserver(){ echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum update - elif [[ $num == 1 ]]; then + elif [ "$num" = 1 ]; then update_url='--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master' - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash' - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then update_url='-x '$authentication'@127.0.0.1:'$mix_port' https://raw.githubusercontent.com/juewuy/ShellClash/master' - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ read -p "请输入个人源路径 > " update_url if [ -z "$update_url" ];then @@ -629,11 +759,10 @@ setserver(){ echo -e "\033[31m取消输入,返回上级菜单\033[0m" update fi - elif [[ $num == 9 ]]; then + elif [ "$num" = 9 ]; then update_url='http://192.168.31.30:8080/clash-for-Miwifi' else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum update fi #写入mark文件 @@ -644,6 +773,97 @@ setserver(){ release_new="" update } +checkupdate(){ +if [ -z "$release_new" ];then + if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then + release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 --connect-timeout 5 -m 5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') + update_url=$update_url@$release_new + fi + curl -skL --connect-timeout 5 -m 5 $update_url/bin/version > /tmp/clashversion + source /tmp/clashversion + [ -z "$release_new" ] && release_new=$versionsh +fi +} +update(){ + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[33m正在检查更新!\033[0m" + checkupdate + [ "$clashcore" = "clash" ] && clash_n=$clash_v || clash_n=$clashpre_v + echo -e "\033[30;47m欢迎使用更新功能:\033[0m" + echo ----------------------------------------------- + echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh\033[0m" + echo -e " 2 切换\033[33mclash核心 \033[33m$clashv\033[0m > \033[32m$clash_n\033[0m" + echo -e " 3 更新\033[32mGeoIP数据库 \033[33m$Geo_v\033[0m > \033[32m$GeoIP_v\033[0m" + echo -e " 4 安装本地\033[35mDashboard\033[0m面板" + echo -e " 5 生成本地PAC文件(需先安装本地面板)" + echo ----------------------------------------------- + echo -e " 7 切换\033[36m安装源\033[0m地址" + echo -e " 8 鸣谢" + echo -e " 9 \033[31m卸载\033[34mShellClash\033[0m" + echo -e " 0 返回上级菜单" + echo ----------------------------------------------- + read -p "请输入对应数字 > " num + if [ -z "$num" ]; then + echoerrornum + clashsh + elif [ "$num" = 0 ]; then + clashsh + elif [ "$num" = 1 ]; then + getsh + + elif [ "$num" = 2 ]; then + getcore + + elif [ "$num" = 3 ]; then + getgeo + update + + elif [ "$num" = 4 ]; then + getdb + + elif [ "$num" = 5 ]; then + setpac + update + + elif [ "$num" = 7 ]; then + setserver + + elif [ "$num" = 8 ]; then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "感谢:\033[32mClash \033[0m作者\033[36m Dreamacro\033[0m 项目地址:\033[32mhttps://github.com/Dreamacro/clash\033[0m" + echo -e "感谢:\033[32msubconverter \033[0m作者\033[36m tindy2013\033[0m 项目地址:\033[32mhttps://github.com/tindy2013/subconverter\033[0m" + echo -e "感谢:\033[32malecthw提供的GeoIP数据库\033[0m 项目地址:\033[32mhttps://github.com/alecthw/mmdb_china_ip_list\033[0m" + echo -e "感谢:\033[32myacd \033[0m作者\033[36m haishanh\033[0m 项目地址:\033[32mhttps://github.com/haishanh/yacd\033[0m" + echo -e "感谢:\033[32m更多的帮助过我的人!\033[0m" + sleep 2 + update + + elif [ "$num" = 9 ]; then + read -p "确认卸载ShellClash?(警告:该操作不可逆!)[1/0] " res + if [ "$res" = '1' ]; then + $clashdir/start.sh stop + rm -rf $clashdir + rm -rf /etc/init.d/clash + rm -rf /etc/systemd/system/clash.service + rm -rf /usr/lib/systemd/system/clash.service + rm -rf /www/clash + sed -i '/alias clash=*/'d /etc/profile + sed -i '/export clashdir=*/'d /etc/profile + sed -i '/http*_proxy/'d /etc/profile + sed -i '/HTTP*_PROXY/'d /etc/profile + source /etc/profile > /dev/null 2>&1 + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo 已卸载ShellClash相关文件!有缘再会! + exit + fi + echo -e "\033[31m操作已取消!\033[0m" + update + else + echoerrornum + clashsh + fi +exit; +} userguide(){ echo 欢迎使用ShellClash新手引导! checkupdate @@ -671,30 +891,29 @@ testcommand(){ echo " 0 返回上级目录!" read -p "请输入对应数字 > " num if [ -z "$num" ]; then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum clashsh - elif [[ $num == 0 ]]; then + elif [ "$num" = 0 ]; then clashsh - elif [[ $num == 1 ]]; then + elif [ "$num" = 1 ]; then $clashdir/start.sh stop echo ----------------------------------------------- $clashdir/clash -t -d $clashdir echo ----------------------------------------------- echo -e "\033[31m如有报错请截图后到TG群询问!!!\033[0m" exit; - elif [[ $num == 2 ]]; then + elif [ "$num" = 2 ]; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ netstat -ntulp |grep 53 echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "可以使用\033[44m netstat -ntulp |grep xxx \033[0m来查询任意(xxx)端口" exit; - elif [[ $num == 3 ]]; then + elif [ "$num" = 3 ]; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ openssl speed -multi 4 -evp aes-128-gcm echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ exit; - elif [[ $num == 4 ]]; then + elif [ "$num" = 4 ]; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ iptables -t nat -L PREROUTING --line-numbers echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -702,12 +921,12 @@ testcommand(){ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ iptables -t nat -L clash_dns --line-numbers exit; - elif [[ $num == 5 ]]; then + elif [ "$num" = 5 ]; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sed -n '1,40p' $yaml echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ exit; - elif [[ $num == 6 ]]; then + elif [ "$num" = 6 ]; then echo 注意:测试结果不保证一定准确! delay=`curl -kx ${authentication}@127.0.0.1:$mix_port -o /dev/null -s -w '%{time_starttransfer}' 'https://google.tw' & { sleep 3 ; kill $! & }` > /dev/null 2>&1 delay=`echo |awk "{print $delay*1000}"` > /dev/null 2>&1 @@ -718,11 +937,10 @@ testcommand(){ echo -e "\033[31m连接超时!请重试或检查节点配置!\033[0m" fi clashsh - elif [[ $num == 7 ]]; then + elif [ "$num" = 7 ]; then userguide else - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请输入正确的数字!\033[0m" + echoerrornum clashsh fi } \ No newline at end of file diff --git a/scripts/start.sh b/scripts/start.sh index 442424b..faa3217 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,172 +2,170 @@ # Copyright (C) Juewuy getconfig(){ -#加载环境变量 -[ -z "$clashdir" ] && source /etc/profile > /dev/null 2>&1 -ccfg=$clashdir/mark -#检查/读取标识文件 -[ ! -f $ccfg ]&& echo '#标识clash运行状态的文件,不明勿动!' >> $ccfg -source $ccfg -#默认设置 -[ -z "$skip_cert" ] && skip_cert=已开启 -[ -z "$common_ports" ] && common_ports=已开启 -[ -z "$dns_mod" ] && dns_mod=redir_host -[ -z "$dns_over" ] && dns_over=已开启 -[ -z "$modify_yaml" ] && modify_yaml=未开启 -[ -z "$ipv6_support" ] && ipv6_support=未开启 -[ -z "$start_old" ] && start_old=未开启 -[ -z "$local_proxy" ] && local_proxy=未开启 -[ -z "$mix_port" ] && mix_port=7890 -[ -z "$redir_port" ] && redir_port=7892 -[ -z "$db_port" ] && db_port=9999 -[ -z "$dns_port" ] && dns_port=1053 -[ -z "$dns_nameserver" ] && dns_nameserver='114.114.114.114, 223.5.5.5' -[ -z "$dns_fallback" ] && dns_fallback='1.0.0.1, 8.8.4.4' -#是否代理常用端口 -[ "$common_ports" = "已开启" ] && ports='-m multiport --dports 22,53,587,465,995,993,143,80,443 ' -} + #加载配置文件 + [ -z "$clashdir" ] && source /etc/profile > /dev/null 2>&1 + ccfg=$clashdir/mark + [ -f $ccfg ] && source $ccfg + #默认设置 + [ -z "$skip_cert" ] && skip_cert=已开启 + [ -z "$common_ports" ] && common_ports=已开启 + [ -z "$dns_mod" ] && dns_mod=redir_host + [ -z "$dns_over" ] && dns_over=已开启 + [ -z "$modify_yaml" ] && modify_yaml=未开启 + [ -z "$ipv6_support" ] && ipv6_support=未开启 + [ -z "$start_old" ] && start_old=未开启 + [ -z "$local_proxy" ] && local_proxy=未开启 + [ -z "$mix_port" ] && mix_port=7890 + [ -z "$redir_port" ] && redir_port=7892 + [ -z "$db_port" ] && db_port=9999 + [ -z "$dns_port" ] && dns_port=1053 + [ -z "$dns_nameserver" ] && dns_nameserver='114.114.114.114, 223.5.5.5' + [ -z "$dns_fallback" ] && dns_fallback='1.0.0.1, 8.8.4.4' + #是否代理常用端口 + [ "$common_ports" = "已开启" ] && ports='-m multiport --dports 53,587,465,995,993,143,80,443 ' + } getyaml(){ -#前后端订阅服务器地址索引,可在此处添加! -Server=`sed -n ""$server_link"p"< /dev/null 2>&1 -result=$(curl -w %{http_code} -kLo $yamlnew $Https) -if [ "$result" != "200" ];then + #前后端订阅服务器地址索引,可在此处添加! + Server=`sed -n ""$server_link"p"< /dev/null 2>&1 + result=$(curl -w %{http_code} -kLo $yamlnew $Https) + if [ "$result" != "200" ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m请尝试使用【导入节点/链接】功能!\033[0m" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - exit 1 - else - if [ "$retry" -ge 5 ];then - echo -e "\033[32m无法获取配置文件,请检查链接格式以及网络连接状态!\033[0m" + echo -e "\033[31m配置文件获取失败!\033[0m" + if [ -z "$markhttp" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m请尝试使用【导入节点/链接】功能!\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ exit 1 else - retry=$((retry+1)) - echo -e "\033[32m尝试使用其他服务器获取配置!\033[0m" - echo -e "\033[33m正在尝试第$retry次/共5次!\033[0m" - sed -i '/server_link=*/'d $ccfg - if [ "$server_link" -ge 5 ]; then - server_link=0 + if [ "$retry" -ge 5 ];then + echo -e "\033[32m无法获取配置文件,请检查链接格式以及网络连接状态!\033[0m" + exit 1 + else + retry=$((retry+1)) + echo -e "\033[32m尝试使用其他服务器获取配置!\033[0m" + echo -e "\033[33m正在尝试第$retry次/共5次!\033[0m" + sed -i '/server_link=*/'d $ccfg + if [ "$server_link" -ge 5 ]; then + server_link=0 + fi + server_link=$((server_link+1)) + sed -i "1i\server_link=$server_link" $ccfg + Https="" + getyaml fi - server_link=$((server_link+1)) - sed -i "1i\server_link=$server_link" $ccfg - Https="" - getyaml fi - fi -else - Https="" - #检测节点 - if [ -z "$(cat $yamlnew | grep 'server:' | grep -v 'nameserver')" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[33m获取到了配置文件,但似乎并不包含正确的节点信息!\033[0m" - echo ----------------------------------------------- - sed -n '1,30p' $yamlnew - echo ----------------------------------------------- - echo -e "\033[33m请检查如上配置文件信息:\033[0m" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - exit 1 - fi - #检测旧格式 - if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m已经停止对旧格式配置文件的支持!!!\033[0m" - echo -e "请使用新格式或者使用【导入节点/链接】功能!" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - exit 1 - fi - #检测不支持的加密协议 - if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[31m不支持chacha20加密,请更换节点加密协议!!!\033[0m" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - exit 1 - fi - #替换文件 - [ -f $yaml ] && mv $yaml $yaml.bak - mv $yamlnew $yaml - echo 配置文件已生成!正在启动clash使其生效! - #重启clash服务 - $0 stop - $0 start - sleep 1 - if [ -z "$(pidof clash)" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - if [ -f $yaml.bak ];then - $clashdir/start.sh stop - mv $yaml.bak $yaml - $0 start - echo -e "\033[31mclash服务启动失败!已还原配置文件并重启clash!\033[0m" - sleep 1 - [ -n "$(pidof clash)" ] && exit 0 + else + Https="" + #检测节点 + if [ -z "$(cat $yamlnew | grep 'server:' | grep -v 'nameserver')" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[33m获取到了配置文件,但似乎并不包含正确的节点信息!\033[0m" + echo ----------------------------------------------- + sed -n '1,30p' $yamlnew + echo ----------------------------------------------- + echo -e "\033[33m请检查如上配置文件信息:\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + exit 1 fi - echo -e "\033[31mclash服务启动失败!请查看报错信息!\033[0m" + #检测旧格式 + if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m已经停止对旧格式配置文件的支持!!!\033[0m" + echo -e "请使用新格式或者使用【导入节点/链接】功能!" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + exit 1 + fi + #检测不支持的加密协议 + if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m不支持chacha20加密,请更换节点加密协议!!!\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + exit 1 + fi + #替换文件 + [ -f $yaml ] && mv $yaml $yaml.bak + mv $yamlnew $yaml + echo 配置文件已生成!正在启动clash使其生效! + #重启clash服务 $0 stop - $clashdir/clash -t -d $clashdir - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - exit 1 + $0 start + sleep 1 + if [ -z "$(pidof clash)" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if [ -f $yaml.bak ];then + $clashdir/start.sh stop + mv $yaml.bak $yaml + $0 start + echo -e "\033[31mclash服务启动失败!已还原配置文件并重启clash!\033[0m" + sleep 1 + [ -n "$(pidof clash)" ] && exit 0 + fi + echo -e "\033[31mclash服务启动失败!请查看报错信息!\033[0m" + $0 stop + $clashdir/clash -t -d $clashdir + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + exit 1 + fi fi -fi } modify_yaml(){ ##########需要变更的配置########### -lan='allow-lan: true' -mode='mode: Rule' -log='log-level: info' -[ "$ipv6_support" = "已开启" ] && ipv6='ipv6: true' || ipv6='ipv6: false' -external="external-controller: 0.0.0.0:$db_port" -[ -d $clashdir/ui ] && db_ui=ui -[ "$redir_mod" != "Redir模式" ] && tun='tun: {enable: true, stack: system}' || tun='tun: {enable: false}' -exper='experimental: {ignore-resolve-fail: true, interface-name: en0}' -#dns配置 -[ "$dns_over" = "未开启" ] && dns_local=', 127.0.0.1:53' -if [ "$dns_mod" = "fake-ip" ];then - dns='dns: {enable: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, fake-ip-filter: ["*.lan", "time.windows.com", "time.nist.gov", "time.apple.com", "time.asia.apple.com", "*.ntp.org.cn", "*.openwrt.pool.ntp.org", "time1.cloud.tencent.com", "time.ustc.edu.cn", "pool.ntp.org", "ntp.ubuntu.com", "ntp.aliyun.com", "ntp1.aliyun.com", "ntp2.aliyun.com", "ntp3.aliyun.com", "ntp4.aliyun.com", "ntp5.aliyun.com", "ntp6.aliyun.com", "ntp7.aliyun.com", "time1.aliyun.com", "time2.aliyun.com", "time3.aliyun.com", "time4.aliyun.com", "time5.aliyun.com", "time6.aliyun.com", "time7.aliyun.com", "*.time.edu.cn", "time1.apple.com", "time2.apple.com", "time3.apple.com", "time4.apple.com", "time5.apple.com", "time6.apple.com", "time7.apple.com", "time1.google.com", "time2.google.com", "time3.google.com", "time4.google.com", "music.163.com", "*.music.163.com", "*.126.net", "musicapi.taihe.com", "music.taihe.com", "songsearch.kugou.com", "trackercdn.kugou.com", "*.kuwo.cn", "api-jooxtt.sanook.com", "api.joox.com", "joox.com", "y.qq.com", "*.y.qq.com", "streamoc.music.tc.qq.com", "mobileoc.music.tc.qq.com", "isure.stream.qqmusic.qq.com", "dl.stream.qqmusic.qq.com", "aqqmusic.tc.qq.com", "amobile.music.tc.qq.com", "*.xiami.com", "*.music.migu.cn", "music.migu.cn", "*.msftconnecttest.com", "*.msftncsi.com", "localhost.ptlogin2.qq.com", "*.*.*.srv.nintendo.net", "*.*.stun.playstation.net", "xbox.*.*.microsoft.com", "*.*.xboxlive.com", "proxy.golang.org"], nameserver: ['$dns_nameserver', 127.0.0.1:53], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}' -else - dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: ['$dns_nameserver$dns_local'], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}' -fi + lan='allow-lan: true' + mode='mode: Rule' + log='log-level: info' + [ "$ipv6_support" = "已开启" ] && ipv6='ipv6: true' || ipv6='ipv6: false' + external="external-controller: 0.0.0.0:$db_port" + [ -d $clashdir/ui ] && db_ui=ui + [ "$redir_mod" != "Redir模式" ] && tun='tun: {enable: true, stack: system}' || tun='tun: {enable: false}' + exper='experimental: {ignore-resolve-fail: true, interface-name: en0}' + #dns配置 + [ "$dns_over" = "未开启" ] && dns_local=', 127.0.0.1:53' + if [ "$dns_mod" = "fake-ip" ];then + dns='dns: {enable: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, fake-ip-filter: ["*.lan", "time.windows.com", "time.nist.gov", "time.apple.com", "time.asia.apple.com", "*.ntp.org.cn", "*.openwrt.pool.ntp.org", "time1.cloud.tencent.com", "time.ustc.edu.cn", "pool.ntp.org", "ntp.ubuntu.com", "ntp.aliyun.com", "ntp1.aliyun.com", "ntp2.aliyun.com", "ntp3.aliyun.com", "ntp4.aliyun.com", "ntp5.aliyun.com", "ntp6.aliyun.com", "ntp7.aliyun.com", "time1.aliyun.com", "time2.aliyun.com", "time3.aliyun.com", "time4.aliyun.com", "time5.aliyun.com", "time6.aliyun.com", "time7.aliyun.com", "*.time.edu.cn", "time1.apple.com", "time2.apple.com", "time3.apple.com", "time4.apple.com", "time5.apple.com", "time6.apple.com", "time7.apple.com", "time1.google.com", "time2.google.com", "time3.google.com", "time4.google.com", "music.163.com", "*.music.163.com", "*.126.net", "musicapi.taihe.com", "music.taihe.com", "songsearch.kugou.com", "trackercdn.kugou.com", "*.kuwo.cn", "api-jooxtt.sanook.com", "api.joox.com", "joox.com", "y.qq.com", "*.y.qq.com", "streamoc.music.tc.qq.com", "mobileoc.music.tc.qq.com", "isure.stream.qqmusic.qq.com", "dl.stream.qqmusic.qq.com", "aqqmusic.tc.qq.com", "amobile.music.tc.qq.com", "*.xiami.com", "*.music.migu.cn", "music.migu.cn", "*.msftconnecttest.com", "*.msftncsi.com", "localhost.ptlogin2.qq.com", "*.*.*.srv.nintendo.net", "*.*.stun.playstation.net", "xbox.*.*.microsoft.com", "*.*.xboxlive.com", "proxy.golang.org"], nameserver: ['$dns_nameserver', 127.0.0.1:53], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}' + else + dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: ['$dns_nameserver$dns_local'], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}' + fi ################################### yaml=$clashdir/config.yaml @@ -287,9 +285,6 @@ daemon(){ if [ -n "$cronpath" ];then echo '*/1 * * * * test -z "$(pidof clash)" && /etc/init.d/clash restart #clash保守模式守护进程' >> $cronpath chmod 600 $cronpath - else - echo 找不到定时任务配置文件,无法添加守护进程! - echo 请进入定时任务菜单手动指定系统定时任务文件路径!!! fi } web_save(){ @@ -326,9 +321,6 @@ web_save_auto(){ echo '*/10 * * * * test -n "$(pidof clash)" && /etc/init.d/clash web_save #每10分钟保存节点配置' >> $cronpath chmod 600 $cronpath fi - else - echo 找不到定时任务配置文件,无法添加守护进程! - echo 请进入定时任务菜单手动指定系统定时任务文件路径!!! fi } afstart(){ @@ -341,7 +333,7 @@ afstart(){ #标记启动时间 mark_time #设置本机代理 - [ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port $dbdir + [ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port $hostdir #启用面板配置自动保存 web_save_auto #后台还原面板配置