mirror of
https://github.com/Dichgrem/singbox-example.git
synced 2025-07-31 17:19:31 -04:00
fix:remove
This commit is contained in:
38
singbox.sh
38
singbox.sh
@ -37,13 +37,10 @@ check_update() {
|
|||||||
update_singbox() {
|
update_singbox() {
|
||||||
printf "${CYAN}===== 升级/安装 Sing-box 二进制 =====${NC}\n"
|
printf "${CYAN}===== 升级/安装 Sing-box 二进制 =====${NC}\n"
|
||||||
if command -v apt-get &>/dev/null; then
|
if command -v apt-get &>/dev/null; then
|
||||||
printf "${BLUE}使用官方 deb 安装脚本升级...${NC}\n"
|
|
||||||
bash <(curl -fsSL https://sing-box.app/deb-install.sh)
|
bash <(curl -fsSL https://sing-box.app/deb-install.sh)
|
||||||
elif command -v dnf &>/dev/null || command -v yum &>/dev/null; then
|
elif command -v dnf &>/dev/null || command -v yum &>/dev/null; then
|
||||||
printf "${BLUE}使用官方 rpm 安装脚本升级...${NC}\n"
|
|
||||||
bash <(curl -fsSL https://sing-box.app/rpm-install.sh)
|
bash <(curl -fsSL https://sing-box.app/rpm-install.sh)
|
||||||
elif command -v pacman &>/dev/null; then
|
elif command -v pacman &>/dev/null; then
|
||||||
printf "${BLUE}使用官方 arch 安装脚本升级...${NC}\n"
|
|
||||||
bash <(curl -fsSL https://sing-box.app/arch-install.sh)
|
bash <(curl -fsSL https://sing-box.app/arch-install.sh)
|
||||||
else
|
else
|
||||||
printf "${RED}无法识别发行版,请手动升级 Sing-box 二进制${NC}\n" >&2
|
printf "${RED}无法识别发行版,请手动升级 Sing-box 二进制${NC}\n" >&2
|
||||||
@ -81,18 +78,20 @@ install_singbox() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
VERSION=$($BIN_PATH version | head -n1 | awk '{print $NF}')
|
VERSION=$($BIN_PATH version | head -n1 | awk '{print $NF}')
|
||||||
printf "${GREEN}已安装/更新 $BIN_NAME 版本:%s${NC}\n" "$VERSION"
|
printf "${GREEN}已安装/更新 sing-box 版本:%s${NC}\n" "$VERSION"
|
||||||
|
|
||||||
|
# 生成参数
|
||||||
UUID=$($BIN_PATH generate uuid)
|
UUID=$($BIN_PATH generate uuid)
|
||||||
KEY_OUTPUT=$($BIN_PATH generate reality-keypair)
|
KEY_OUTPUT=$($BIN_PATH generate reality-keypair)
|
||||||
PRIVATE_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PrivateKey/ {print \$2}')
|
PRIVATE_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PrivateKey/ {print $2}')
|
||||||
PUB_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PublicKey/ {print \$2}')
|
PUB_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PublicKey/ {print $2}')
|
||||||
SHORT_ID=$(openssl rand -hex 8)
|
SHORT_ID=$(openssl rand -hex 8)
|
||||||
FP="chrome"
|
FP="chrome"
|
||||||
SERVER_IP=$(curl -s https://ifconfig.me)
|
SERVER_IP=$(curl -s https://ifconfig.me)
|
||||||
PORT=443
|
PORT=443
|
||||||
SPX="/"
|
SPX="/"
|
||||||
|
|
||||||
|
# 写入配置和状态
|
||||||
mkdir -p "$CONFIG_DIR"
|
mkdir -p "$CONFIG_DIR"
|
||||||
cat >"$CONFIG_DIR/config.json" <<EOF
|
cat >"$CONFIG_DIR/config.json" <<EOF
|
||||||
{
|
{
|
||||||
@ -129,6 +128,7 @@ SPX="$SPX"
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
systemctl enable sing-box.service
|
systemctl enable sing-box.service
|
||||||
|
systemctl restart sing-box.service
|
||||||
printf "${GREEN}安装并启动完成。${NC}\n"
|
printf "${GREEN}安装并启动完成。${NC}\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,19 +157,21 @@ show_link() {
|
|||||||
# 卸载 Sing-box
|
# 卸载 Sing-box
|
||||||
uninstall_singbox() {
|
uninstall_singbox() {
|
||||||
printf "${CYAN}===== 卸载 Sing-box =====${NC}\n"
|
printf "${CYAN}===== 卸载 Sing-box =====${NC}\n"
|
||||||
if systemctl status sing-box.service &>/dev/null; then
|
systemctl stop sing-box.service 2>/dev/null || true
|
||||||
systemctl stop sing-box.service
|
systemctl disable sing-box.service 2>/dev/null || true
|
||||||
systemctl disable sing-box.service
|
|
||||||
rm -rf "$CONFIG_DIR"
|
rm -rf "$CONFIG_DIR"
|
||||||
printf "${GREEN}卸载完成:已移除配置。${NC}\n"
|
if command -v apt-get &>/dev/null; then
|
||||||
else
|
apt-get remove -y sing-box
|
||||||
printf "${YELLOW}服务未安装,无需卸载。${NC}\n"
|
elif command -v yum &>/dev/null; then
|
||||||
|
yum remove -y sing-box
|
||||||
|
elif command -v pacman &>/dev/null; then
|
||||||
|
pacman -Rss --noconfirm sing-box
|
||||||
fi
|
fi
|
||||||
|
printf "${GREEN}卸载完成。${NC}\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 重新安装
|
# 重新安装
|
||||||
reinstall_singbox() {
|
reinstall_singbox() {
|
||||||
printf "${CYAN}===== 重新安装 Sing-box =====${NC}\n"
|
|
||||||
uninstall_singbox
|
uninstall_singbox
|
||||||
install_singbox
|
install_singbox
|
||||||
}
|
}
|
||||||
@ -188,12 +190,10 @@ while true; do
|
|||||||
printf "${BOLD}输入数字 [1-7]: ${NC}"
|
printf "${BOLD}输入数字 [1-7]: ${NC}"
|
||||||
read -r choice
|
read -r choice
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
1) install_singbox ;;
|
1) install_singbox ;; 2) status_singbox ;; 3)
|
||||||
2) status_singbox ;;
|
show_link
|
||||||
3) show_link ;;
|
;;
|
||||||
4) uninstall_singbox ;;
|
4) uninstall_singbox ;; 5) reinstall_singbox ;; 6) update_singbox ;;
|
||||||
5) reinstall_singbox ;;
|
|
||||||
6) update_singbox ;;
|
|
||||||
7)
|
7)
|
||||||
printf "${GREEN}退出。${NC}\n"
|
printf "${GREEN}退出。${NC}\n"
|
||||||
exit 0
|
exit 0
|
||||||
|
Reference in New Issue
Block a user