2023-02-01 10:13:35 +08:00
|
|
|
|
#!/bin/sh
|
2023-01-13 20:37:27 +08:00
|
|
|
|
# Copyright (C) Juewuy
|
|
|
|
|
|
2024-08-25 21:25:58 +08:00
|
|
|
|
version=1.9.1beta15
|
2023-01-13 20:37:27 +08:00
|
|
|
|
|
|
|
|
|
setdir(){
|
|
|
|
|
dir_avail(){
|
2023-08-07 22:09:41 +08:00
|
|
|
|
df $2 $1 |awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' |grep -E 'Ava|可用' |awk '{print $2}'
|
2023-01-13 20:37:27 +08:00
|
|
|
|
}
|
|
|
|
|
set_usb_dir(){
|
|
|
|
|
echo -e "请选择安装目录"
|
|
|
|
|
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 -e "\033[31m输入错误!请重新设置!\033[0m"
|
|
|
|
|
set_usb_dir
|
|
|
|
|
fi
|
|
|
|
|
}
|
2023-04-04 10:23:19 +08:00
|
|
|
|
set_cust_dir(){
|
|
|
|
|
echo -----------------------------------------------
|
|
|
|
|
echo '可用路径 剩余空间:'
|
|
|
|
|
df -h | awk '{print $6,$4}'| sed 1d
|
|
|
|
|
echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!'
|
|
|
|
|
read -p "请输入自定义路径 > " dir
|
|
|
|
|
if [ "$(dir_avail $dir)" = 0 ];then
|
|
|
|
|
echo "\033[31m路径错误!请重新设置!\033[0m"
|
|
|
|
|
set_cust_dir
|
|
|
|
|
fi
|
|
|
|
|
}
|
2023-01-13 20:37:27 +08:00
|
|
|
|
echo -----------------------------------------------
|
|
|
|
|
if [ -n "$systype" ];then
|
|
|
|
|
[ "$systype" = "Padavan" ] && dir=/etc/storage
|
|
|
|
|
[ "$systype" = "mi_snapshot" ] && {
|
|
|
|
|
echo -e "\033[33m检测到当前设备为小米官方系统,请选择安装位置\033[0m"
|
2023-04-12 17:19:44 +08:00
|
|
|
|
[ "$(dir_avail /data)" -gt 256 ] && echo " 1 安装到 /data 目录(推荐,支持软固化功能)"
|
|
|
|
|
[ "$(dir_avail /userdisk)" -gt 256 ] && echo " 2 安装到 /userdisk 目录(推荐,支持软固化功能)"
|
2023-04-04 10:23:19 +08:00
|
|
|
|
echo " 3 安装自定义目录(不推荐,不明勿用!)"
|
|
|
|
|
echo " 0 退出安装"
|
2023-01-13 20:37:27 +08:00
|
|
|
|
echo -----------------------------------------------
|
|
|
|
|
read -p "请输入相应数字 > " num
|
|
|
|
|
case "$num" in
|
|
|
|
|
1)
|
|
|
|
|
dir=/data
|
|
|
|
|
;;
|
|
|
|
|
2)
|
2023-04-04 10:23:19 +08:00
|
|
|
|
dir=/userdisk
|
|
|
|
|
;;
|
2023-01-13 20:37:27 +08:00
|
|
|
|
3)
|
2023-04-04 10:23:19 +08:00
|
|
|
|
set_cust_dir
|
2023-01-13 20:37:27 +08:00
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
exit 1 ;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
[ "$systype" = "asusrouter" ] && {
|
|
|
|
|
echo -e "\033[33m检测到当前设备为华硕固件,请选择安装方式\033[0m"
|
|
|
|
|
echo -e " 1 基于USB设备安装(通用,须插入\033[31m任意\033[0mUSB设备)"
|
|
|
|
|
echo -e " 2 基于自启脚本安装(仅支持梅林及部分官改固件)"
|
|
|
|
|
echo -e " 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 -e "如无法正常开机启动,请重新使用USB方式安装!"
|
|
|
|
|
sleep 2
|
|
|
|
|
dir=/jffs ;;
|
|
|
|
|
*)
|
|
|
|
|
exit 1 ;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
2023-05-03 16:59:03 +08:00
|
|
|
|
[ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt
|
2023-01-13 20:37:27 +08:00
|
|
|
|
else
|
2024-01-02 17:09:11 +08:00
|
|
|
|
echo -e "\033[33m安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m"
|
2023-01-13 20:37:27 +08:00
|
|
|
|
echo -e " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)"
|
|
|
|
|
echo -e " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)"
|
|
|
|
|
echo -e " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)"
|
|
|
|
|
echo -e " 4 在\033[32m外置存储\033[0m中安装"
|
|
|
|
|
echo -e " 5 手动设置安装目录"
|
|
|
|
|
echo -e " 0 退出安装"
|
|
|
|
|
echo -----------------------------------------------
|
|
|
|
|
read -p "请输入相应数字 > " num
|
|
|
|
|
#设置目录
|
|
|
|
|
if [ -z $num ];then
|
|
|
|
|
echo 安装已取消
|
|
|
|
|
exit 1;
|
|
|
|
|
elif [ "$num" = "1" ];then
|
|
|
|
|
dir=/etc
|
|
|
|
|
elif [ "$num" = "2" ];then
|
|
|
|
|
dir=/usr/share
|
|
|
|
|
elif [ "$num" = "3" ];then
|
|
|
|
|
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
|
|
|
|
|
echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!'
|
|
|
|
|
read -p "请输入自定义路径 > " dir
|
|
|
|
|
if [ -z "$dir" ];then
|
|
|
|
|
echo -e "\033[31m路径错误!请重新设置!\033[0m"
|
|
|
|
|
setdir
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo 安装已取消!!!
|
|
|
|
|
exit 1;
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ! -w $dir ];then
|
|
|
|
|
echo -e "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir
|
|
|
|
|
else
|
2023-04-14 16:45:31 +08:00
|
|
|
|
echo -e "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)"
|
2023-01-13 20:37:27 +08:00
|
|
|
|
read -p "确认安装?(1/0) > " res
|
2024-01-10 22:02:15 +08:00
|
|
|
|
[ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir
|
2023-01-13 20:37:27 +08:00
|
|
|
|
fi
|
|
|
|
|
}
|
2024-01-10 22:02:15 +08:00
|
|
|
|
setconfig(){
|
2023-01-13 20:37:27 +08:00
|
|
|
|
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
2024-01-10 22:02:15 +08:00
|
|
|
|
[ -z "$3" ] && configpath=${CRASHDIR}/configs/ShellCrash.cfg || configpath="${3}"
|
|
|
|
|
[ -n "$(grep "${1}=" "$configpath")" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath
|
2023-01-13 20:37:27 +08:00
|
|
|
|
}
|
|
|
|
|
#特殊固件识别及标记
|
|
|
|
|
[ -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'
|
2024-04-05 18:22:33 +08:00
|
|
|
|
#华硕启用jffs
|
|
|
|
|
nvram set jffs2_scripts="1"
|
|
|
|
|
nvram commit
|
2023-01-13 20:37:27 +08:00
|
|
|
|
}
|
|
|
|
|
[ -f "/data/etc/crontabs/root" ] && systype=mi_snapshot #小米设备
|
2023-05-03 16:59:03 +08:00
|
|
|
|
[ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备
|
2023-01-13 20:37:27 +08:00
|
|
|
|
|
|
|
|
|
#检查环境变量
|
2024-01-02 17:59:40 +08:00
|
|
|
|
[ -z "$CRASHDIR" -a -n "$clashdir" ] && CRASHDIR=$clashdir
|
2024-01-10 22:02:15 +08:00
|
|
|
|
[ -z "$CRASHDIR" -a -d /tmp/SC_tmp ] && setdir
|
2023-01-13 20:37:27 +08:00
|
|
|
|
#移动文件
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mkdir -p ${CRASHDIR}
|
|
|
|
|
mv -f /tmp/SC_tmp/* ${CRASHDIR} 2>/dev/null
|
2023-01-17 19:55:45 +08:00
|
|
|
|
|
2023-01-13 20:37:27 +08:00
|
|
|
|
#初始化
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mkdir -p ${CRASHDIR}/configs
|
|
|
|
|
[ -f "${CRASHDIR}/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' > ${CRASHDIR}/configs/ShellCrash.cfg
|
2023-01-13 20:37:27 +08:00
|
|
|
|
#判断系统类型写入不同的启动文件
|
2024-01-10 22:02:15 +08:00
|
|
|
|
if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ];then
|
2023-01-13 20:37:27 +08:00
|
|
|
|
#设为init.d方式启动
|
2024-01-10 22:02:15 +08:00
|
|
|
|
cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash
|
2024-01-06 22:35:41 +08:00
|
|
|
|
chmod 755 /etc/init.d/shellcrash
|
2023-01-13 20:37:27 +08:00
|
|
|
|
else
|
2023-04-02 19:46:08 +08:00
|
|
|
|
[ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
|
2024-01-10 22:02:15 +08:00
|
|
|
|
[ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
|
|
|
|
|
if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then
|
2024-01-28 12:15:40 +08:00
|
|
|
|
#创建shellcrash用户
|
2024-04-04 20:29:46 +08:00
|
|
|
|
userdel shellcrash 2>/dev/null
|
2024-01-28 12:15:40 +08:00
|
|
|
|
sed -i '/0:7890/d' /etc/passwd
|
2024-01-30 11:40:55 +08:00
|
|
|
|
sed -i '/x:7890/d' /etc/group
|
2024-04-04 20:29:46 +08:00
|
|
|
|
if useradd -h >/dev/null 2>&1; then
|
2024-02-04 16:55:06 +08:00
|
|
|
|
useradd shellcrash -u 7890 2>/dev/null
|
2024-01-30 11:40:55 +08:00
|
|
|
|
sed -Ei s/7890:7890/0:7890/g /etc/passwd
|
|
|
|
|
else
|
|
|
|
|
echo "shellcrash:x:0:7890::/home/shellcrash:/bin/sh" >> /etc/passwd
|
|
|
|
|
fi
|
2024-01-24 16:09:10 +08:00
|
|
|
|
#配置systemd
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null
|
2024-01-06 22:35:41 +08:00
|
|
|
|
sed -i "s%/etc/ShellCrash%$CRASHDIR%g" $sysdir/shellcrash.service
|
2024-01-10 22:02:15 +08:00
|
|
|
|
rm -rf $sysdir/clash.service #旧版文件清理
|
2023-01-13 20:37:27 +08:00
|
|
|
|
systemctl daemon-reload
|
2024-02-09 10:40:16 +08:00
|
|
|
|
else
|
2024-01-30 11:40:55 +08:00
|
|
|
|
#设为保守模式启动
|
2024-02-16 15:19:39 +08:00
|
|
|
|
systemctl disable shellcrash 2>/dev/null
|
2024-01-30 11:40:55 +08:00
|
|
|
|
setconfig start_old 已开启
|
2024-02-09 10:40:16 +08:00
|
|
|
|
fi
|
2023-01-13 20:37:27 +08:00
|
|
|
|
fi
|
|
|
|
|
#修饰文件及版本号
|
2024-04-04 20:29:46 +08:00
|
|
|
|
command -v bash >/dev/null 2>&1 && shtype=bash
|
|
|
|
|
[ -x /bin/ash ] && shtype=ash
|
|
|
|
|
for file in start.sh task.sh menu.sh;do
|
2024-01-10 22:02:15 +08:00
|
|
|
|
sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file}
|
|
|
|
|
chmod 755 ${CRASHDIR}/${file}
|
|
|
|
|
done
|
2023-01-13 20:37:27 +08:00
|
|
|
|
setconfig versionsh_l $version
|
2024-01-10 22:02:15 +08:00
|
|
|
|
#生成用于执行systemd及procd服务的变量文件
|
2024-01-20 16:35:52 +08:00
|
|
|
|
[ ! -f ${CRASHDIR}/configs/command.env ] && {
|
|
|
|
|
TMPDIR='/tmp/ShellCrash'
|
|
|
|
|
BINDIR=${CRASHDIR}
|
|
|
|
|
touch ${CRASHDIR}/configs/command.env
|
|
|
|
|
setconfig TMPDIR ${TMPDIR} ${CRASHDIR}/configs/command.env
|
|
|
|
|
setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env
|
|
|
|
|
}
|
2024-02-02 11:47:17 +08:00
|
|
|
|
if [ -n "$(grep 'crashcore=singbox' ${CRASHDIR}/configs/ShellCrash.cfg)" ];then
|
|
|
|
|
COMMAND='"$TMPDIR/CrashCore run -D $BINDIR -C $TMPDIR/jsons"'
|
2024-01-28 12:15:40 +08:00
|
|
|
|
else
|
2024-02-02 11:47:17 +08:00
|
|
|
|
COMMAND='"$TMPDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"'
|
2024-01-28 12:15:40 +08:00
|
|
|
|
fi
|
|
|
|
|
setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env
|
2024-03-03 19:12:31 +08:00
|
|
|
|
#设置防火墙执行模式
|
|
|
|
|
[ -z "$(grep firewall_mod $CRASHDIR/configs/ShellClash.cfg 2>/dev/null)" ] && {
|
2024-04-04 20:29:46 +08:00
|
|
|
|
iptables -j REDIRECT -h >/dev/null 2>&1 && firewall_mod=iptables
|
2024-03-03 19:12:31 +08:00
|
|
|
|
nft add table inet shellcrash 2>/dev/null && firewall_mod=nftables
|
|
|
|
|
setconfig firewall_mod $firewall_mod
|
|
|
|
|
}
|
2023-01-13 20:37:27 +08:00
|
|
|
|
#设置更新地址
|
|
|
|
|
[ -n "$url" ] && setconfig update_url $url
|
|
|
|
|
#设置环境变量
|
|
|
|
|
[ -w /opt/etc/profile ] && profile=/opt/etc/profile
|
|
|
|
|
[ -w /jffs/configs/profile.add ] && profile=/jffs/configs/profile.add
|
|
|
|
|
[ -w ~/.bashrc ] && profile=~/.bashrc
|
|
|
|
|
[ -w /etc/profile ] && profile=/etc/profile
|
|
|
|
|
if [ -n "$profile" ];then
|
2024-01-02 17:09:11 +08:00
|
|
|
|
sed -i '/alias crash=*/'d $profile
|
2024-01-06 22:35:41 +08:00
|
|
|
|
echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >> $profile #设置快捷命令环境变量
|
2024-01-13 14:23:34 +08:00
|
|
|
|
sed -i '/alias clash=*/'d $profile
|
|
|
|
|
echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >> $profile #设置快捷命令环境变量
|
2024-01-02 17:09:11 +08:00
|
|
|
|
sed -i '/export CRASHDIR=*/'d $profile
|
2024-01-06 22:35:41 +08:00
|
|
|
|
echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile #设置路径环境变量
|
2024-02-04 16:55:06 +08:00
|
|
|
|
source $profile >/dev/null 2>&1 || echo 运行错误!请使用bash而不是dash运行安装命令!!!
|
2023-01-13 20:37:27 +08:00
|
|
|
|
#适配zsh环境变量
|
2024-01-25 12:42:23 +08:00
|
|
|
|
[ -n "$(cat /etc/shells 2>/dev/null|grep -oE 'zsh')" ] && [ -z "$(cat ~/.zshrc 2>/dev/null|grep CRASHDIR)" ] && {
|
2024-02-13 21:43:44 +08:00
|
|
|
|
sed -i '/alias crash=*/'d ~/.zshrc 2>/dev/null
|
2024-01-25 12:48:51 +08:00
|
|
|
|
echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >> ~/.zshrc
|
|
|
|
|
# 兼容 clash 命令
|
2024-02-13 21:43:44 +08:00
|
|
|
|
sed -i '/alias clash=*/'d ~/.zshrc 2>/dev/null
|
2024-01-25 12:48:51 +08:00
|
|
|
|
echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >> ~/.zshrc
|
2024-02-13 21:43:44 +08:00
|
|
|
|
sed -i '/export CRASHDIR=*/'d ~/.zshrc 2>/dev/null
|
2024-01-02 17:09:11 +08:00
|
|
|
|
echo "export CRASHDIR=\"$CRASHDIR\"" >> ~/.zshrc
|
2024-02-04 16:55:06 +08:00
|
|
|
|
source ~/.zshrc >/dev/null 2>&1
|
2023-01-13 20:37:27 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
echo -e "\033[33m无法写入环境变量!请检查安装权限!\033[0m"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2024-04-05 18:22:33 +08:00
|
|
|
|
#在允许的情况下创建/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
|
|
|
|
|
}
|
2023-01-13 20:37:27 +08:00
|
|
|
|
#梅林/Padavan额外设置
|
|
|
|
|
[ -n "$initdir" ] && {
|
2024-01-02 17:09:11 +08:00
|
|
|
|
sed -i '/ShellCrash初始化/'d $initdir
|
2023-01-13 20:37:27 +08:00
|
|
|
|
touch $initdir
|
2024-01-02 17:09:11 +08:00
|
|
|
|
echo "$CRASHDIR/start.sh init #ShellCrash初始化脚本" >> $initdir
|
2023-01-15 20:58:15 +08:00
|
|
|
|
chmod a+rx $initdir 2>/dev/null
|
2023-01-13 20:37:27 +08:00
|
|
|
|
setconfig initdir $initdir
|
2024-02-07 11:13:11 +08:00
|
|
|
|
}
|
|
|
|
|
#Padavan额外设置
|
|
|
|
|
[ -f "/etc/storage/started_script.sh" ] && mount -t tmpfs -o remount,rw,size=45M tmpfs /tmp #增加/tmp空间以适配新的内核压缩方式
|
2023-05-03 16:59:03 +08:00
|
|
|
|
#镜像化OpenWrt(snapshot)额外设置
|
|
|
|
|
if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then
|
2024-01-10 22:02:15 +08:00
|
|
|
|
chmod 755 ${CRASHDIR}/misnap_init.sh
|
2024-01-04 12:36:54 +08:00
|
|
|
|
uci delete firewall.ShellClash 2>/dev/null
|
|
|
|
|
uci delete firewall.ShellCrash 2>/dev/null
|
2024-01-02 17:09:11 +08:00
|
|
|
|
uci set firewall.ShellCrash=include
|
|
|
|
|
uci set firewall.ShellCrash.type='script'
|
|
|
|
|
uci set firewall.ShellCrash.path="$CRASHDIR/misnap_init.sh"
|
|
|
|
|
uci set firewall.ShellCrash.enabled='1'
|
2023-01-13 20:37:27 +08:00
|
|
|
|
uci commit firewall
|
|
|
|
|
setconfig systype $systype
|
|
|
|
|
else
|
2024-01-10 22:02:15 +08:00
|
|
|
|
rm -rf ${CRASHDIR}/misnap_init.sh
|
2023-01-13 20:37:27 +08:00
|
|
|
|
fi
|
|
|
|
|
#华硕USB启动额外设置
|
|
|
|
|
[ "$usb_status" = "1" ] && {
|
2024-01-10 22:02:15 +08:00
|
|
|
|
echo "$CRASHDIR/start.sh init #ShellCrash初始化脚本" > ${CRASHDIR}/asus_usb_mount.sh
|
2024-01-02 17:09:11 +08:00
|
|
|
|
nvram set script_usbmount="$CRASHDIR/asus_usb_mount.sh"
|
2023-01-13 20:37:27 +08:00
|
|
|
|
nvram commit
|
|
|
|
|
}
|
|
|
|
|
#删除临时文件
|
2024-01-06 22:35:41 +08:00
|
|
|
|
rm -rf /tmp/*rash*gz
|
2023-01-13 20:37:27 +08:00
|
|
|
|
rm -rf /tmp/SC_tmp
|
2023-07-21 20:39:10 +08:00
|
|
|
|
#转换&清理旧版本文件
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mkdir -p ${CRASHDIR}/yamls
|
|
|
|
|
mkdir -p ${CRASHDIR}/jsons
|
|
|
|
|
mkdir -p ${CRASHDIR}/tools
|
|
|
|
|
mkdir -p ${CRASHDIR}/task
|
2023-08-03 20:53:31 +08:00
|
|
|
|
for file in config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml ;do
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mv -f ${CRASHDIR}/$file ${CRASHDIR}/yamls/$file 2>/dev/null
|
2023-07-30 09:49:41 +08:00
|
|
|
|
done
|
2024-01-10 22:02:15 +08:00
|
|
|
|
[ ! -L ${CRASHDIR}/config.yaml ] && mv -f ${CRASHDIR}/config.yaml ${CRASHDIR}/yamls/config.yaml 2>/dev/null
|
2024-02-13 22:28:06 +08:00
|
|
|
|
for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list singbox_providers.list clash_providers.list;do
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mv -f ${CRASHDIR}/$file ${CRASHDIR}/configs/$file 2>/dev/null
|
2023-07-30 09:49:41 +08:00
|
|
|
|
done
|
2024-01-02 17:09:11 +08:00
|
|
|
|
#配置文件改名
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mv -f ${CRASHDIR}/mark ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null
|
|
|
|
|
mv -f ${CRASHDIR}/configs/ShellClash.cfg ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null
|
2024-02-26 10:36:45 +08:00
|
|
|
|
#数据库改名
|
|
|
|
|
mv -f ${CRASHDIR}/geosite.dat ${CRASHDIR}/GeoSite.dat 2>/dev/null
|
2024-01-05 13:24:07 +08:00
|
|
|
|
#内核改名
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mv -f ${CRASHDIR}/clash ${CRASHDIR}/CrashCore 2>/dev/null
|
2024-02-02 13:42:19 +08:00
|
|
|
|
#内核压缩
|
2024-02-01 23:14:28 +08:00
|
|
|
|
[ -f ${CRASHDIR}/CrashCore ] && tar -zcf ${CRASHDIR}/CrashCore.tar.gz -C ${CRASHDIR} CrashCore
|
2024-01-02 17:09:11 +08:00
|
|
|
|
for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh;do
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mv -f ${CRASHDIR}/$file ${CRASHDIR}/tools/$file 2>/dev/null
|
2024-01-02 17:09:11 +08:00
|
|
|
|
done
|
|
|
|
|
for file in cron task.sh task.list;do
|
2024-01-10 22:02:15 +08:00
|
|
|
|
mv -f ${CRASHDIR}/$file ${CRASHDIR}/task/$file 2>/dev/null
|
2023-07-30 09:49:41 +08:00
|
|
|
|
done
|
2024-01-06 22:35:41 +08:00
|
|
|
|
#旧版文件清理
|
2024-02-04 16:55:06 +08:00
|
|
|
|
userdel shellclash >/dev/null 2>&1
|
2024-01-30 11:40:55 +08:00
|
|
|
|
sed -i '/shellclash/d' /etc/passwd
|
|
|
|
|
sed -i '/shellclash/d' /etc/group
|
2024-01-10 22:02:15 +08:00
|
|
|
|
rm -rf /etc/init.d/clash
|
2024-01-24 16:09:10 +08:00
|
|
|
|
[ "$systype" = "mi_snapshot" -a "$CRASHDIR" != '/data/clash' ] && rm -rf /data/clash
|
2024-03-08 21:35:53 +08:00
|
|
|
|
for file in CrashCore clash.sh getdate.sh shellcrash.rc core.new clashservice log shellcrash.service mark? mark.bak;do
|
2024-01-10 22:02:15 +08:00
|
|
|
|
rm -rf ${CRASHDIR}/$file
|
2023-07-30 09:49:41 +08:00
|
|
|
|
done
|
2024-01-06 22:35:41 +08:00
|
|
|
|
#旧版变量改名
|
|
|
|
|
sed -i "s/clashcore/crashcore/g" $configpath
|
2024-01-11 15:04:51 +08:00
|
|
|
|
sed -i "s/clash_v/core_v/g" $configpath
|
2024-01-10 22:02:15 +08:00
|
|
|
|
sed -i "s/clash.meta/meta/g" $configpath
|
2024-01-06 22:35:41 +08:00
|
|
|
|
sed -i "s/ShellClash/ShellCrash/g" $configpath
|
2024-01-30 23:12:52 +08:00
|
|
|
|
sed -i "s/cpucore=armv8/cpucore=arm64/g" $configpath
|
2024-03-03 19:12:31 +08:00
|
|
|
|
sed -i "s/redir_mod=Nft基础/redir_mod=Redir模式/g" $configpath
|
|
|
|
|
sed -i "s/redir_mod=Nft混合/redir_mod=Tproxy模式/g" $configpath
|
2024-03-15 16:15:19 +08:00
|
|
|
|
sed -i "s/redir_mod=Tproxy混合/redir_mod=Tproxy模式/g" $configpath
|
2024-03-08 21:35:53 +08:00
|
|
|
|
sed -i "s/redir_mod=纯净模式/firewall_area=4/g" $configpath
|
2024-01-11 15:04:51 +08:00
|
|
|
|
|
2024-01-02 17:09:11 +08:00
|
|
|
|
echo -e "\033[32m脚本初始化完成,请输入\033[30;47m crash \033[0;33m命令开始使用!\033[0m"
|