Compare commits
No commits in common. "main" and "master" have entirely different histories.
3 changed files with 85 additions and 18 deletions
28
README.md
28
README.md
|
|
@ -1,7 +1,33 @@
|
|||
# Cns 一键脚本
|
||||
# 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
|
||||
```
|
||||
|
||||
```
|
||||
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'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
2
cns.init
2
cns.init
|
|
@ -11,6 +11,7 @@
|
|||
# Description: Start cns daemon at boot time
|
||||
### END INIT INFO
|
||||
START=99
|
||||
EXTRA_COMMANDS="status"
|
||||
|
||||
usage()
|
||||
{
|
||||
|
|
@ -69,6 +70,7 @@ 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]" || \
|
||||
|
|
|
|||
73
cns.sh
73
cns.sh
|
|
@ -6,11 +6,14 @@
|
|||
#Stop cns & delete cns files.
|
||||
Delete() {
|
||||
systemctl disable cns.service
|
||||
rm -f /etc/init.d/cns /lib/systemd/system/cns.service
|
||||
chkconfig --del Acns
|
||||
/etc/init.d/Acns disable
|
||||
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.
|
||||
|
|
@ -25,20 +28,17 @@ Error() {
|
|||
#Make cns start cmd
|
||||
Config() {
|
||||
[ -n "$cns_install_dir" ] && return #Variables come from the environment
|
||||
clear
|
||||
echo $echo_e_arg "\033[0;34m以修改为本地国内源,请放心安装 \033[0m"
|
||||
echo ""
|
||||
echo -n '请输入cns服务端口(如果不用请留空): '
|
||||
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://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."
|
||||
$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."
|
||||
[ -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://jihulab.com/hepingcaizi/Cns/-/raw/master/cns.service || Error "cns.service download failed."
|
||||
$download_tool_cmd /lib/systemd/system/cns.service https://git.disroot.org/dongge/Cns/raw/branch/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 "是否更新系统?[n]: "
|
||||
echo -n "make a update?[n]: "
|
||||
read update
|
||||
PM=`type apt-get || type yum`
|
||||
PM=`echo "$PM" | grep -o '/.*'`
|
||||
|
|
@ -120,13 +120,52 @@ 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
|
||||
sleep 3
|
||||
Delete >/dev/null 2>&1
|
||||
InstallInit
|
||||
InstallFiles
|
||||
"${cns_install_dir}/cns.init" start|grep -q FAILED && "${cns_install_dir}/cns.init" start|grep -q FAILED && Error "cns install 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
|
||||
|
|
@ -135,7 +174,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`[ -f /etc/init.d/cns ] && /etc/init.d/cns usage || \"$cns_install_dir/cns.init\" usage`\033[0m"
|
||||
\r`AddAutoStart`\033[0m"
|
||||
}
|
||||
|
||||
Uninstall() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue