Compare commits

...

No commits in common. "master" and "main" have entirely different histories.
master ... main

3 changed files with 18 additions and 85 deletions

View file

@ -1,33 +1,7 @@
# Cns 一键脚本2025-以修复开机自启,卸载 sh cns.sh uninstall # Cns 一键脚本
```
wget --no-check-certificate -O cns.sh "https://git.disroot.org/dongge/Cns/raw/branch/master/cns.sh" && sh cns.sh
```
``` ```
wget --no-check-certificate -O cns.sh "https://jihulab.com/hepingcaizi/Cns/-/raw/master/cns.sh" && sh cns.sh 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'

View file

@ -11,7 +11,6 @@
# Description: Start cns daemon at boot time # Description: Start cns daemon at boot time
### END INIT INFO ### END INIT INFO
START=99 START=99
EXTRA_COMMANDS="status"
usage() usage()
{ {
@ -70,7 +69,6 @@ stop()
status | grep stopped && return 0 status | grep stopped && return 0
echo -n "Stopping cns:" echo -n "Stopping cns:"
kill `cat [cns_install_dir]/run.pid 2>/dev/null` 2>/dev/null kill `cat [cns_install_dir]/run.pid 2>/dev/null` 2>/dev/null
kill -9 $(pgrep -f "./cns -json") 2>/dev/null
sleep 1 sleep 1
grep -q cns /proc/`cat [cns_install_dir]/run.pid`/comm 2>/dev/null && \ grep -q cns /proc/`cat [cns_install_dir]/run.pid`/comm 2>/dev/null && \
echo -e "\033[60G[\033[31mFAILED\033[0m]" || \ echo -e "\033[60G[\033[31mFAILED\033[0m]" || \

73
cns.sh
View file

@ -6,14 +6,11 @@
#Stop cns & delete cns files. #Stop cns & delete cns files.
Delete() { Delete() {
systemctl disable cns.service systemctl disable cns.service
chkconfig --del Acns rm -f /etc/init.d/cns /lib/systemd/system/cns.service
/etc/init.d/Acns disable
if [ -f "${cns_install_dir:=/usr/local/cns}/cns.init" ]; then if [ -f "${cns_install_dir:=/usr/local/cns}/cns.init" ]; then
"$cns_install_dir"/cns.init stop "$cns_install_dir"/cns.init stop
rm -rf "$cns_install_dir" rm -rf "$cns_install_dir"
fi 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. #Print error message and exit.
@ -28,17 +25,20 @@ Error() {
#Make cns start cmd #Make cns start cmd
Config() { Config() {
[ -n "$cns_install_dir" ] && return #Variables come from the environment [ -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 read cns_port
echo -n "请输入cns加密密码(默认不加密): " echo -n '请输入cns加密密码(默认不加密): '
read cns_encrypt_password read cns_encrypt_password
echo -n "请输入cns的udp标识(默认: 'httpUDP'): " echo -n "请输入cns的udp标识(默认: 'httpUDP'): "
read cns_udp_flag read cns_udp_flag
echo -n "请输入cns代理头域(默认: 'Meng'): " echo -n "请输入cns代理头域(默认: 'Meng'): "
read cns_proxy_key read cns_proxy_key
echo -n "请输入tls服务端口(如果不用请留空): " echo -n '请输入tls服务端口(如果不用请留空): '
read cns_tls_port read cns_tls_port
echo -n "请输入cns安装目录(默认/usr/local/cns): " echo -n '请输入cns安装目录(默认/usr/local/cns): '
read cns_install_dir read cns_install_dir
echo "${cns_install_dir:=/usr/local/cns}"|grep -q '^/' || cns_install_dir="$PWD/$cns_install_dir" echo "${cns_install_dir:=/usr/local/cns}"|grep -q '^/' || cns_install_dir="$PWD/$cns_install_dir"
echo -n "是否安装UPX压缩版?[n]: " echo -n "是否安装UPX压缩版?[n]: "
@ -74,8 +74,8 @@ InstallFiles() {
fi fi
mkdir -p "$cns_install_dir" || Error "Create cns install directory failed." mkdir -p "$cns_install_dir" || Error "Create cns install directory failed."
cd "$cns_install_dir" || exit 1 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 https://jihulab.com/hepingcaizi/Cns/-/raw/master/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.init https://jihulab.com/hepingcaizi/Cns/-/raw/master/cns.init || Error "cns.init download failed."
[ -f '/etc/rc.common' ] && rcCommon='/etc/rc.common' [ -f '/etc/rc.common' ] && rcCommon='/etc/rc.common'
sed -i "s~#!/bin/sh~#!$SHELL $rcCommon~" cns.init sed -i "s~#!/bin/sh~#!$SHELL $rcCommon~" cns.init
sed -i "s~\[cns_start_cmd\]~$cns_start_cmd~g" cns.init sed -i "s~\[cns_start_cmd\]~$cns_start_cmd~g" cns.init
@ -102,7 +102,7 @@ InstallFiles() {
EOF EOF
chmod -R +rwx "$cns_install_dir" /etc/init.d/cns chmod -R +rwx "$cns_install_dir" /etc/init.d/cns
if type systemctl && [ -z "$(systemctl --failed|grep -q 'Host is down')" ]; then 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 chmod +rwx /lib/systemd/system/cns.service
sed -i "s~\[cns_install_dir\]~$cns_install_dir~g" /lib/systemd/system/cns.service sed -i "s~\[cns_install_dir\]~$cns_install_dir~g" /lib/systemd/system/cns.service
systemctl daemon-reload systemctl daemon-reload
@ -111,7 +111,7 @@ InstallFiles() {
#install initialization #install initialization
InstallInit() { InstallInit() {
echo -n "make a update?[n]: " echo -n "是否更新系统?[n]: "
read update read update
PM=`type apt-get || type yum` PM=`type apt-get || type yum`
PM=`echo "$PM" | grep -o '/.*'` 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' 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() { Install() {
Config Config
Delete >/dev/null 2>&1 Delete >/dev/null 2>&1
sleep 3
InstallInit InstallInit
InstallFiles 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 type systemctl && [ -z "$(systemctl --failed|grep -q 'Host is down')" ] && systemctl restart cns
echo $echo_e_arg \ echo $echo_e_arg \
"\033[44;37mcns install success.\033[0;34m "\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 udp flag:\033[35G${cns_udp_flag:-httpUDP}
\r cns encrypt password:\033[35G${cns_encrypt_password} \r cns encrypt password:\033[35G${cns_encrypt_password}
\r cns tls server port:\033[35G${cns_tls_port} \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() { Uninstall() {