v1.0.0beta15.7

~优化了本机代理实现方式,增加了选项菜单
~优化了定时任务实现方式,适配更多设备
~优化了配置文件修饰方式
~优化了启动和关闭进程时的检测,修复错误
~优化了非root用户体验
~优化脚本结构
This commit is contained in:
juewuy
2020-10-28 13:49:45 +08:00
parent 335c466520
commit a0b31a4905
5 changed files with 42 additions and 32 deletions

Binary file not shown.

View File

@@ -62,7 +62,7 @@ gettar(){
echo 开始解压文件!
mkdir -p $clashdir > /dev/null
tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
[ $? -ne 0 ] && echo "文件解压失败!" && rm -rf /tmp/clashfm.tar.gz && exit 1
#初始化文件目录
[ -f "$clashdir/mark" ] || echo '#标识clash运行状态的文件不明勿动' > $clashdir/mark
#判断系统类型写入不同的启动文件
@@ -149,10 +149,13 @@ else
echo 安装已取消!!!
exit;
fi
echo 目标目录磁盘剩余:$(df -h $dir | awk '{print $4}' | sed 1d )
read -p "确认安装?(1/0) > " res
[ "$res" != "1" ] && setdir
clashdir=$dir/clash
if [ ! -w $dir ];then
$echo "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir
else
echo 目标目录磁盘剩余:$(df -h $dir | awk '{print $4}' | sed 1d )
read -p "确认安装?(1/0) > " res
[ "$res" = "1" ] && clashdir=$dir/clash || setdir
fi
}
#输出

View File

@@ -120,12 +120,17 @@ EOF
startover(){
echo -e "\033[32mclash服务已启动\033[0m"
if [ -n "$hostdir" ];then
echo -e "请使用\033[30;47m http://$host$hostdir \033[0m管理内置规则"
echo -e "请使用\033[4;32mhttp://$host$hostdir\033[0m管理内置规则"
else
echo -e "可使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "可使用\033[4;32mhttp://clash.razord.top\033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m $db_port \033[0m"
echo -e "推荐前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
fi
if [ "$redir_mod" = "纯净模式" ];then
echo -----------------------------------------------
echo -e "其他设备可以使用PAC配置连接\033[4;32mhttp://$host:$db_port/ui/pac\033[0m"
echo -e "或者使用HTTP/SOCK5方式连接IP{\033[36m$host\033[0m}端口{\033[36m$mix_port\033[0m}"
fi
}
clashstart(){
#检查clash核心

View File

@@ -152,7 +152,7 @@ linkset(){
Https=""
#获取在线yaml文件
$clashdir/start.sh getyaml
start_over
startover
exit;
elif [ "$num" = '2' ]; then
linkfilter
@@ -246,7 +246,7 @@ getlink2(){
setconfig Https \'$Https\'
#获取在线yaml文件
$clashdir/start.sh getyaml
start_over
startover
exit;
fi
elif [ "$Https" = 0 ];then
@@ -359,7 +359,7 @@ clashlink(){
read -p "确认更新配置文件?[1/0] > " res
if [ "$res" = '1' ]; then
$clashdir/start.sh getyaml
start_over
startover
exit;
fi
clashlink
@@ -384,7 +384,7 @@ gettar(){
echo 开始解压文件!
mkdir -p $clashdir > /dev/null
tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
[ $? -ne 0 ] && echo "文件解压失败!" && rm -rf /tmp/clashfm.tar.gz && exit 1
#初始化文件目录
[ -f "$clashdir/mark" ] || echo '#标识clash运行状态的文件不明勿动' > $clashdir/mark
#判断系统类型写入不同的启动文件
@@ -532,7 +532,7 @@ getcore(){
getcore
else
echo -e "\033[32m$clashcore核心下载成功,正在替换!\033[0m"
mv /tmp/clash.new $clashdir/clash
mv -f /tmp/clash.new $clashdir/clash
chmod 777 $clashdir/clash #授予权限
setconfig clashcore $clashcore
setconfig clashv $version
@@ -559,7 +559,7 @@ getgeo(){
else
echo -----------------------------------------------
echo -e "\033[32mGeoIP数据库文件下载成功\033[0m"
mv /tmp/Country.mmdb $clashdir/Country.mmdb
mv -f /tmp/Country.mmdb $clashdir/Country.mmdb
setconfig Geo_v $GeoIP_v
rm -rf /tmp/clashversion
fi
@@ -648,7 +648,7 @@ getdb(){
echo -e "\033[33m下载成功正在解压文件\033[0m"
mkdir -p $dbdir > /dev/null
tar -zxvf "/tmp/clashdb.tar.gz" -C $dbdir > /dev/null
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
[ $? -ne 0 ] && echo "文件解压失败!" && rm -rf /tmp/clashfm.tar.gz && exit 1
#修改默认host和端口
if [ "$db_type" = "clashdb" ];then
sed -i "s/127.0.0.1/${host}/g" $dbdir/js/*.js

View File

@@ -35,11 +35,12 @@ logger(){
}
cronset(){
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
crontab -l > /tmp/conf
sed -i "/$1/d" /tmp/conf
echo "$2" >> /tmp/conf
crontab /tmp/conf
rm -f /tmp/conf
crondir=/tmp/cron_$USER
crontab -l > $crondir
sed -i "/$1/d" $crondir
echo "$2" >> $crondir
crontab $crondir
rm -f $crondir
}
mark_time(){
start_time=`date +%s`
@@ -90,7 +91,7 @@ EOF`
echo -e "-----------------------------------------------\033[0m"
#获取在线yaml文件
yaml=$clashdir/config.yaml
yamlnew=/tmp/clash_config.yaml
yamlnew=/tmp/clash_config_$USER.yaml
rm -rf $yamlnew
source $clashdir/getdate.sh && webget $yamlnew $Https
if [ "$result" != "200" ];then
@@ -189,16 +190,17 @@ modify_yaml(){
fi
###################################
yaml=$clashdir/config.yaml
tmp_clash=/tmp/clash_$USER
#预删除需要添加的项目
a=$(grep -n "port:" $yaml | head -1 | cut -d ":" -f 1)
b=$(grep -n "^prox" $yaml | head -1 | cut -d ":" -f 1)
b=$((b-1))
mkdir -p /tmp/clash > /dev/null
sed "${a},${b}d" $yaml > /tmp/clash/rule.yaml
mkdir -p $tmp_clash > /dev/null
sed "${a},${b}d" $yaml > $tmp_clash/rule.yaml
#跳过本地tls证书验证
[ "$skip_cert" = "已开启" ] && sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' /tmp/clash/rule.yaml
[ "$skip_cert" = "已开启" ] && sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' $tmp_clash/rule.yaml
#添加配置
cat > /tmp/clash/set.yaml <<EOF
cat > $tmp_clash/set.yaml <<EOF
mixed-port: $mix_port
redir-port: $redir_port
authentication: ["$authentication"]
@@ -213,11 +215,11 @@ $tun
$exper
$dns
EOF
cat /tmp/clash/set.yaml /tmp/clash/rule.yaml > /tmp/clash/config.yaml
cmp -s /tmp/clash/config.yaml $yaml
[ "$?" != 0 ] && mv -f /tmp/clash/config.yaml $yaml || rm -f /tmp/clash/config.yaml
rm -f /tmp/clash/set.yaml
rm -f /tmp/clash/rule.yaml
cat $tmp_clash/set.yaml $tmp_clash/rule.yaml > $tmp_clash/config.yaml
cmp -s $tmp_clash/config.yaml $yaml
[ "$?" != 0 ] && mv -f $tmp_clash/config.yaml $yaml || rm -f $tmp_clash/config.yaml
rm -f $tmp_clash/set.yaml
rm -f $tmp_clash/rule.yaml
}
#设置路由规则
start_redir(){
@@ -331,10 +333,10 @@ web_save(){
fi
}
#使用get_save获取面板节点设置
get_save http://localhost:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g'| sed 's/"//g' > /tmp/clash_web_save
get_save http://localhost:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g'| sed 's/"//g' > /tmp/clash_web_save_$USER
#对比文件,如果有变动则写入磁盘,否则清除缓存
cmp -s /tmp/clash_web_save $clashdir/web_save
[ "$?" = 0 ] && rm -rf /tmp/clash_web_save || mv -f /tmp/clash_web_save $clashdir/web_save
cmp -s /tmp/clash_web_save_$USER $clashdir/web_save
[ "$?" = 0 ] && rm -rf /tmp/clash_web_save_$USER || mv -f /tmp/clash_web_save_$USER $clashdir/web_save
}
web_restore(){
put_save(){