From 787184bb8a36999495496c0e129a5fdb51d496de Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Sun, 27 Apr 2025 11:57:38 +0330 Subject: [PATCH] fix: prevent duplicate WARP outbound entries and improve installation flow --- core/scripts/warp/install.sh | 37 +++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/core/scripts/warp/install.sh b/core/scripts/warp/install.sh index 22cbeb0..ecd29e2 100644 --- a/core/scripts/warp/install.sh +++ b/core/scripts/warp/install.sh @@ -3,16 +3,39 @@ source /etc/hysteria/core/scripts/path.sh if systemctl is-active --quiet wg-quick@wgcf.service; then - echo "WARP is already active. Skipping installation and configuration update." + echo "WARP is already active. Checking configuration..." + + if [ -f "$CONFIG_FILE" ] && jq -e '.outbounds[] | select(.name == "warps")' "$CONFIG_FILE" > /dev/null 2>&1; then + echo "WARP outbound already exists in the configuration. No changes needed." + else + if [ -f "$CONFIG_FILE" ]; then + jq '.outbounds += [{"name": "warps", "type": "direct", "direct": {"mode": 4, "bindDevice": "wgcf"}}]' "$CONFIG_FILE" > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json "$CONFIG_FILE" + python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1 + echo "WARP outbound added to config.json." + else + echo "Error: Config file $CONFIG_FILE not found." + fi + fi else echo "Installing WARP..." bash <(curl -fsSL https://raw.githubusercontent.com/ReturnFI/Warp/main/warp.sh) wgx - if [ -f "$CONFIG_FILE" ]; then - jq '.outbounds += [{"name": "warps", "type": "direct", "direct": {"mode": 4, "bindDevice": "wgcf"}}]' "$CONFIG_FILE" > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json "$CONFIG_FILE" - python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1 - echo "WARP installed and outbound added to config.json." + if systemctl is-active --quiet wg-quick@wgcf.service; then + echo "WARP installation successful." + + if [ -f "$CONFIG_FILE" ]; then + if jq -e '.outbounds[] | select(.name == "warps")' "$CONFIG_FILE" > /dev/null 2>&1; then + echo "WARP outbound already exists in the configuration." + else + jq '.outbounds += [{"name": "warps", "type": "direct", "direct": {"mode": 4, "bindDevice": "wgcf"}}]' "$CONFIG_FILE" > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json "$CONFIG_FILE" + echo "WARP outbound added to config.json." + fi + python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1 + echo "Hysteria2 restarted with updated configuration." + else + echo "Error: Config file $CONFIG_FILE not found." + fi else - echo "Error: Config file $CONFIG_FILE not found." + echo "WARP installation failed." fi -fi +fi \ No newline at end of file