~优化zsh环境变量适配

~修复pac文件内host不正确的bug
This commit is contained in:
juewuy
2025-12-06 22:40:07 +08:00
parent bab47c62af
commit 3f85b5e19f
2 changed files with 5 additions and 19 deletions

View File

@@ -244,34 +244,21 @@ grep -q 'firewall_mod' "$CRASHDIR/configs/ShellClash.cfg" 2>/dev/null || {
if [ -n "$profile" ]; then
sed -i '/alias crash=*/'d $profile
echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >>$profile #设置快捷命令环境变量
sed -i '/alias clash=*/'d $profile
echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >>$profile #设置快捷命令环境变量
sed -i '/export CRASHDIR=*/'d $profile
echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile #设置路径环境变量
source $profile >/dev/null 2>&1 || echo 运行错误请使用bash而不是dash运行安装命令
#适配zsh环境变量
[ -n "$(cat /etc/shells 2>/dev/null | grep -oE 'zsh')" ] && [ -z "$(cat ~/.zshrc 2>/dev/null | grep CRASHDIR)" ] && {
zsh --version >/dev/null 2>&1 && [ -z "$(cat ~/.zshrc 2>/dev/null | grep CRASHDIR)" ] && {
sed -i '/alias crash=*/'d ~/.zshrc 2>/dev/null
echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >>~/.zshrc
# 兼容 clash 命令
sed -i '/alias clash=*/'d ~/.zshrc 2>/dev/null
echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >>~/.zshrc
sed -i '/export CRASHDIR=*/'d ~/.zshrc 2>/dev/null
echo "export CRASHDIR=\"$CRASHDIR\"" >>~/.zshrc
source ~/.zshrc >/dev/null 2>&1
. ~/.zshrc >/dev/null 2>&1
}
else
echo -e "\033[33m无法写入环境变量请检查安装权限\033[0m"
exit 1
fi
#在允许的情况下创建/usr/bin/crash文件
touch /usr/bin/crash 2>/dev/null && {
cat >/usr/bin/crash <<EOF
#/bin/$shtype
$CRASHDIR/menu.sh \$1 \$2 \$3 \$4 \$5
EOF
chmod +x /usr/bin/crash
}
#梅林/Padavan额外设置
[ -n "$initdir" ] && {
sed -i '/ShellCrash初始化/'d $initdir

View File

@@ -470,7 +470,7 @@ EOF
#读取本机hosts并生成配置文件
if [ "$hosts_opt" != "未启用" ] && [ -z "$(grep -aE '^hosts:' "$CRASHDIR"/yamls/user.yaml 2>/dev/null)" ]; then
#NTP劫持
cat >>"$TMPDIR"/hosts.yaml <<EOF
cat >"$TMPDIR"/hosts.yaml <<EOF
hosts:
'time.android.com': 203.107.6.88
'time.facebook.com': 203.107.6.88
@@ -1845,8 +1845,8 @@ singbox_check() { #singbox启动前检查
return 0
}
network_check() { #检查是否联网
for host in 223.5.5.5 dns.alidns.com doh.pub doh.360.cn; do
ping -c 3 $host >/dev/null 2>&1 && return 0
for text in 223.5.5.5 dns.alidns.com doh.pub doh.360.cn; do
ping -c 3 $text >/dev/null 2>&1 && return 0
sleep 5
done
logger "当前设备无法连接网络,已停止启动!" 33
@@ -2058,7 +2058,6 @@ stop)
fi
PID=$(pidof CrashCore) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1
#清理缓存目录
rm -rf "$TMPDIR"/crash_start_time
rm -rf "$TMPDIR"/CrashCore
;;
restart)