优化安装脚本,添加DNS解析配置
This commit is contained in:
74
install.sh
74
install.sh
@@ -160,23 +160,78 @@ while true; do
|
|||||||
if [[ "$i" -eq 1 && -n "$NODE_ID" ]]; then
|
if [[ "$i" -eq 1 && -n "$NODE_ID" ]]; then
|
||||||
DEFAULT_NODE_ID="$NODE_ID"
|
DEFAULT_NODE_ID="$NODE_ID"
|
||||||
fi
|
fi
|
||||||
read -p "Enter Node ID for node #$i [${DEFAULT_NODE_ID}]: " INPUT_ID
|
if [[ -n "$DEFAULT_NODE_ID" ]]; then
|
||||||
|
read -p "Enter Node ID for node #$i [${DEFAULT_NODE_ID}] (type NO to finish): " INPUT_ID
|
||||||
|
else
|
||||||
|
read -p "Enter Node ID for node #$i (type NO to finish): " INPUT_ID
|
||||||
|
fi
|
||||||
CURRENT_NODE_ID=${INPUT_ID:-$DEFAULT_NODE_ID}
|
CURRENT_NODE_ID=${INPUT_ID:-$DEFAULT_NODE_ID}
|
||||||
|
if [[ "$CURRENT_NODE_ID" =~ ^([nN][oO])$ ]]; then
|
||||||
|
if [[ "${#NODE_IDS[@]}" -eq 0 ]]; then
|
||||||
|
echo -e "${RED}At least one Node ID is required${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
fi
|
||||||
if [[ -z "$CURRENT_NODE_ID" ]]; then
|
if [[ -z "$CURRENT_NODE_ID" ]]; then
|
||||||
echo -e "${RED}Node ID is required for node #$i${NC}"
|
echo -e "${RED}Node ID is required for node #$i${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
NODE_IDS+=("$CURRENT_NODE_ID")
|
if ! [[ "$CURRENT_NODE_ID" =~ ^[0-9]+$ ]]; then
|
||||||
|
echo -e "${RED}Node ID must be a positive integer${NC}"
|
||||||
read -p "Add another node? [y/N]: " INPUT_ADD_ANOTHER
|
exit 1
|
||||||
if [[ ! "$INPUT_ADD_ANOTHER" =~ ^([yY][eE][sS]|[yY]|1|true|TRUE)$ ]]; then
|
|
||||||
break
|
|
||||||
fi
|
fi
|
||||||
|
NODE_IDS+=("$CURRENT_NODE_ID")
|
||||||
((i++))
|
((i++))
|
||||||
done
|
done
|
||||||
|
|
||||||
NODE_COUNT=${#NODE_IDS[@]}
|
NODE_COUNT=${#NODE_IDS[@]}
|
||||||
|
|
||||||
|
DNS_MODE_DEFAULT=${DNS_MODE:-udp}
|
||||||
|
read -p "Enter DNS mode [${DNS_MODE_DEFAULT}] (udp/local): " INPUT_DNS_MODE
|
||||||
|
DNS_MODE=$(echo "${INPUT_DNS_MODE:-$DNS_MODE_DEFAULT}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
case "$DNS_MODE" in
|
||||||
|
udp)
|
||||||
|
DNS_SERVER_DEFAULT=${DNS_SERVER:-1.1.1.1}
|
||||||
|
DNS_SERVER_PORT_DEFAULT=${DNS_SERVER_PORT:-53}
|
||||||
|
read -p "Enter DNS server [${DNS_SERVER_DEFAULT}]: " INPUT_DNS_SERVER
|
||||||
|
DNS_SERVER=${INPUT_DNS_SERVER:-$DNS_SERVER_DEFAULT}
|
||||||
|
read -p "Enter DNS server port [${DNS_SERVER_PORT_DEFAULT}]: " INPUT_DNS_SERVER_PORT
|
||||||
|
DNS_SERVER_PORT=${INPUT_DNS_SERVER_PORT:-$DNS_SERVER_PORT_DEFAULT}
|
||||||
|
if [[ -z "$DNS_SERVER" ]]; then
|
||||||
|
echo -e "${RED}DNS server is required in udp mode${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! [[ "$DNS_SERVER_PORT" =~ ^[0-9]+$ ]] || [[ "$DNS_SERVER_PORT" -lt 1 ]] || [[ "$DNS_SERVER_PORT" -gt 65535 ]]; then
|
||||||
|
echo -e "${RED}DNS server port must be an integer between 1 and 65535${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
DNS_SERVER_JSON=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"tag": "dns-upstream",
|
||||||
|
"type": "udp",
|
||||||
|
"server": "$DNS_SERVER",
|
||||||
|
"server_port": $DNS_SERVER_PORT
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
local)
|
||||||
|
DNS_SERVER_JSON=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"tag": "dns-local",
|
||||||
|
"type": "local"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "${RED}Unsupported DNS mode: $DNS_MODE. Supported values: udp, local${NC}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Sync time (Critical for SS 2022)
|
# Sync time (Critical for SS 2022)
|
||||||
echo -e "${YELLOW}Syncing system time...${NC}"
|
echo -e "${YELLOW}Syncing system time...${NC}"
|
||||||
timedatectl set-ntp true || true
|
timedatectl set-ntp true || true
|
||||||
@@ -240,12 +295,7 @@ cat > "$CONFIG_BASE_FILE" <<EOF
|
|||||||
},
|
},
|
||||||
"dns": {
|
"dns": {
|
||||||
"servers": [
|
"servers": [
|
||||||
{
|
${DNS_SERVER_JSON}
|
||||||
"tag": "dns-remote",
|
|
||||||
"type": "udp",
|
|
||||||
"server": "1.1.1.1",
|
|
||||||
"server_port": 53
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"services": [
|
"services": [
|
||||||
|
|||||||
Reference in New Issue
Block a user