From 7091319fcb331ce8cf0ecc4ca3cda1488a88f713 Mon Sep 17 00:00:00 2001 From: juewuy Date: Sat, 24 Oct 2020 21:13:06 +0800 Subject: [PATCH] =?UTF-8?q?v1.0.0beta15.3=20~=E4=BC=98=E5=8C=96=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E8=AF=AD=E5=8F=A5=E5=92=8C=E7=BB=93=E6=9E=84=20~?= =?UTF-8?q?=E5=AE=8C=E7=BE=8E=E9=80=82=E9=85=8D=E6=94=AF=E6=8C=81wget?= =?UTF-8?q?=EF=BC=81=EF=BC=81=EF=BC=81=20~=E4=BC=98=E5=8C=96=E9=9D=9Eroot?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C=20~=E5=A2=9E=E5=8A=A0Gitee?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=BA=90=20~=E5=A2=9E=E5=8A=A0=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=97=A5=E5=BF=97=E4=BB=A5=E5=8F=8A=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=8A=9F=E8=83=BD=20~=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=83=85=E5=86=B5=E4=B8=8B=E5=BC=80=E6=9C=BA?= =?UTF-8?q?=E8=87=AA=E5=90=AF=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 50 ++++++++++++++-- install.sh | 40 +++++++++---- install_cdn.sh | 144 --------------------------------------------- scripts/clash.sh | 2 +- scripts/getdate.sh | 30 ++++++---- scripts/start.sh | 15 +++-- 6 files changed, 104 insertions(+), 177 deletions(-) delete mode 100644 install_cdn.sh diff --git a/README.md b/README.md index 4bd03a4..768626e 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ 使用方式: -- -~确认路由器或设备已经开启SSH并获取root权限
-~使用SSH连接工具(如putty,JuiceSSH,系统自带终端等)路由器或设备的SSH管理界面,并切换到root用户
-~确认设备已经安装curl,如未安装,LInux设备请[参考此处](https://www.howtoing.com/install-curl-in-linux)进行安装,基于OpenWrt(小米官方系统、潘多拉、高恪等)的设备请使用如下命令安装:
+~确认路由器设备已经开启SSH并获取root权限(带GUI桌面的Linux设备可使用自带终端安装)
+~使用SSH连接工具(如putty,JuiceSSH,系统自带终端等)路由器或Linux设备的SSH管理界面或终端界面,并切换到root用户
+~确认设备已经安装curl或者wget下载工具。如未安装,LInux设备请[参考此处](https://www.howtoing.com/install-curl-in-linux)安装curl,基于OpenWrt(小米官方系统、潘多拉、高恪等)的设备请使用如下命令安装curl:
```shell opkg update && opkg install curl @@ -33,7 +33,7 @@ opkg update && opkg install curl ~之后在SSH界面执行如下安装命令,并按照后续提示完成安装
-~使用curl:
+~**使用curl安装**:
```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 ``` -~安装完成管理脚本后,执行如下命令以运行管理脚本
+~**使用wget安装**:
+ +```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用户安装后**请额外执行以下命令以读取环境变量:
+ +```shell +source ~/.bashrc &> /dev/null +``` + +~安装完成管理脚本后,执行如下命令以**运行管理脚本**
```Shell clash #正常模式运行 @@ -52,8 +65,35 @@ clash -h #脚本帮助及说明 clash -t #测试模式运行 ``` +~**运行时的额外依赖**:
+ +`大部分的设备/系统都已经预装了以下的大部分依赖,使用时如无影响可以无视之` + +```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) 交流反馈: diff --git a/install.sh b/install.sh index f0b23f2..10b9c62 100644 --- a/install.sh +++ b/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 '可用路径 剩余空间:' diff --git a/install_cdn.sh b/install_cdn.sh deleted file mode 100644 index 5958784..0000000 --- a/install_cdn.sh +++ /dev/null @@ -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 diff --git a/scripts/clash.sh b/scripts/clash.sh index 6443ac9..f61572c 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -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 #检查/读取标识文件 diff --git a/scripts/getdate.sh b/scripts/getdate.sh index 7a54e62..bac3c0b 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/scripts/start.sh b/scripts/start.sh index 353576c..dcecfca 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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