2020-09-13 19:33:39 +08:00
|
|
|
|
#! /bin/bash
|
2020-08-03 15:12:16 +08:00
|
|
|
|
# Copyright (C) Juewuy
|
|
|
|
|
|
|
|
|
|
echo "***********************************************"
|
|
|
|
|
echo "** 欢迎使用 **"
|
2020-09-13 19:33:39 +08:00
|
|
|
|
echo "** ShellClash **"
|
2020-08-03 15:12:16 +08:00
|
|
|
|
echo "** by Juewuy **"
|
|
|
|
|
echo "***********************************************"
|
2020-09-17 14:50:29 +08:00
|
|
|
|
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
|
2020-09-19 09:29:50 +08:00
|
|
|
|
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')
|
2020-09-17 14:50:29 +08:00
|
|
|
|
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
|
|
|
|
|
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
|
2020-09-20 17:57:21 +08:00
|
|
|
|
|
2020-09-17 14:50:29 +08:00
|
|
|
|
echo -e "最新版本:\033[32m$release_new\033[0m"
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-09-13 19:33:39 +08:00
|
|
|
|
echo -e "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m"
|
2020-08-27 10:46:34 +08:00
|
|
|
|
echo -e "\033[37m支持各种基于openwrt的路由器设备"
|
2020-09-17 14:50:29 +08:00
|
|
|
|
echo -e "\033[33m有限兼容debian、centos等Linux系统\033[0m"
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-09-13 19:33:39 +08:00
|
|
|
|
echo -e "\033[32m 1 在默认目录(/etc)安装ShellClash"
|
2020-08-07 17:03:11 +08:00
|
|
|
|
echo -e "\033[33m 2 手动设置安装目录(不明勿用!)"
|
|
|
|
|
echo -e "\033[0m 0 退出安装"
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-08-03 15:12:16 +08:00
|
|
|
|
read -p "请输入相应数字 > " num
|
|
|
|
|
|
|
|
|
|
if [ -z $num ];then
|
|
|
|
|
echo 安装已取消
|
|
|
|
|
exit;
|
2020-09-13 19:33:39 +08:00
|
|
|
|
elif [ "$num" = "1" ];then
|
2020-08-03 15:35:45 +08:00
|
|
|
|
dir=/etc
|
2020-09-13 19:33:39 +08:00
|
|
|
|
elif [ "$num" = "2" ];then
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-08-03 15:12:16 +08:00
|
|
|
|
echo '可用路径 剩余空间:'
|
|
|
|
|
df -h | awk '{print $6,$2}'| sed 1d
|
2020-08-03 15:35:45 +08:00
|
|
|
|
echo '路径是必须带 / 的格式,写入虚拟内存(/tmp,/sys,..)的文件会在重启后消失!!!'
|
2020-08-03 15:12:16 +08:00
|
|
|
|
read -p "请输入自定义路径 > " dir
|
|
|
|
|
if [ -z $dir ];then
|
|
|
|
|
echo 路径错误!已取消安装!
|
|
|
|
|
exit;
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo 安装已取消
|
|
|
|
|
exit;
|
|
|
|
|
fi
|
2020-08-03 15:35:45 +08:00
|
|
|
|
#下载文件包
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-08-03 15:12:16 +08:00
|
|
|
|
echo 开始从服务器获取安装文件!
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-09-19 09:29:50 +08:00
|
|
|
|
tarurl=$url@$release_new/bin/clashfm.tar.gz
|
2020-08-03 15:12:16 +08:00
|
|
|
|
if command -v curl &> /dev/null; then
|
2020-08-03 19:00:34 +08:00
|
|
|
|
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
|
|
|
|
|
else $result
|
2020-08-03 15:12:16 +08:00
|
|
|
|
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
|
2020-08-03 15:35:45 +08:00
|
|
|
|
#解压
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-08-03 15:12:16 +08:00
|
|
|
|
echo 开始解压文件!
|
2020-08-04 11:04:00 +08:00
|
|
|
|
mkdir -p $dir/clash > /dev/null
|
2020-08-14 14:56:38 +08:00
|
|
|
|
tar -zxvf '/tmp/clashfm.tar.gz' -C $dir/clash/
|
2020-08-03 15:12:16 +08:00
|
|
|
|
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
|
2020-09-20 17:57:21 +08:00
|
|
|
|
#初始化文件目录
|
|
|
|
|
if [ ! -f "$dir/clash/mark" ]; then
|
|
|
|
|
cat >$dir/clash/mark<<EOF
|
|
|
|
|
#标识clash运行状态的文件,不明勿动!
|
|
|
|
|
EOF
|
|
|
|
|
fi
|
2020-09-18 21:09:06 +08:00
|
|
|
|
#判断系统类型写入不同的启动文件
|
2020-09-20 17:57:21 +08:00
|
|
|
|
if [ -f /etc/rc.common ];then
|
2020-09-18 21:09:06 +08:00
|
|
|
|
mv $dir/clash/clashservice /etc/init.d/clash #将rc服务文件移动到系统目录
|
|
|
|
|
chmod 777 /etc/init.d/clash #授予权限
|
|
|
|
|
else
|
|
|
|
|
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
|
|
|
|
|
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
|
2020-09-20 17:57:21 +08:00
|
|
|
|
if [ -n "$sysdir" ];then
|
|
|
|
|
mv $dir/clash/clash.service $sysdir/clash.service #将service服务文件移动到系统目录
|
|
|
|
|
sed -i "s%/etc/clash%${dir}/clash%g" $sysdir/clash.service
|
2020-09-20 18:48:27 +08:00
|
|
|
|
rm -rf /etc/init.d/clash
|
2020-09-20 17:57:21 +08:00
|
|
|
|
else
|
|
|
|
|
#设为保守模式
|
|
|
|
|
sed -i '/start_old=*/'d $dir/clash/mark
|
|
|
|
|
sed -i "1i\start_old=已开启" $dir/clash/mark
|
|
|
|
|
fi
|
2020-08-07 17:03:11 +08:00
|
|
|
|
fi
|
2020-09-18 21:09:06 +08:00
|
|
|
|
#修饰文件及版本号
|
2020-09-19 09:29:50 +08:00
|
|
|
|
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
|
2020-09-18 21:09:06 +08:00
|
|
|
|
sed -i "s%#!/bin/sh%#!/bin/$shtype%g" $dir/clash/start.sh
|
|
|
|
|
chmod 777 $dir/clash/start.sh
|
2020-08-07 17:03:11 +08:00
|
|
|
|
sed -i '/versionsh_l=*/'d $dir/clash/mark
|
2020-09-18 21:09:06 +08:00
|
|
|
|
sed -i "1i\versionsh_l=$release_new" $dir/clash/mark
|
2020-08-03 15:35:45 +08:00
|
|
|
|
#设置环境变量
|
2020-08-03 15:12:16 +08:00
|
|
|
|
sed -i '/alias clash=*/'d /etc/profile
|
2020-09-13 19:33:39 +08:00
|
|
|
|
echo "alias clash=\"$shtype $dir/clash/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
|
2020-08-03 15:35:45 +08:00
|
|
|
|
sed -i '/export clashdir=*/'d /etc/profile
|
2020-08-03 19:00:34 +08:00
|
|
|
|
echo "export clashdir=\"$dir/clash\"" >> /etc/profile #设置clash路径环境变量
|
2020-08-03 15:35:45 +08:00
|
|
|
|
#删除临时文件
|
|
|
|
|
rm -rf /tmp/clashfm.tar.gz
|
2020-09-20 17:57:21 +08:00
|
|
|
|
rm -rf $dir/clash/clashservice
|
2020-09-20 18:48:27 +08:00
|
|
|
|
rm -rf $dir/clash/clash.service
|
2020-08-03 15:35:45 +08:00
|
|
|
|
#提示
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-09-13 19:33:39 +08:00
|
|
|
|
echo ShellClash 已经安装成功!
|
2020-08-27 10:46:34 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
echo -e "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m"
|
2020-08-10 20:24:28 +08:00
|
|
|
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2020-08-04 11:04:00 +08:00
|
|
|
|
|