diff --git a/bin/clashfm.tar.gz b/bin/clashfm.tar.gz index c3add58..be706c4 100644 Binary files a/bin/clashfm.tar.gz and b/bin/clashfm.tar.gz differ diff --git a/bin/version b/bin/version index a6f7043..9c843d0 100644 --- a/bin/version +++ b/bin/version @@ -2,5 +2,5 @@ clashnet_v=v1.7.6 clashpre_v=2021.09.15 clash_v=v1.7.1 meta_v=v1.12.0 -versionsh=1.6.3 GeoIP_v=20220920 +versionsh=1.6.4 diff --git a/install.sh b/install.sh index c3bf312..e9acf32 100644 --- a/install.sh +++ b/install.sh @@ -16,13 +16,17 @@ setconfig(){ configpath=$clashdir/mark [ -n "$(grep ${1} $configpath)" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath } -[ -f "/etc/storage/started_script.sh" ] && systype=Padavan && initdir='/etc/storage/started_script.sh' -[ -d "/jffs" ] && systype=asusrouter && { +#特殊固件识别及标记 +[ -f "/etc/storage/started_script.sh" ] && { + systype=Padavan #老毛子固件 + initdir='/etc/storage/started_script.sh' + } +[ -d "/jffs" ] && { + systype=asusrouter #华硕固件 [ -f "/jffs/.asusrouter" ] && initdir='/jffs/.asusrouter' [ -d "/jffs/scripts" ] && initdir='/jffs/scripts/nat-start' - [ -z "$initdir" ] && initdir='/jffs/scripts/nat-start' && mkdir -p '/jffs/scripts' } -[ -f "/data/etc/crontabs/root" -a "$(dir_avail /etc)" = 0 ] && systype=mi_snapshot +[ -f "/data/etc/crontabs/root" ] && systype=mi_wifi #小米设备 #检查root权限 if [ "$USER" != "root" -a -z "$systype" ];then echo 当前用户:$USER @@ -132,13 +136,15 @@ gettar(){ echo 无法写入环境变量!请检查安装权限! exit 1 fi - #华硕/Padavan额外设置 + #梅林/Padavan额外设置 [ -n "$initdir" ] && { - sed -i '/ShellClash初始化/'d $initdir && touch $initdir && echo "$clashdir/start.sh init #ShellClash初始化脚本" >> $initdir + sed -i '/ShellClash初始化/'d $initdir + touch $initdir + echo "$clashdir/start.sh init #ShellClash初始化脚本" >> $initdir setconfig initdir $initdir } #小米镜像化OpenWrt额外设置 - if [ "$systype" = "mi_snapshot" ];then + if [ "$systype" = "mi_wifi" ];then chmod 755 $clashdir/misnap_init.sh uci set firewall.ShellClash=include uci set firewall.ShellClash.type='script' @@ -150,6 +156,12 @@ gettar(){ rm -rf $clashdir/misnap_init.sh rm -rf $clashdir/clashservice fi + #华硕USB启动额外设置 + [ "$usb_status" = "1" ] && { + echo "$clashdir/start.sh init #ShellClash初始化脚本" > $clashdir/asus_usb_mount.sh + nvram set script_usbmount="$clashdir/asus_usb_mount.sh" + nvram commit + } #删除临时文件 rm -rf /tmp/clashfm.tar.gz rm -rf $clashdir/clash.service @@ -168,17 +180,74 @@ $echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033 echo ----------------------------------------------- } setdir(){ + set_usb_dir(){ + $echo "请选择安装目录" + du -hL /mnt | awk '{print " "NR" "$2" "$1}' + read -p "请输入相应数字 > " num + dir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) + if [ -z "$dir" ];then + $echo "\033[31m输入错误!请重新设置!\033[0m" + set_usb_dir + fi + } +echo ----------------------------------------------- if [ -n "$systype" ];then [ "$systype" = "Padavan" ] && dir=/etc/storage - [ "$systype" = "asusrouter" ] && dir=/jffs - [ "$systype" = "mi_snapshot" ] && dir=/data + [ "$systype" = "mi_wifi" ] && { + $echo "\033[33m检测到当前设备为小米官方系统,请选择安装位置\033[0m" + $echo " 1 安装到/data目录(推荐,支持软固化功能)" + $echo " 2 安装到USB设备(支持软固化功能)" + [ "$(dir_avail /etc)" != 0 ] && $echo " 3 安装到/etc目录(不推荐)" + $echo " 0 退出安装" + echo ----------------------------------------------- + read -p "请输入相应数字 > " num + case "$num" in + 1) + dir=/data + ;; + 2) + set_usb_dir ;; + 3) + if [ "$(dir_avail /etc)" != 0 ];then + dir=/etc + systype="" + else + $echo "\033[31m你的设备不支持安装到/etc目录,已改为安装到/data\033[0m" + dir=data + fi + ;; + *) + exit 1 ;; + esac + } + [ "$systype" = "asusrouter" ] && { + $echo "\033[33m检测到当前设备为华硕固件,请选择安装方式\033[0m" + $echo " 1 基于USB设备安装(通用,须插入\033[31m任意\033[0mUSB设备)" + $echo " 2 基于自启脚本安装(仅支持梅林及部分官改固件)" + $echo " 0 退出安装" + echo ----------------------------------------------- + read -p "请输入相应数字 > " num + case "$num" in + 1) + read -p "将脚本安装到USB存储/系统闪存?(1/0) > " res + [ "$res" = "1" ] && set_usb_dir || dir=/jffs + usb_status=1 + ;; + 2) + $echo "如无法正常开机启动,请重新使用USB方式安装!" + sleep 2 + dir=/jffs ;; + *) + exit 1 ;; + esac + } else - echo ----------------------------------------------- $echo "\033[33m安装ShellClash至少需要预留约1MB的磁盘空间\033[0m" $echo " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" - $echo " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux设备)" + $echo " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" $echo " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)" - $echo " 4 手动设置安装目录" + $echo " 4 在\033[32m外置存储\033[0m中安装" + $echo " 5 手动设置安装目录" $echo " 0 退出安装" echo ----------------------------------------------- read -p "请输入相应数字 > " num @@ -194,6 +263,8 @@ else dir=~/.local/share mkdir -p ~/.config/systemd/user elif [ "$num" = "4" ];then + set_usb_dir + elif [ "$num" = "5" ];then echo ----------------------------------------------- echo '可用路径 剩余空间:' df -h | awk '{print $6,$4}'| sed 1d diff --git a/scripts/clash.sh b/scripts/clash.sh index 5e0d09c..e4c2c4b 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -1630,6 +1630,8 @@ case "$1" in rm -rf /tmp/clash_$USER sed -Ei s/0:7890/7890:7890/g /etc/passwd userdel -r shellclash 2>/dev/null + nvram set script_usbmount="" 2>/dev/null + nvram commit 2>/dev/null echo ----------------------------------------------- echo -e "\033[36m已卸载ShellClash相关文件!有缘再会!\033[0m" echo -e "\033[33m请手动关闭当前窗口以重置环境变量!\033[0m" diff --git a/scripts/misnap_init.sh b/scripts/misnap_init.sh index de95b16..53854e1 100644 --- a/scripts/misnap_init.sh +++ b/scripts/misnap_init.sh @@ -5,12 +5,10 @@ clashdir=/data/clash profile=/etc/profile #h初始化环境变量 -if [ `type -t clash` != "alias" ];then - echo "alias clash=\"$clashdir/clash.sh\"" >> $profile -fi -if [ -z $clashdir ];then - echo "export clashdir=\"$clashdir\"" >> $profile -fi +sed -i "/alias clash/d" $profile +sed -i "/export clashdir/d" $profile +echo "alias clash=\"$clashdir/clash.sh\"" >> $profile +echo "export clashdir=\"$clashdir\"" >> $profile #设置init.d服务并启动clash服务 ln -sf $clashdir/clashservice /etc/init.d/clash chmod 755 /etc/init.d/clash diff --git a/scripts/start.sh b/scripts/start.sh index 5f3f9d5..1d6a994 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -986,21 +986,28 @@ restart) $0 start ;; init) + sleep 30 if [ -d "/etc/storage/clash" ];then clashdir=/etc/storage/clash i=1 - while [ ! -w "/etc/profile" -a "$i" -lt 60 ];do - sleep 1 && i=$((i+1)) + while [ ! -w "/etc/profile" -a "$i" -lt 7 ];do + sleep 5 && i=$((i+1)) done profile=/etc/profile sed -i '' $profile #将软链接转化为一般文件 elif [ -d "/jffs/clash" ];then clashdir=/jffs/clash - profile=/jffs/configs/profile.add + if [ -w /etc/profile ];then + profile=/etc/profile + else + profile=$(cat /etc/profile | grep -oE '\-f.*jffs.*profile' | awk '{print $2}') + fi else clashdir=$(cd $(dirname $0);pwd) profile=/etc/profile fi + sed -i "/alias clash/d" $profile + sed -i "/export clashdir/d" $profile echo "alias clash=\"$clashdir/clash.sh\"" >> $profile echo "export clashdir=\"$clashdir\"" >> $profile [ -f $clashdir/.dis_startup ] && cronset "clash保守模式守护进程" || $0 start