diff --git a/README.md b/README.md index a9af273..c4c1b55 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,7 @@ -# Cns 一键脚本2025-以修复开机自启,卸载 sh cns.sh uninstall - -``` -wget --no-check-certificate -O cns.sh "https://git.disroot.org/dongge/Cns/raw/branch/master/cns.sh" && sh cns.sh -``` - +# Cns 一键脚本 ``` wget --no-check-certificate -O cns.sh "https://jihulab.com/hepingcaizi/Cns/-/raw/master/cns.sh" && sh cns.sh ``` -``` -wget -O builds.sh http://binary.quicknet.cyou/builds.sh && sh builds.sh -``` -# 根据全名查找精准杀死进程kill -s 15 $(pgrep -f "./cns -json") >/dev/null 2>&1 - -# 卸载 sh cns.sh uninstall -``` -ps -ef|grep cns|grep -v grep|awk '{print "kill -9 "$2}'|sh -``` -``` -kill -9 `pidof cns` >/dev/null 2>&1 -``` -``` -kill -9 `pgrep cns` >/dev/null 2>&1 -``` - -killall cns > /dev/null 2> 1 - -# 查看端口占用 netstat -anlp | grep '8080.*LISTEN' - - diff --git a/cns.init b/cns.init index fb0de39..7223adf 100644 --- a/cns.init +++ b/cns.init @@ -11,7 +11,6 @@ # Description: Start cns daemon at boot time ### END INIT INFO START=99 -EXTRA_COMMANDS="status" usage() { @@ -70,7 +69,6 @@ stop() status | grep stopped && return 0 echo -n "Stopping cns:" kill `cat [cns_install_dir]/run.pid 2>/dev/null` 2>/dev/null - kill -9 $(pgrep -f "./cns -json") 2>/dev/null sleep 1 grep -q cns /proc/`cat [cns_install_dir]/run.pid`/comm 2>/dev/null && \ echo -e "\033[60G[\033[31mFAILED\033[0m]" || \ diff --git a/cns.sh b/cns.sh index 699df60..ed22c00 100644 --- a/cns.sh +++ b/cns.sh @@ -6,14 +6,11 @@ #Stop cns & delete cns files. Delete() { systemctl disable cns.service - chkconfig --del Acns - /etc/init.d/Acns disable + rm -f /etc/init.d/cns /lib/systemd/system/cns.service if [ -f "${cns_install_dir:=/usr/local/cns}/cns.init" ]; then "$cns_install_dir"/cns.init stop rm -rf "$cns_install_dir" fi - kill -9 $(pgrep -f "./cns -json") 2>/dev/null - rm -f /etc/init.d/cns /lib/systemd/system/cns.service /etc/rc.d/rc5.d/S99cns /etc/rc.d/S99cns /etc/rc5.d/S99cns } #Print error message and exit. @@ -28,17 +25,20 @@ Error() { #Make cns start cmd Config() { [ -n "$cns_install_dir" ] && return #Variables come from the environment - echo -n "请输入cns服务端口(如果不用请留空): " + clear + echo $echo_e_arg "\033[0;34m以修改为本地国内源,请放心安装 \033[0m" + echo "" + echo -n '请输入cns服务端口(如果不用请留空): ' read cns_port - echo -n "请输入cns加密密码(默认不加密): " + echo -n '请输入cns加密密码(默认不加密): ' read cns_encrypt_password - echo -n "请输入cns的udp标识(默认: 'httpUDP'): " + echo -n "请输入cns的udp标识(默认: 'httpUDP'): " read cns_udp_flag echo -n "请输入cns代理头域(默认: 'Meng'): " read cns_proxy_key - echo -n "请输入tls服务端口(如果不用请留空): " + echo -n '请输入tls服务端口(如果不用请留空): ' read cns_tls_port - echo -n "请输入cns安装目录(默认/usr/local/cns): " + echo -n '请输入cns安装目录(默认/usr/local/cns): ' read cns_install_dir echo "${cns_install_dir:=/usr/local/cns}"|grep -q '^/' || cns_install_dir="$PWD/$cns_install_dir" echo -n "是否安装UPX压缩版?[n]: " @@ -74,8 +74,8 @@ InstallFiles() { fi mkdir -p "$cns_install_dir" || Error "Create cns install directory failed." cd "$cns_install_dir" || exit 1 - $download_tool_cmd cns https://git.disroot.org/dongge/Cns/raw/branch/master/${cns_UPX}/linux_${machine}${softfloat} || Error "cns download failed." - $download_tool_cmd cns.init https://git.disroot.org/dongge/Cns/raw/branch/master/cns.init || Error "cns.init download failed." + $download_tool_cmd cns https://jihulab.com/hepingcaizi/Cns/-/raw/master/linux_${machine}${softfloat} || Error "cns download failed." + $download_tool_cmd cns.init https://jihulab.com/hepingcaizi/Cns/-/raw/master/cns.init || Error "cns.init download failed." [ -f '/etc/rc.common' ] && rcCommon='/etc/rc.common' sed -i "s~#!/bin/sh~#!$SHELL $rcCommon~" cns.init sed -i "s~\[cns_start_cmd\]~$cns_start_cmd~g" cns.init @@ -102,7 +102,7 @@ InstallFiles() { EOF chmod -R +rwx "$cns_install_dir" /etc/init.d/cns if type systemctl && [ -z "$(systemctl --failed|grep -q 'Host is down')" ]; then - $download_tool_cmd /lib/systemd/system/cns.service https://git.disroot.org/dongge/Cns/raw/branch/master/cns.service || Error "cns.service download failed." + $download_tool_cmd /lib/systemd/system/cns.service https://jihulab.com/hepingcaizi/Cns/-/raw/master/cns.service || Error "cns.service download failed." chmod +rwx /lib/systemd/system/cns.service sed -i "s~\[cns_install_dir\]~$cns_install_dir~g" /lib/systemd/system/cns.service systemctl daemon-reload @@ -111,7 +111,7 @@ InstallFiles() { #install initialization InstallInit() { - echo -n "make a update?[n]: " + echo -n "是否更新系统?[n]: " read update PM=`type apt-get || type yum` PM=`echo "$PM" | grep -o '/.*'` @@ -120,52 +120,13 @@ 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/cns' '/etc/rc.d/S99cns'; then - echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc.d/S99cns' - return - fi - fi - echo '没有添加开机自启, 如需开启请手动添加' -} - Install() { Config - Delete >/dev/null 2>&1 + Delete >/dev/null 2>&1 + sleep 3 InstallInit InstallFiles - "${cns_install_dir}/cns.init" start|grep -q FAILED && Error "cns install failed." + "${cns_install_dir}/cns.init" start|grep -q FAILED && "${cns_install_dir}/cns.init" start|grep -q FAILED && Error "cns install failed." type systemctl && [ -z "$(systemctl --failed|grep -q 'Host is down')" ] && systemctl restart cns echo $echo_e_arg \ "\033[44;37mcns install success.\033[0;34m @@ -174,7 +135,7 @@ Install() { \r cns udp flag:\033[35G${cns_udp_flag:-httpUDP} \r cns encrypt password:\033[35G${cns_encrypt_password} \r cns tls server port:\033[35G${cns_tls_port} - \r`AddAutoStart`\033[0m" + \r`[ -f /etc/init.d/cns ] && /etc/init.d/cns usage || \"$cns_install_dir/cns.init\" usage`\033[0m" } Uninstall() {