~新增openrc启动模式兼容
This commit is contained in:
@@ -177,14 +177,14 @@ mv -f /tmp/SC_tmp/* ${CRASHDIR} 2>/dev/null
|
|||||||
mkdir -p ${CRASHDIR}/configs
|
mkdir -p ${CRASHDIR}/configs
|
||||||
[ -f "${CRASHDIR}/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' >${CRASHDIR}/configs/ShellCrash.cfg
|
[ -f "${CRASHDIR}/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' >${CRASHDIR}/configs/ShellCrash.cfg
|
||||||
#判断系统类型写入不同的启动文件
|
#判断系统类型写入不同的启动文件
|
||||||
|
[ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
|
||||||
|
[ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
|
||||||
if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
|
if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
|
||||||
#设为init.d方式启动
|
#设为init.d方式启动
|
||||||
cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash
|
cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash
|
||||||
chmod 755 /etc/init.d/shellcrash
|
chmod 755 /etc/init.d/shellcrash
|
||||||
else
|
rm -rf ${CRASHDIR}/shellcrash.openrc
|
||||||
[ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
|
elif [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ]; then
|
||||||
[ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
|
|
||||||
if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ]; then
|
|
||||||
#创建shellcrash用户
|
#创建shellcrash用户
|
||||||
userdel shellcrash 2>/dev/null
|
userdel shellcrash 2>/dev/null
|
||||||
sed -i '/0:7890/d' /etc/passwd
|
sed -i '/0:7890/d' /etc/passwd
|
||||||
@@ -198,32 +198,17 @@ else
|
|||||||
#配置systemd
|
#配置systemd
|
||||||
mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null
|
mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null
|
||||||
sed -i "s%/etc/ShellCrash%$CRASHDIR%g" $sysdir/shellcrash.service
|
sed -i "s%/etc/ShellCrash%$CRASHDIR%g" $sysdir/shellcrash.service
|
||||||
rm -rf $sysdir/clash.service #旧版文件清理
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
else
|
elif rc-status -r >/dev/null 2>&1; then
|
||||||
|
#设为openrc方式启动
|
||||||
|
cp -f ${CRASHDIR}/shellcrash.openrc /etc/init.d/shellcrash
|
||||||
|
chmod 755 /etc/init.d/shellcrash
|
||||||
|
rm -rf ${CRASHDIR}/shellcrash.procd
|
||||||
|
else
|
||||||
#设为保守模式启动
|
#设为保守模式启动
|
||||||
systemctl disable shellcrash 2>/dev/null
|
|
||||||
setconfig start_old 已开启
|
setconfig start_old 已开启
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 在此处添加Alpine OpenRC配置(约第220-230行附近)
|
|
||||||
# Alpine Linux (OpenRC) 自启动配置
|
|
||||||
if [ -f "/sbin/openrc" ] && [ "$(cat /proc/1/comm)" = "init" ]; then
|
|
||||||
# 创建启动脚本
|
|
||||||
if [ ! -f "/etc/local.d/shellcrash.start" ]; then
|
|
||||||
echo "#!/bin/sh" > /etc/local.d/shellcrash.start
|
|
||||||
echo "${CRASHDIR}/start.sh start &" >> /etc/local.d/shellcrash.start
|
|
||||||
chmod +x /etc/local.d/shellcrash.start
|
|
||||||
fi
|
|
||||||
# 添加到默认运行级别
|
|
||||||
rc-update add local default >/dev/null 2>&1
|
|
||||||
setconfig autostart "enable"
|
|
||||||
logger "已配置Alpine系统自启动" 32
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#修饰文件及版本号
|
#修饰文件及版本号
|
||||||
command -v bash >/dev/null 2>&1 && shtype=bash
|
command -v bash >/dev/null 2>&1 && shtype=bash
|
||||||
[ -x /bin/ash ] && shtype=ash
|
[ -x /bin/ash ] && shtype=ash
|
||||||
@@ -232,7 +217,7 @@ for file in start.sh task.sh menu.sh; do
|
|||||||
chmod 755 ${CRASHDIR}/${file}
|
chmod 755 ${CRASHDIR}/${file}
|
||||||
done
|
done
|
||||||
setconfig versionsh_l $version
|
setconfig versionsh_l $version
|
||||||
#生成用于执行systemd及procd服务的变量文件
|
#生成用于执行启动服务的变量文件
|
||||||
[ ! -f ${CRASHDIR}/configs/command.env ] && {
|
[ ! -f ${CRASHDIR}/configs/command.env ] && {
|
||||||
TMPDIR='/tmp/ShellCrash'
|
TMPDIR='/tmp/ShellCrash'
|
||||||
BINDIR=${CRASHDIR}
|
BINDIR=${CRASHDIR}
|
||||||
@@ -351,7 +336,7 @@ sed -i '/shellclash/d' /etc/group
|
|||||||
rm -rf /etc/init.d/clash
|
rm -rf /etc/init.d/clash
|
||||||
rm -rf ${CRASHDIR}/rules
|
rm -rf ${CRASHDIR}/rules
|
||||||
[ "$systype" = "mi_snapshot" -a "$CRASHDIR" != '/data/clash' ] && rm -rf /data/clash
|
[ "$systype" = "mi_snapshot" -a "$CRASHDIR" != '/data/clash' ] && rm -rf /data/clash
|
||||||
for file in CrashCore clash.sh getdate.sh shellcrash.rc core.new clashservice log shellcrash.service mark? mark.bak; do
|
for file in CrashCore clash.sh getdate.sh core.new clashservice log shellcrash.service mark? mark.bak; do
|
||||||
rm -rf ${CRASHDIR}/$file
|
rm -rf ${CRASHDIR}/$file
|
||||||
done
|
done
|
||||||
#旧版变量改名
|
#旧版变量改名
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ ckstatus() {
|
|||||||
[ -n "$(find /etc/rc.d -name '*shellcrash')" ] && autostart=enable || autostart=disable
|
[ -n "$(find /etc/rc.d -name '*shellcrash')" ] && autostart=enable || autostart=disable
|
||||||
elif ckcmd systemctl; then
|
elif ckcmd systemctl; then
|
||||||
[ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && autostart=enable || autostart=disable
|
[ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && autostart=enable || autostart=disable
|
||||||
|
elif rc-status -r >/dev/null 2>&1; then
|
||||||
|
rc-update show default | grep -q "shellcrash" && autostart=enable || autostart=disable
|
||||||
else
|
else
|
||||||
[ -f ${CRASHDIR}/.dis_startup ] && autostart=disable || autostart=enable
|
[ -f ${CRASHDIR}/.dis_startup ] && autostart=disable || autostart=enable
|
||||||
fi
|
fi
|
||||||
@@ -1169,7 +1171,7 @@ setboot() { #启动相关设置
|
|||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
echo -e "\033[30;47m欢迎使用启动设置菜单:\033[0m"
|
echo -e "\033[30;47m欢迎使用启动设置菜单:\033[0m"
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
echo -e " 1 ${auto_set}\033[0mShellCrash开机启动(alpine需先禁用再启用)"
|
echo -e " 1 ${auto_set}\033[0mShellCrash开机启动"
|
||||||
echo -e " 2 使用保守模式: \033[36m$start_old\033[0m ————基于定时任务(每分钟检测)"
|
echo -e " 2 使用保守模式: \033[36m$start_old\033[0m ————基于定时任务(每分钟检测)"
|
||||||
echo -e " 3 设置自启延时: \033[36m$delay\033[0m ————用于解决自启后服务受限"
|
echo -e " 3 设置自启延时: \033[36m$delay\033[0m ————用于解决自启后服务受限"
|
||||||
echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————用于闪存空间不足的设备"
|
echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————用于闪存空间不足的设备"
|
||||||
@@ -1186,8 +1188,7 @@ setboot() { #启动相关设置
|
|||||||
# 禁止自启动:删除各系统的启动项
|
# 禁止自启动:删除各系统的启动项
|
||||||
[ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *shellcrash >/dev/null 2>&1 && cd - >/dev/null
|
[ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *shellcrash >/dev/null 2>&1 && cd - >/dev/null
|
||||||
ckcmd systemctl && systemctl disable shellcrash.service >/dev/null 2>&1
|
ckcmd systemctl && systemctl disable shellcrash.service >/dev/null 2>&1
|
||||||
# 新增:删除Alpine的启动脚本
|
[rc-status -r >/dev/null 2>&1 && rc-update del shellcrash default >/dev/null
|
||||||
[ -f "/sbin/openrc" ] && rm -f /etc/local.d/shellcrash.start
|
|
||||||
touch ${CRASHDIR}/.dis_startup
|
touch ${CRASHDIR}/.dis_startup
|
||||||
autostart=disable
|
autostart=disable
|
||||||
echo -e "\033[33m已禁止ShellCrash开机启动!\033[0m"
|
echo -e "\033[33m已禁止ShellCrash开机启动!\033[0m"
|
||||||
@@ -1195,15 +1196,7 @@ setboot() { #启动相关设置
|
|||||||
# 允许自启动:配置各系统的启动项
|
# 允许自启动:配置各系统的启动项
|
||||||
[ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ] && /etc/init.d/shellcrash enable
|
[ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ] && /etc/init.d/shellcrash enable
|
||||||
ckcmd systemctl && systemctl enable shellcrash.service >/dev/null 2>&1
|
ckcmd systemctl && systemctl enable shellcrash.service >/dev/null 2>&1
|
||||||
# 新增:配置Alpine的启动脚本
|
rc-status -r >/dev/null 2>&1 && rc-update add shellcrash default >/dev/null
|
||||||
if [ -f "/sbin/openrc" ]; then
|
|
||||||
[ ! -f "/etc/local.d/shellcrash.start" ] && {
|
|
||||||
echo "#!/bin/sh" > /etc/local.d/shellcrash.start
|
|
||||||
echo "${CRASHDIR}/start.sh start &" >> /etc/local.d/shellcrash.start
|
|
||||||
chmod +x /etc/local.d/shellcrash.start
|
|
||||||
}
|
|
||||||
rc-update add local default >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
rm -rf ${CRASHDIR}/.dis_startup
|
rm -rf ${CRASHDIR}/.dis_startup
|
||||||
autostart=enable
|
autostart=enable
|
||||||
echo -e "\033[32m已设置ShellCrash开机启动!\033[0m"
|
echo -e "\033[32m已设置ShellCrash开机启动!\033[0m"
|
||||||
@@ -1219,7 +1212,7 @@ setboot() { #启动相关设置
|
|||||||
setconfig start_old $start_old
|
setconfig start_old $start_old
|
||||||
${CRASHDIR}/start.sh stop
|
${CRASHDIR}/start.sh stop
|
||||||
else
|
else
|
||||||
if [ "$(cat /proc/1/comm)" = "procd" -o "$(cat /proc/1/comm)" = "systemd" ]; then
|
if grep -qE 'procd|systemd' /proc/1/comm || rc-status -r >/dev/null 2>&1; then
|
||||||
echo -e "\033[32m改为使用系统守护进程启动服务!!\033[0m"
|
echo -e "\033[32m改为使用系统守护进程启动服务!!\033[0m"
|
||||||
${CRASHDIR}/start.sh cronset "ShellCrash初始化"
|
${CRASHDIR}/start.sh cronset "ShellCrash初始化"
|
||||||
start_old=未开启
|
start_old=未开启
|
||||||
@@ -2060,7 +2053,7 @@ tools() {
|
|||||||
[ -f /etc/firewall.user ] && echo -e " 4 \033[32m配置\033[0m外网访问SSH"
|
[ -f /etc/firewall.user ] && echo -e " 4 \033[32m配置\033[0m外网访问SSH"
|
||||||
[ -x /usr/sbin/otapredownload ] && echo -e " 5 \033[33m$mi_update\033[0m小米系统自动更新"
|
[ -x /usr/sbin/otapredownload ] && echo -e " 5 \033[33m$mi_update\033[0m小米系统自动更新"
|
||||||
[ "$systype" = "mi_snapshot" ] && echo -e " 6 小米设备软固化SSH ———— \033[$mi_autoSSH_type \033[0m"
|
[ "$systype" = "mi_snapshot" ] && echo -e " 6 小米设备软固化SSH ———— \033[$mi_autoSSH_type \033[0m"
|
||||||
[ -d /etc/ddns ] && echo -e " 7 配置\033[32mDDNS服务\033[0m(需下载相关脚本)"
|
[ -f /etc/config/ddns ] && echo -e " 7 配置\033[32mDDNS服务\033[0m(需下载相关脚本)"
|
||||||
[ "$systype" = "mi_snapshot" ] && echo -e " 8 小米设备Tun模块修复 ———— \033[$mi_tunfix \033[0m"
|
[ "$systype" = "mi_snapshot" ] && echo -e " 8 小米设备Tun模块修复 ———— \033[$mi_tunfix \033[0m"
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
echo -e " 0 返回上级菜单"
|
echo -e " 0 返回上级菜单"
|
||||||
@@ -2093,12 +2086,12 @@ tools() {
|
|||||||
${CRASHDIR}/start.sh get_bin ${TMPDIR}/ShellDDNS.sh tools/ShellDDNS.sh
|
${CRASHDIR}/start.sh get_bin ${TMPDIR}/ShellDDNS.sh tools/ShellDDNS.sh
|
||||||
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
||||||
mv -f ${TMPDIR}/ShellDDNS.sh ${CRASHDIR}/tools/ShellDDNS.sh
|
mv -f ${TMPDIR}/ShellDDNS.sh ${CRASHDIR}/tools/ShellDDNS.sh
|
||||||
source ${CRASHDIR}/tools/ShellDDNS.sh
|
. ${CRASHDIR}/tools/ShellDDNS.sh
|
||||||
else
|
else
|
||||||
echo -e "\033[31m文件下载失败!\033[0m"
|
echo -e "\033[31m文件下载失败!\033[0m"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
source ${CRASHDIR}/tools/ShellDDNS.sh
|
. ${CRASHDIR}/tools/ShellDDNS.sh
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
tools
|
tools
|
||||||
|
|||||||
74
scripts/shellcrash.openrc
Normal file
74
scripts/shellcrash.openrc
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/sbin/openrc-run
|
||||||
|
|
||||||
|
# 服务名
|
||||||
|
name="ShellCrash"
|
||||||
|
description="Custom proxy service for ShellCrash"
|
||||||
|
#获取目录
|
||||||
|
CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
|
||||||
|
[ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}')
|
||||||
|
source ${CRASHDIR}/configs/command.env #加载启动命令和启动目录
|
||||||
|
|
||||||
|
# PID 文件
|
||||||
|
pidfile="/run/shellcrash.pid"
|
||||||
|
|
||||||
|
depend() {
|
||||||
|
#need net
|
||||||
|
after firewall
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
ebegin "Starting ShellCrash service"
|
||||||
|
|
||||||
|
# 如果 firewal_area=5 则运行主旁转发脚本
|
||||||
|
if grep -q 'firewall_area=5' "$CRASHDIR/configs/ShellCrash.cfg" 2>/dev/null; then
|
||||||
|
"$CRASHDIR/start.sh" start_firewall
|
||||||
|
eend $? "Firewall start failed"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 确定运行用户:shellcrash 或 root
|
||||||
|
if grep -q 'shellcrash:x:0:7890' /etc/passwd; then
|
||||||
|
runuser="shellcrash"
|
||||||
|
else
|
||||||
|
runuser="root"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 必要文件检测
|
||||||
|
"$CRASHDIR/start.sh" bfstart
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
eend 1 "bfstart check failed"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 启动主程序(后台进程)
|
||||||
|
start-stop-daemon --start \
|
||||||
|
--background \
|
||||||
|
--make-pidfile \
|
||||||
|
--pidfile "${pidfile}" \
|
||||||
|
--user "${runuser}" \
|
||||||
|
--exec ${COMMAND%% *} -- ${COMMAND#* }
|
||||||
|
|
||||||
|
ret=$?
|
||||||
|
eend $ret
|
||||||
|
[ $ret -ne 0 ] && return
|
||||||
|
|
||||||
|
# 启动后操作
|
||||||
|
"$CRASHDIR/start.sh" afstart &
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
ebegin "Stopping ShellCrash service"
|
||||||
|
|
||||||
|
# 停止后台进程
|
||||||
|
start-stop-daemon --stop \
|
||||||
|
--pidfile "${pidfile}" \
|
||||||
|
--retry 5
|
||||||
|
|
||||||
|
rm -f "${pidfile}"
|
||||||
|
|
||||||
|
# 清理 firewall、proxy
|
||||||
|
"$CRASHDIR/start.sh" stop_firewall
|
||||||
|
"$CRASHDIR/start.sh" unset_proxy
|
||||||
|
|
||||||
|
eend $?
|
||||||
|
}
|
||||||
@@ -2032,6 +2032,8 @@ start)
|
|||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl start shellcrash.service || start_error
|
systemctl start shellcrash.service || start_error
|
||||||
}
|
}
|
||||||
|
elif rc-status -r >/dev/null 2>&1; then
|
||||||
|
rc-service shellcrash start >/dev/null 2>&1
|
||||||
else
|
else
|
||||||
bfstart && start_old
|
bfstart && start_old
|
||||||
fi
|
fi
|
||||||
@@ -2052,6 +2054,8 @@ stop)
|
|||||||
systemctl stop shellcrash.service >/dev/null 2>&1
|
systemctl stop shellcrash.service >/dev/null 2>&1
|
||||||
elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
|
elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
|
||||||
/etc/init.d/shellcrash stop >/dev/null 2>&1
|
/etc/init.d/shellcrash stop >/dev/null 2>&1
|
||||||
|
elif rc-status -r >/dev/null 2>&1; then
|
||||||
|
rc-service shellcrash stop >/dev/null 2>&1
|
||||||
else
|
else
|
||||||
stop_firewall #清理路由策略
|
stop_firewall #清理路由策略
|
||||||
unset_proxy #禁用本机代理
|
unset_proxy #禁用本机代理
|
||||||
|
|||||||
Reference in New Issue
Block a user