From 0abe34884e1b3b783ec41547e04d0b51cfd7e19b Mon Sep 17 00:00:00 2001 From: juewuy Date: Sun, 20 Sep 2020 12:25:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install_test.sh | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 install_test.sh diff --git a/install_test.sh b/install_test.sh new file mode 100644 index 0000000..b8d5019 --- /dev/null +++ b/install_test.sh @@ -0,0 +1,105 @@ +#! /bin/bash +# Copyright (C) Juewuy + +echo "***********************************************" +echo "** 欢迎使用 **" +echo "** ShellClash **" +echo "** by Juewuy **" +echo "***********************************************" + +url="http://192.168.31.30:8080/clash-for-Miwifi" +url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master" + +#release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.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') +[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}') +[ -z "$release_new" ] && echo "无法连接服务器!" && exit +echo -e "最新版本:\033[32m$release_new\033[0m" +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo -e "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" +echo -e "\033[37m支持各种基于openwrt的路由器设备" +echo -e "\033[33m有限兼容debian、centos等Linux系统\033[0m" +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo -e "\033[32m 1 在默认目录(/etc)安装ShellClash" +echo -e "\033[33m 2 手动设置安装目录(不明勿用!)" +echo -e "\033[0m 0 退出安装" +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +read -p "请输入相应数字 > " num + +if [ -z $num ];then + echo 安装已取消 + exit; +elif [ "$num" = "1" ];then + dir=/etc +elif [ "$num" = "2" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo '可用路径 剩余空间:' + df -h | awk '{print $6,$2}'| sed 1d + echo '路径是必须带 / 的格式,写入虚拟内存(/tmp,/sys,..)的文件会在重启后消失!!!' + read -p "请输入自定义路径 > " dir + if [ -z $dir ];then + echo 路径错误!已取消安装! + exit; + fi +else + echo 安装已取消 + exit; +fi +#下载文件包 +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo 开始从服务器获取安装文件! +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#tarurl=$url@$release_new/bin/clashfm.tar.gz +tarurl=$url/bin/clashfm.tar.gz +if command -v curl &> /dev/null; then + result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl) +else $result + wget-ssl -q --no-check-certificate --tries=1 --timeout=10 -O /tmp/clashfm.tar.gz $tarurl + [ $? -eq 0 ] && result="200" +fi +[ "$result" != "200" ] && echo "文件下载失败!" && exit 1 +#解压 +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo 开始解压文件! +mkdir -p $dir/clash > /dev/null +tar -zxvf '/tmp/clashfm.tar.gz' -C $dir/clash/ +[ $? -ne 0 ] && echo "文件解压失败!" && exit 1 +#判断系统类型写入不同的启动文件 +if [ -n "$(cat /proc/version | grep -i openwrt)" ];then + mv $dir/clash/clashservice /etc/init.d/clash #将rc服务文件移动到系统目录 + chmod 777 /etc/init.d/clash #授予权限 + rm -rf $dir/clash/clash.service +else + [ -d /etc/systemd/system ] && sysdir=/etc/systemd/system + [ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/ + mv $dir/clash/clash.service $sysdir/clash.service #将service服务文件移动到系统目录 + sed -i "s%/etc/clash%${dir}/clash%g" $sysdir/clash.service + rm -rf $dir/clash/clashservice + rm -rf /etc/init.d/clash +fi +#初始化文件目录 +if [ ! -f "$dir/clash/mark" ]; then +cat >$dir/clash/mark<> /etc/profile #设置快捷命令环境变量 +sed -i '/export clashdir=*/'d /etc/profile +echo "export clashdir=\"$dir/clash\"" >> /etc/profile #设置clash路径环境变量 +#删除临时文件 +rm -rf /tmp/clashfm.tar.gz +#提示 +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo ShellClash 已经安装成功! +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo -e "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m" +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +