mirror of
https://github.com/Dichgrem/singbox-example.git
synced 2025-12-18 12:31:59 -05:00
Compare commits
3 Commits
1aefb1daf8
...
0b5f0408ce
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b5f0408ce | ||
|
|
d75214ca9a | ||
|
|
2ca559f210 |
@@ -9,29 +9,20 @@
|
|||||||
"listen": "::",
|
"listen": "::",
|
||||||
"listen_port": 443,
|
"listen_port": 443,
|
||||||
"users":
|
"users":
|
||||||
[
|
[{ "name": "$NAME", "uuid": "$UUID", "flow": "xtls-rprx-vision" }],
|
||||||
{
|
|
||||||
"name": "AK-JP-100G",
|
|
||||||
"uuid": "singbox生成",
|
|
||||||
"flow": "xtls-rprx-vision",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"tls":
|
"tls":
|
||||||
{
|
{
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"server_name": "s0.awsstatic.com",
|
"server_name": "$SNI",
|
||||||
"reality":
|
"reality":
|
||||||
{
|
{
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"handshake":
|
"handshake": { "server": "$SNI", "server_port": 443 },
|
||||||
{ "server": "s0.awsstatic.com", "server_port": 443 },
|
"private_key": "$PRIVATE_KEY",
|
||||||
"private_key": "singbox生成",
|
"short_id": "$SHORT_ID",
|
||||||
"short_id": ["singbox生成"],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"outbounds": [{ "type": "direct" }, { "type": "dns", "tag": "dns-out" }],
|
"outbounds": [{ "type": "direct" }],
|
||||||
"route": { "rules": [{ "protocol": "dns", "outbound": "dns-out" }] },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# install_singbox.sh
|
# install_singbox.sh
|
||||||
|
# 版本号
|
||||||
|
SCRIPT_VERSION="1.12.1"
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# 颜色定义
|
# 颜色定义
|
||||||
@@ -93,23 +95,49 @@ install_singbox() {
|
|||||||
mkdir -p "$CONFIG_DIR"
|
mkdir -p "$CONFIG_DIR"
|
||||||
cat >"$CONFIG_DIR/config.json" <<EOF
|
cat >"$CONFIG_DIR/config.json" <<EOF
|
||||||
{
|
{
|
||||||
"log": {"level": "info"},
|
"log": {
|
||||||
"dns": {"servers": [{"address": "tls://8.8.8.8"}]},
|
"level": "info"
|
||||||
"inbounds": [{
|
},
|
||||||
|
"dns": {
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"address": "tls://8.8.8.8"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"inbounds": [
|
||||||
|
{
|
||||||
"type": "vless",
|
"type": "vless",
|
||||||
"tag": "VLESSReality",
|
"tag": "VLESSReality",
|
||||||
"listen": "::",
|
"listen": "::",
|
||||||
"listen_port": 443,
|
"listen_port": 443,
|
||||||
"users": [{"name":"$NAME","uuid":"$UUID","flow":"xtls-rprx-vision"}],
|
"users": [
|
||||||
"tls": {"enabled":true,"server_name":"$SNI","reality":{
|
{
|
||||||
|
"name": "$NAME",
|
||||||
|
"uuid": "$UUID",
|
||||||
|
"flow": "xtls-rprx-vision"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tls": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"handshake": {"server":"$SNI","server_port":443},
|
"server_name": "$SNI",
|
||||||
|
"reality": {
|
||||||
|
"enabled": true,
|
||||||
|
"handshake": {
|
||||||
|
"server": "$SNI",
|
||||||
|
"server_port": 443
|
||||||
|
},
|
||||||
"private_key": "$PRIVATE_KEY",
|
"private_key": "$PRIVATE_KEY",
|
||||||
"short_id":["$SHORT_ID"]
|
"short_id": "$SHORT_ID"
|
||||||
}}
|
}
|
||||||
}],
|
}
|
||||||
"outbounds": [{"type":"direct"},{"type":"dns","tag":"dns-out"}],
|
}
|
||||||
"route": {"rules": [{"protocol":"dns","outbound":"dns-out"}]}
|
],
|
||||||
|
"outbounds": [
|
||||||
|
{
|
||||||
|
"type": "direct"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -170,16 +198,57 @@ status_singbox() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 显示 VLESS Reality 链接
|
# 显示 VLESS Reality 链接 + 二维码
|
||||||
show_link() {
|
show_link() {
|
||||||
printf "${CYAN}===== 您的 VLESS Reality 链接 =====${NC}\n"
|
printf "${CYAN}===== 您的 VLESS Reality 链接 =====${NC}\n"
|
||||||
[[ -f "$STATE_FILE" ]] || {
|
|
||||||
printf "${RED}未找到状态文件,请先安装。${NC}\n"
|
# 如果状态文件不存在,尝试从 config.json 读取并生成
|
||||||
|
if [[ ! -f "$STATE_FILE" ]]; then
|
||||||
|
if [[ -f "$CONFIG_DIR/config.json" ]]; then
|
||||||
|
NAME=$(grep -oP '"name"\s*:\s*"\K[^"]+' "$CONFIG_DIR/config.json")
|
||||||
|
UUID=$(grep -oP '"uuid"\s*:\s*"\K[^"]+' "$CONFIG_DIR/config.json")
|
||||||
|
SNI=$(grep -oP '"server_name"\s*:\s*"\K[^"]+' "$CONFIG_DIR/config.json")
|
||||||
|
PUB_KEY=$(grep -oP '"public_key"\s*:\s*"\K[^"]+' "$CONFIG_DIR/config.json")
|
||||||
|
SHORT_ID=$(grep -oP '"short_id"\s*:\s*"\K[^"]+' "$CONFIG_DIR/config.json")
|
||||||
|
FP="chrome"
|
||||||
|
SERVER_IP=$(curl -s https://ifconfig.me)
|
||||||
|
PORT=443
|
||||||
|
SPX="/"
|
||||||
|
|
||||||
|
# 保存新的 state.env
|
||||||
|
mkdir -p "$CONFIG_DIR"
|
||||||
|
cat >"$STATE_FILE" <<EOF
|
||||||
|
NAME="$NAME"
|
||||||
|
SNI="$SNI"
|
||||||
|
UUID="$UUID"
|
||||||
|
PUB_KEY="$PUB_KEY"
|
||||||
|
SHORT_ID="$SHORT_ID"
|
||||||
|
FP="$FP"
|
||||||
|
SERVER_IP="$SERVER_IP"
|
||||||
|
PORT="$PORT"
|
||||||
|
SPX="$SPX"
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
printf "${RED}未找到配置文件,请先安装。${NC}\n"
|
||||||
return
|
return
|
||||||
}
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 读取 state.env
|
||||||
source "$STATE_FILE"
|
source "$STATE_FILE"
|
||||||
LINK="vless://${UUID}@${SERVER_IP}:${PORT}?security=reality&sni=${SNI}&fp=${FP}&pbk=${PUB_KEY}&sid=${SHORT_ID}&spx=${SPX}&type=tcp&flow=xtls-rprx-vision&encryption=none#${NAME}"
|
LINK="vless://${UUID}@${SERVER_IP}:${PORT}?security=reality&sni=${SNI}&fp=${FP}&pbk=${PUB_KEY}&sid=${SHORT_ID}&spx=${SPX}&type=tcp&flow=xtls-rprx-vision&encryption=none#${NAME}"
|
||||||
|
|
||||||
printf "${GREEN}%s${NC}\n\n" "$LINK"
|
printf "${GREEN}%s${NC}\n\n" "$LINK"
|
||||||
|
|
||||||
|
# 生成二维码
|
||||||
|
if command -v qrencode &>/dev/null; then
|
||||||
|
printf "${CYAN}===== 二维码 =====${NC}\n"
|
||||||
|
qrencode -t ANSIUTF8 "$LINK"
|
||||||
|
printf "\n"
|
||||||
|
else
|
||||||
|
printf "${YELLOW}未安装 qrencode,无法生成二维码。\n"
|
||||||
|
printf "安装方法:apt install qrencode 或 yum install qrencode${NC}\n"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 卸载 Sing-box
|
# 卸载 Sing-box
|
||||||
@@ -204,8 +273,34 @@ reinstall_singbox() {
|
|||||||
install_singbox
|
install_singbox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 更新脚本自身
|
||||||
|
update_self() {
|
||||||
|
local script_path="${BASH_SOURCE[0]}"
|
||||||
|
local tmp_file="/tmp/install_singbox.sh.tmp"
|
||||||
|
|
||||||
|
printf "${CYAN}===== 更新脚本自身 =====${NC}\n"
|
||||||
|
if command -v curl &>/dev/null; then
|
||||||
|
local url="https://raw.githubusercontent.com/Dichgrem/singbox-example/refs/heads/main/script/singbox.sh"
|
||||||
|
echo "从 $url 下载最新脚本..."
|
||||||
|
if curl -fsSL "$url" -o "$tmp_file"; then
|
||||||
|
echo "下载成功,准备替换本地脚本..."
|
||||||
|
chmod +x "$tmp_file"
|
||||||
|
mv "$tmp_file" "$script_path"
|
||||||
|
echo "脚本更新完成。"
|
||||||
|
echo "重启脚本..."
|
||||||
|
exec bash "$script_path"
|
||||||
|
else
|
||||||
|
echo "${RED}下载失败,无法更新脚本。${NC}"
|
||||||
|
rm -f "$tmp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "${RED}未安装 curl,无法自动更新脚本。${NC}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# 菜单主循环
|
# 菜单主循环
|
||||||
check_update
|
check_update
|
||||||
|
printf "${BLUE}当前脚本版本:${SCRIPT_VERSION}${NC}\n"
|
||||||
while true; do
|
while true; do
|
||||||
printf "${BOLD}${BLUE}请选择操作:${NC}\n"
|
printf "${BOLD}${BLUE}请选择操作:${NC}\n"
|
||||||
printf " ${YELLOW}1)${NC} 安装 Sing-box 并生成配置\n"
|
printf " ${YELLOW}1)${NC} 安装 Sing-box 并生成配置\n"
|
||||||
@@ -215,7 +310,8 @@ while true; do
|
|||||||
printf " ${YELLOW}5)${NC} 重新安装 Sing-box\n"
|
printf " ${YELLOW}5)${NC} 重新安装 Sing-box\n"
|
||||||
printf " ${YELLOW}6)${NC} 升级 Sing-box 二进制\n"
|
printf " ${YELLOW}6)${NC} 升级 Sing-box 二进制\n"
|
||||||
printf " ${YELLOW}7)${NC} 更换 SNI 域名\n"
|
printf " ${YELLOW}7)${NC} 更换 SNI 域名\n"
|
||||||
printf " ${YELLOW}8)${NC} 退出\n"
|
printf " ${YELLOW}8)${NC} 更新脚本自身\n"
|
||||||
|
printf " ${YELLOW}9)${NC} 退出\n"
|
||||||
printf "${BOLD}输入数字 [1-8]: ${NC}"
|
printf "${BOLD}输入数字 [1-8]: ${NC}"
|
||||||
read -r choice
|
read -r choice
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
@@ -226,7 +322,8 @@ while true; do
|
|||||||
5) reinstall_singbox ;;
|
5) reinstall_singbox ;;
|
||||||
6) update_singbox ;;
|
6) update_singbox ;;
|
||||||
7) change_sni ;;
|
7) change_sni ;;
|
||||||
8)
|
8) update_self ;;
|
||||||
|
9)
|
||||||
printf "${GREEN}退出。${NC}\n"
|
printf "${GREEN}退出。${NC}\n"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user