完善和修改README
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
- `/etc/sing-box/config.d/10-base.json`
|
||||
- `/etc/sing-box/config.d/route.json`
|
||||
- `/etc/sing-box/config.d/outbound.json`
|
||||
- 旧版如果遗留 `/etc/sing-box/config.d/20-outbounds.json`,请不要与 `outbound.json` 同时保留,否则可能出现重复 outbound tag 导致启动失败
|
||||
- 安装后的服务名为:
|
||||
- `singbox.service`
|
||||
|
||||
@@ -71,17 +72,13 @@
|
||||
|
||||
### 1. 编译并安装
|
||||
|
||||
在 Linux 服务器上进入仓库目录:
|
||||
在 Linux 服务器上执行脚本:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://s3.cloudyun.top/downloads/singbox/install.sh | bash
|
||||
```
|
||||
`install.sh` 默认会从 `https://s3.cloudyun.top/downloads/singbox` 下载对应架构的预编译 `sing-box` 二进制,再继续进入面板和服务配置流程。
|
||||
|
||||
升级已安装的 sing-box:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://s3.cloudyun.top/downloads/singbox/update.sh | bash
|
||||
该脚本同时具有更新的功能
|
||||
```
|
||||
`update.sh` 会从同一发布地址下载对应架构的 `sing-box` 二进制,并自动重启已检测到的 `singbox` 或 `sing-box` 服务。
|
||||
|
||||
|
||||
70
install.sh
70
install.sh
@@ -12,6 +12,7 @@ CONFIG_MERGE_DIR="$CONFIG_DIR/config.d"
|
||||
CONFIG_BASE_FILE="$CONFIG_MERGE_DIR/10-base.json"
|
||||
CONFIG_ROUTE_FILE="$CONFIG_MERGE_DIR/route.json"
|
||||
CONFIG_OUTBOUNDS_FILE="$CONFIG_MERGE_DIR/outbound.json"
|
||||
LEGACY_CONFIG_OUTBOUNDS_FILE="$CONFIG_MERGE_DIR/20-outbounds.json"
|
||||
WORK_DIR="/var/lib/sing-box"
|
||||
BINARY_PATH="/usr/local/bin/sing-box"
|
||||
SERVICE_NAME="singbox"
|
||||
@@ -143,7 +144,7 @@ detect_v2bx() {
|
||||
}
|
||||
|
||||
detect_existing_installation() {
|
||||
if [[ -x "$BINARY_PATH" || -f "$SERVICE_FILE" || -f "$CONFIG_BASE_FILE" || -f "$CONFIG_ROUTE_FILE" || -f "$CONFIG_OUTBOUNDS_FILE" || -f "$CONFIG_DIR/config.json" ]]; then
|
||||
if [[ -x "$BINARY_PATH" || -f "$SERVICE_FILE" || -f "$CONFIG_BASE_FILE" || -f "$CONFIG_ROUTE_FILE" || -f "$CONFIG_OUTBOUNDS_FILE" || -f "$LEGACY_CONFIG_OUTBOUNDS_FILE" || -f "$CONFIG_DIR/config.json" ]]; then
|
||||
EXISTING_INSTALL=1
|
||||
fi
|
||||
|
||||
@@ -415,6 +416,70 @@ write_default_outbound_config() {
|
||||
EOF
|
||||
}
|
||||
|
||||
compact_default_outbound_config() {
|
||||
cat <<'EOF' | tr -d '[:space:]'
|
||||
{
|
||||
"outbounds": [
|
||||
{
|
||||
"type": "direct",
|
||||
"tag": "direct"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
compact_file_contents() {
|
||||
local path="$1"
|
||||
tr -d '[:space:]' < "$path"
|
||||
}
|
||||
|
||||
is_default_outbound_config() {
|
||||
local path="$1"
|
||||
if [[ ! -f "$path" ]]; then
|
||||
return 1
|
||||
fi
|
||||
[[ "$(compact_file_contents "$path")" == "$(compact_default_outbound_config)" ]]
|
||||
}
|
||||
|
||||
normalize_outbound_config_layout() {
|
||||
if [[ -f "$LEGACY_CONFIG_OUTBOUNDS_FILE" && ! -f "$CONFIG_OUTBOUNDS_FILE" ]]; then
|
||||
mv "$LEGACY_CONFIG_OUTBOUNDS_FILE" "$CONFIG_OUTBOUNDS_FILE"
|
||||
echo -e "${YELLOW}Migrated legacy outbound config to ${CONFIG_OUTBOUNDS_FILE}${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ ! -f "$LEGACY_CONFIG_OUTBOUNDS_FILE" || ! -f "$CONFIG_OUTBOUNDS_FILE" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$(compact_file_contents "$LEGACY_CONFIG_OUTBOUNDS_FILE")" == "$(compact_file_contents "$CONFIG_OUTBOUNDS_FILE")" ]]; then
|
||||
backup_path_if_exists "$LEGACY_CONFIG_OUTBOUNDS_FILE"
|
||||
rm -f "$LEGACY_CONFIG_OUTBOUNDS_FILE"
|
||||
echo -e "${YELLOW}Removed duplicate legacy outbound config: ${LEGACY_CONFIG_OUTBOUNDS_FILE}${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if is_default_outbound_config "$CONFIG_OUTBOUNDS_FILE"; then
|
||||
backup_path_if_exists "$CONFIG_OUTBOUNDS_FILE"
|
||||
rm -f "$CONFIG_OUTBOUNDS_FILE"
|
||||
mv "$LEGACY_CONFIG_OUTBOUNDS_FILE" "$CONFIG_OUTBOUNDS_FILE"
|
||||
echo -e "${YELLOW}Replaced installer default outbound config with legacy custom config from ${LEGACY_CONFIG_OUTBOUNDS_FILE}${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if is_default_outbound_config "$LEGACY_CONFIG_OUTBOUNDS_FILE"; then
|
||||
backup_path_if_exists "$LEGACY_CONFIG_OUTBOUNDS_FILE"
|
||||
rm -f "$LEGACY_CONFIG_OUTBOUNDS_FILE"
|
||||
echo -e "${YELLOW}Removed legacy default outbound config to avoid duplicate outbound tags.${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -e "${RED}Both ${CONFIG_OUTBOUNDS_FILE} and ${LEGACY_CONFIG_OUTBOUNDS_FILE} exist and contain different outbound definitions.${NC}"
|
||||
echo -e "${RED}Please merge them into a single config file before rerunning the installer to avoid duplicate outbound tags.${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
load_v2bx_defaults() {
|
||||
if [[ -z "$V2BX_CONFIG_PATH" ]] && ! find_v2bx_config; then
|
||||
return 1
|
||||
@@ -798,6 +863,7 @@ echo -e "${YELLOW}Generating configuration...${NC}"
|
||||
backup_path_if_exists "$CONFIG_BASE_FILE"
|
||||
backup_path_if_exists "$CONFIG_ROUTE_FILE"
|
||||
backup_path_if_exists "$CONFIG_OUTBOUNDS_FILE"
|
||||
backup_path_if_exists "$LEGACY_CONFIG_OUTBOUNDS_FILE"
|
||||
backup_path_if_exists "$CONFIG_DIR/config.json"
|
||||
backup_path_if_exists "$SERVICE_FILE"
|
||||
|
||||
@@ -825,6 +891,8 @@ ${SERVICE_JSON}
|
||||
}
|
||||
EOF
|
||||
|
||||
normalize_outbound_config_layout
|
||||
|
||||
if [[ -f "$CONFIG_DIR/config.json" ]]; then
|
||||
rm -f "$CONFIG_ROUTE_FILE" "$CONFIG_OUTBOUNDS_FILE"
|
||||
if ! extract_legacy_config_sections "$CONFIG_DIR/config.json"; then
|
||||
|
||||
Reference in New Issue
Block a user