mirror of
https://github.com/juewuy/ShellCrash.git
synced 2024-11-16 11:42:18 +08:00
v1.0.0beta15.3
~优化脚本语句和结构 ~完美适配支持wget!!! ~优化非root用户体验 ~增加Gitee下载源 ~增加脚本日志以及查看日志功能 ~修复部分情况下开机自启显示错误的bug
This commit is contained in:
parent
4743965c58
commit
7091319fcb
50
README.md
50
README.md
|
@ -23,9 +23,9 @@
|
|||
|
||||
使用方式:
|
||||
--
|
||||
~确认路由器或设备已经开启SSH并获取root权限<br>
|
||||
~使用SSH连接工具(如putty,JuiceSSH,系统自带终端等)路由器或设备的SSH管理界面,并切换到root用户<br>
|
||||
~确认设备已经安装curl,如未安装,LInux设备请[参考此处](https://www.howtoing.com/install-curl-in-linux)进行安装,基于OpenWrt(小米官方系统、潘多拉、高恪等)的设备请使用如下命令安装:<br>
|
||||
~确认路由器设备已经开启SSH并获取root权限(带GUI桌面的Linux设备可使用自带终端安装)<br>
|
||||
~使用SSH连接工具(如putty,JuiceSSH,系统自带终端等)路由器或Linux设备的SSH管理界面或终端界面,并切换到root用户<br>
|
||||
~确认设备已经安装curl或者wget下载工具。如未安装,LInux设备请[参考此处](https://www.howtoing.com/install-curl-in-linux)安装curl,基于OpenWrt(小米官方系统、潘多拉、高恪等)的设备请使用如下命令安装curl:<br>
|
||||
|
||||
```shell
|
||||
opkg update && opkg install curl
|
||||
|
@ -33,7 +33,7 @@ opkg update && opkg install curl
|
|||
|
||||
~之后在SSH界面执行如下安装命令,并按照后续提示完成安装<br>
|
||||
|
||||
~使用curl:<br>
|
||||
~**使用curl安装**:<br>
|
||||
|
||||
```Shell
|
||||
#Release版本-github直连
|
||||
|
@ -44,7 +44,20 @@ sh -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/instal
|
|||
sh -c "$(curl -kfsSl --resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master/install.sh)" -s 1 && source /etc/profile &> /dev/null
|
||||
```
|
||||
|
||||
~安装完成管理脚本后,执行如下命令以运行管理脚本<br>
|
||||
~**使用wget安装**:<br>
|
||||
|
||||
```sh
|
||||
#Release版本-jsdelivrCDN源
|
||||
wget -q --no-check-certificate -O /tmp/install.sh https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/install.sh && sh /tmp/install.sh 2 && source /etc/profile &> /dev/null
|
||||
```
|
||||
|
||||
~**非root用户安装后**请额外执行以下命令以读取环境变量:<br>
|
||||
|
||||
```shell
|
||||
source ~/.bashrc &> /dev/null
|
||||
```
|
||||
|
||||
~安装完成管理脚本后,执行如下命令以**运行管理脚本**<br>
|
||||
|
||||
```Shell
|
||||
clash #正常模式运行
|
||||
|
@ -52,8 +65,35 @@ clash -h #脚本帮助及说明
|
|||
clash -t #测试模式运行
|
||||
```
|
||||
|
||||
~**运行时的额外依赖**:<br>
|
||||
|
||||
`大部分的设备/系统都已经预装了以下的大部分依赖,使用时如无影响可以无视之`
|
||||
|
||||
```sh
|
||||
bash/ash 重要! 全部缺少时无法安装及运行脚本
|
||||
|
||||
curl/wget 重要! 全部缺少时无法在线安装及更新,无法使用节点保存功能
|
||||
|
||||
iptables 重要! 缺少时只能使用PAC模式
|
||||
|
||||
systemd/init.d/rc.common 一般~ 全部缺少时只能使用保守模式
|
||||
|
||||
iptables-mod-nat 一般~ 缺少时无法使用redir模式,混合模式
|
||||
|
||||
ip6tables-mod-nat 低~ 缺少时影响redir模式,混合模式对ipv6的支持
|
||||
|
||||
net-tools 低~ 缺少时无法正常检测端口占用
|
||||
|
||||
ubus/iproute-doc 低~ 缺少时无法正常获取本机host地址
|
||||
|
||||
crontab 低~ 缺少时无法启用定时任务功能
|
||||
```
|
||||
|
||||
|
||||
|
||||
更新日志:
|
||||
--
|
||||
|
||||
### [点击查看](https://github.com/juewuy/ShellClash/releases)
|
||||
|
||||
交流反馈:
|
||||
|
|
40
install.sh
40
install.sh
|
@ -18,22 +18,42 @@ if [ "$USER" != "root" ];then
|
|||
read -p "仍要安装?可能会产生未知错误!(1/0) > " res
|
||||
[ "$res" != "1" ] && exit
|
||||
fi
|
||||
|
||||
webget(){
|
||||
#参数【$1】代表下载目录,【$2】代表在线地址
|
||||
#参数【$3】代表输出显示,【$4】不启用重定向
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
[ "$3" = "echooff" ] && progress='-s' || progress='-#'
|
||||
[ -z "$4" ] && redirect='-L' || redirect=''
|
||||
result=$(curl -w %{http_code} --connect-timeout 5 $progress $redirect -ko $1 $2)
|
||||
else
|
||||
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
|
||||
[ "$3" = "echoon" ] && progress=''
|
||||
[ -z "$4" ] && redirect='' || redirect='--max-redirect=0'
|
||||
wget -Y on $progress $redirect --no-check-certificate --timeout=5 -O $1 $2
|
||||
[ $? -eq 0 ] && result="200"
|
||||
fi
|
||||
}
|
||||
#检查更新
|
||||
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
|
||||
if [ "$test" -gt 0 ];then
|
||||
url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master"
|
||||
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash/master"
|
||||
[ "$test" -eq 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi"
|
||||
[ "$test" -eq 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi"
|
||||
else
|
||||
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') #检查版本
|
||||
release_new=$(webget /dev/null https://github.com.cnpmjs.org/juewuy/ShellClash/releases/latest echoon rediroff 2>&1 | grep -oE "releases/tag/.*" | awk -F '[/" ]' '{print $3}')
|
||||
[ -z "$release_new" ] && release_new=master
|
||||
url=$url@$release_new
|
||||
fi
|
||||
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
|
||||
webget /tmp/clashversion $url/bin/version echooff
|
||||
[ "$result" = "200" ] && source /tmp/clashversion || echo -e "\033[31m检查更新失败!\033[0m"
|
||||
[ -z "$release_new" ] && release_new=$versionsh
|
||||
rm -rf /tmp/clashversion
|
||||
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
|
||||
tarurl=$url@$release_new/bin/clashfm.tar.gz
|
||||
[ "$test" -gt 0 ] && tarurl=$url/bin/clashfm.tar.gz
|
||||
|
||||
tarurl=$url/bin/clashfm.tar.gz
|
||||
|
||||
gettar(){
|
||||
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
|
||||
webget /tmp/clashfm.tar.gz $tarurl
|
||||
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
|
||||
#解压
|
||||
echo -----------------------------------------------
|
||||
|
@ -69,7 +89,7 @@ gettar(){
|
|||
sed -i '/versionsh_l=*/'d $clashdir/mark
|
||||
sed -i "1i\versionsh_l=$release_new" $clashdir/mark
|
||||
#设置环境变量
|
||||
[ -w $HOME/.bashrc ] && profile=$HOME/.bashrc
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
sed -i '/alias clash=*/'d $profile
|
||||
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> $profile #设置快捷命令环境变量
|
||||
|
@ -111,8 +131,8 @@ elif [ "$num" = "1" ];then
|
|||
elif [ "$num" = "2" ];then
|
||||
dir=/usr/share
|
||||
elif [ "$num" = "3" ];then
|
||||
dir=$HOME/.local/share
|
||||
mkdir -p $HOME/.config/systemd/user
|
||||
dir=~/.local/share
|
||||
mkdir -p ~/.config/systemd/user
|
||||
elif [ "$num" = "4" ];then
|
||||
echo -----------------------------------------------
|
||||
echo '可用路径 剩余空间:'
|
||||
|
|
144
install_cdn.sh
144
install_cdn.sh
|
@ -1,144 +0,0 @@
|
|||
#! /bin/bash
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
echo='echo -e' && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && echo=echo
|
||||
[ -z "$1" ] && test=0 || test=$1
|
||||
|
||||
echo "***********************************************"
|
||||
echo "** 欢迎使用 **"
|
||||
echo "** ShellClash **"
|
||||
echo "** by Juewuy **"
|
||||
echo "***********************************************"
|
||||
|
||||
#检查root权限
|
||||
[ "$USER" != "root" ] && [ "$USER" != "admin" ] && echo 请使用root用户执行安装!&& exit 1
|
||||
|
||||
#检查更新
|
||||
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
|
||||
if [ "$test" -gt 0 ];then
|
||||
url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master"
|
||||
[ "$test" -eq 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi" && echo $url
|
||||
[ "$test" -eq 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi"
|
||||
else
|
||||
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') #检查版本
|
||||
fi
|
||||
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
|
||||
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
|
||||
tarurl=$url@$release_new/bin/clashfm.tar.gz
|
||||
[ "$test" -gt 0 ] && tarurl=$url/bin/clashfm.tar.gz
|
||||
gettar(){
|
||||
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
|
||||
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
|
||||
#解压
|
||||
echo -----------------------------------------------
|
||||
echo 开始解压文件!
|
||||
mkdir -p $clashdir > /dev/null
|
||||
tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/
|
||||
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
|
||||
#初始化文件目录
|
||||
[ -f "$clashdir/mark" ] || echo '#标识clash运行状态的文件,不明勿动!' > $clashdir/mark
|
||||
#判断系统类型写入不同的启动文件
|
||||
if [ -f /etc/rc.common ];then
|
||||
#设为init.d方式启动
|
||||
mv $clashdir/clashservice /etc/init.d/clash
|
||||
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/
|
||||
if [ -n "$sysdir" ];then
|
||||
#设为systemd方式启动
|
||||
mv $clashdir/clash.service $sysdir/clash.service
|
||||
sed -i "s%/etc/clash%$clashdir%g" $sysdir/clash.service
|
||||
systemctl daemon-reload
|
||||
rm -rf /etc/init.d/clash
|
||||
else
|
||||
#设为保守模式启动
|
||||
sed -i '/start_old=*/'d $clashdir/mark
|
||||
sed -i "1i\start_old=已开启" $clashdir/mark
|
||||
fi
|
||||
fi
|
||||
#修饰文件及版本号
|
||||
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
|
||||
sed -i "s%#!/bin/sh%#!/bin/$shtype%g" $clashdir/start.sh
|
||||
chmod 777 $clashdir/start.sh
|
||||
sed -i '/versionsh_l=*/'d $clashdir/mark
|
||||
sed -i "1i\versionsh_l=$release_new" $clashdir/mark
|
||||
#设置环境变量
|
||||
sed -i '/alias clash=*/'d /etc/profile
|
||||
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
|
||||
sed -i '/export clashdir=*/'d /etc/profile
|
||||
echo "export clashdir=\"$clashdir\"" >> /etc/profile #设置clash路径环境变量
|
||||
#删除临时文件
|
||||
rm -rf /tmp/clashfm.tar.gz
|
||||
rm -rf $clashdir/clashservice
|
||||
rm -rf $clashdir/clash.service
|
||||
}
|
||||
#下载及安装
|
||||
install(){
|
||||
echo -----------------------------------------------
|
||||
echo 开始从服务器获取安装文件!
|
||||
echo -----------------------------------------------
|
||||
gettar
|
||||
echo -----------------------------------------------
|
||||
echo ShellClash 已经安装成功!
|
||||
echo -----------------------------------------------
|
||||
$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m"
|
||||
echo -----------------------------------------------
|
||||
}
|
||||
setdir(){
|
||||
echo -----------------------------------------------
|
||||
$echo "\033[32m 1 在默认目录(/etc)安装"
|
||||
$echo "\033[33m 2 手动设置安装目录"
|
||||
$echo "\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 "\033[31m路径错误!已取消安装!\033[0m"
|
||||
exit;
|
||||
fi
|
||||
else
|
||||
echo 安装已取消!!!
|
||||
exit;
|
||||
fi
|
||||
clashdir=$dir/clash
|
||||
install
|
||||
}
|
||||
|
||||
#输出
|
||||
$echo "最新版本:\033[32m$release_new\033[0m"
|
||||
echo -----------------------------------------------
|
||||
$echo "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m"
|
||||
$echo "\033[37m支持各种基于openwrt的路由器设备"
|
||||
$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m"
|
||||
|
||||
if [ -n "$clashdir" ];then
|
||||
echo -----------------------------------------------
|
||||
$echo "检测到旧的安装目录\033[36m$clashdir\033[0m,是否覆盖安装?"
|
||||
$echo "\033[32m覆盖安装时不会移除配置文件!\033[0m"
|
||||
read -p "覆盖安装/卸载旧版本?(1/0) > " res
|
||||
if [ "$res" = "1" ];then
|
||||
install
|
||||
elif [ "$res" = "0" ];then
|
||||
rm -rf $clashdir
|
||||
echo -----------------------------------------------
|
||||
$echo "\033[31m 旧版本文件已卸载!\033[0m"
|
||||
setdir
|
||||
else
|
||||
$echo "\033[31m输入错误!已取消安装!\033[0m"
|
||||
exit;
|
||||
fi
|
||||
else
|
||||
setdir
|
||||
fi
|
|
@ -5,7 +5,7 @@ getconfig(){
|
|||
#服务器缺省地址
|
||||
[ -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
|
||||
[ -z "$clashdir" ] && echo 环境变量配置有误!请重新安装脚本!
|
||||
ccfg=$clashdir/mark
|
||||
yaml=$clashdir/config.yaml
|
||||
#检查/读取标识文件
|
||||
|
|
|
@ -434,10 +434,12 @@ gettar(){
|
|||
sed -i '/versionsh_l=*/'d $clashdir/mark
|
||||
sed -i "1i\versionsh_l=$release_new" $clashdir/mark
|
||||
#设置环境变量
|
||||
sed -i '/alias clash=*/'d /etc/profile
|
||||
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
|
||||
sed -i '/export clashdir=*/'d /etc/profile
|
||||
echo "export clashdir=\"$clashdir\"" >> /etc/profile #设置clash路径环境变量
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
sed -i '/alias clash=*/'d $profile
|
||||
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> $profile #设置快捷命令环境变量
|
||||
sed -i '/export clashdir=*/'d $profile
|
||||
echo "export clashdir=\"$clashdir\"" >> $profile #设置clash路径环境变量
|
||||
#删除临时文件
|
||||
rm -rf /tmp/clashfm.tar.gz
|
||||
rm -rf $clashdir/clashservice
|
||||
|
@ -860,13 +862,17 @@ update(){
|
|||
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相关文件!有缘再会!
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
sed -i '/alias clash=*/'d $profile
|
||||
sed -i '/export clashdir=*/'d $profile
|
||||
sed -i '/http*_proxy/'d $profile
|
||||
sed -i '/HTTP*_PROXY/'d $profile
|
||||
source $profile > /dev/null 2>&1
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[36m已卸载ShellClash相关文件!有缘再会!\033[0m"
|
||||
echo -e "\033[33m请手动关闭当前窗口以重置环境变量!\033[0m"
|
||||
echo -----------------------------------------------
|
||||
exit
|
||||
fi
|
||||
echo -e "\033[31m操作已取消!\033[0m"
|
||||
|
@ -941,7 +947,7 @@ testcommand(){
|
|||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
exit;
|
||||
elif [ "$num" = 6 ]; then
|
||||
echo 注意:依赖curl,且测试结果不保证一定准确!
|
||||
echo "注意:依赖curl(不支持wget),且测试结果不保证一定准确!"
|
||||
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
|
||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
getconfig(){
|
||||
#加载配置文件
|
||||
[ -z "$clashdir" ] && source /etc/profile > /dev/null 2>&1
|
||||
[ -z "$clashdir" ] && source /etc/profile > /dev/null
|
||||
[ -z "$clashdir" ] && source ~/.bashrc > /dev/null
|
||||
ccfg=$clashdir/mark
|
||||
[ -f $ccfg ] && source $ccfg
|
||||
#默认设置
|
||||
|
@ -432,8 +433,10 @@ set_proxy)
|
|||
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "Proxy Config Script" "http://127.0.0.1${3}/pac"
|
||||
#环境变量方式
|
||||
else
|
||||
echo 'export all_proxy=http://127.0.0.1:'"$2" >> /etc/profile
|
||||
echo 'export ALL_PROXY=$all_proxy' >> /etc/profile
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
echo 'export all_proxy=http://127.0.0.1:'"$2" >> $profile
|
||||
echo 'export ALL_PROXY=$all_proxy' >> $profile
|
||||
fi
|
||||
;;
|
||||
unset_proxy)
|
||||
|
@ -445,8 +448,10 @@ unset_proxy)
|
|||
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "ProxyType" 0
|
||||
#环境变量方式
|
||||
else
|
||||
sed -i '/all_proxy/'d /etc/profile
|
||||
sed -i '/ALL_PROXY/'d /etc/profile
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
sed -i '/all_proxy/'d $profile
|
||||
sed -i '/ALL_PROXY/'d $profile
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Reference in New Issue
Block a user