From 6a4d5c953686c42807450408e95919fdc77df24a Mon Sep 17 00:00:00 2001 From: "cnb.dg2025-08" Date: Sun, 14 Sep 2025 08:18:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=96=87=E4=BB=B6=20cns.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cns/cns.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/cns/cns.sh b/cns/cns.sh index 07093a2..c627476 100644 --- a/cns/cns.sh +++ b/cns/cns.sh @@ -117,6 +117,46 @@ InstallInit() { type curl && download_tool_cmd='curl -L -ko' || download_tool_cmd='wget --no-check-certificate -O' } +AddAutoStart() { + if [ -n "$rcCommon" ]; then + if /etc/init.d/cns enable; then + echo '已添加开机自启, 如需关闭请执行: /etc/init.d/cns disable' + return + fi + fi + if type systemctl &>/dev/null && [ -z "$(systemctl --failed|grep -q 'Host is down')" ]; then + if systemctl enable cns &>/dev/null; then + echo '已添加开机自启, 如需关闭请执行: systemctl disable cns' + return + fi + fi + if type chkconfig &>/dev/null; then + if chkconfig --add cns &>/dev/null && chkconfig cns on &>/dev/null; then + echo '已添加开机自启, 如需关闭请执行: chkconfig cns off' + return + fi + fi + if [ -d '/etc/rc.d/rc5.d' -a -f '/etc/init.d/cns' ]; then + if ln -s '/etc/init.d/cns' '/etc/rc.d/rc5.d/S99cns'; then + echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc.d/rc5.d/S99cns' + return + fi + fi + if [ -d '/etc/rc5.d' -a -f '/etc/init.d/cns' ]; then + if ln -s '/etc/init.d/cns' '/etc/rc5.d/S99cns'; then + echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc5.d/S99cns' + return + fi + fi + if [ -d '/etc/rc.d' -a -f '/etc/init.d/cns' ]; then + if ln -s '/etc/init.d/Acns' '/etc/rc.d/S99cns'; then + echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc.d/S99cns' + return + fi + fi + echo '没有添加开机自启, 如需开启请手动添加' +} + Install() { Config Delete >/dev/null 2>&1 @@ -132,6 +172,7 @@ Install() { \r cns encrypt password:\033[35G${cns_encrypt_password} \r cns tls server port:\033[35G${cns_tls_port} \r`[ -f /etc/init.d/Acns ] && /etc/init.d/Acns usage || \"$cns_install_dir/cns.init\" usage`\033[0m" + \r`AddAutoStart`\033[0m" } Uninstall() {