Refactor paths
This commit is contained in:
@ -1,11 +1,15 @@
|
||||
# Check if wg-quick@wgcf.service is active
|
||||
#!/bin/bash
|
||||
|
||||
# Source the path.sh script to load the CONFIG_FILE and CLI_PATH variables
|
||||
source /etc/hysteria/core/scripts/path.sh
|
||||
|
||||
# Check if wg-quick@wgcf.service is active
|
||||
if ! systemctl is-active --quiet wg-quick@wgcf.service; then
|
||||
echo "WARP is not active. Please install WARP before configuring."
|
||||
return
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CONFIG_FILE="/etc/hysteria/config.json"
|
||||
|
||||
# Check if the config file exists
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
# Check the current status of WARP configurations
|
||||
warp_all_status=$(jq -r 'if .acl.inline | index("warps(all)") then "WARP active" else "Direct" end' "$CONFIG_FILE")
|
||||
@ -62,13 +66,13 @@ if [ -f "$CONFIG_FILE" ]; then
|
||||
fi
|
||||
;;
|
||||
5)
|
||||
return
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option. Please try again."
|
||||
;;
|
||||
esac
|
||||
python3 /etc/hysteria/core/cli.py restart-hysteria2 > /dev/null 2>&1
|
||||
python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1
|
||||
else
|
||||
echo "${red}Error:${NC} Config file $CONFIG_FILE not found."
|
||||
fi
|
||||
echo "Error: Config file $CONFIG_FILE not found."
|
||||
fi
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Source the path.sh script to load the CONFIG_FILE variable
|
||||
source /etc/hysteria/core/scripts/path.sh
|
||||
|
||||
# Check if wg-quick@wgcf.service is active
|
||||
if systemctl is-active --quiet wg-quick@wgcf.service; then
|
||||
echo "WARP is already active. Skipping installation and configuration update."
|
||||
@ -6,13 +11,13 @@ else
|
||||
bash <(curl -fsSL git.io/warp.sh) wgx
|
||||
|
||||
# Check if the config file exists
|
||||
if [ -f "/etc/hysteria/config.json" ]; then
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
# Add the outbound configuration to the config.json file
|
||||
jq '.outbounds += [{"name": "warps", "type": "direct", "direct": {"mode": 4, "bindDevice": "wgcf"}}]' /etc/hysteria/config.json > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json /etc/hysteria/config.json
|
||||
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"
|
||||
# Restart the hysteria-server service
|
||||
python3 /etc/hysteria/core/cli.py restart-hysteria2 > /dev/null 2>&1
|
||||
python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1
|
||||
echo "WARP installed and outbound added to config.json."
|
||||
else
|
||||
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||
echo "Error: Config file $CONFIG_FILE not found."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Source the path.sh script to load the CONFIG_FILE and CLI_PATH variables
|
||||
source /etc/hysteria/core/scripts/path.sh
|
||||
|
||||
# Check if WARP is active
|
||||
if systemctl is-active --quiet wg-quick@wgcf.service; then
|
||||
echo "Uninstalling WARP..."
|
||||
bash <(curl -fsSL git.io/warp.sh) dwg
|
||||
|
||||
if [ -f "/etc/hysteria/config.json" ]; then
|
||||
# Check if the config file exists
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
default_config='["reject(geosite:ir)", "reject(geoip:ir)", "reject(geosite:category-ads-all)", "reject(geoip:private)", "reject(geosite:google@ads)"]'
|
||||
|
||||
jq --argjson default_config "$default_config" '
|
||||
@ -17,14 +24,15 @@ if systemctl is-active --quiet wg-quick@wgcf.service; then
|
||||
.
|
||||
end
|
||||
) | .acl.inline |= ($default_config + (. - $default_config | map(select(. != "direct"))))
|
||||
' /etc/hysteria/config.json > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json /etc/hysteria/config.json
|
||||
jq 'del(.outbounds[] | select(.name == "warps" and .type == "direct" and .direct.mode == 4 and .direct.bindDevice == "wgcf"))' /etc/hysteria/config.json > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json /etc/hysteria/config.json
|
||||
' "$CONFIG_FILE" > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json "$CONFIG_FILE"
|
||||
|
||||
python3 /etc/hysteria/core/cli.py restart-hysteria2 > /dev/null 2>&1
|
||||
jq 'del(.outbounds[] | select(.name == "warps" and .type == "direct" and .direct.mode == 4 and .direct.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 uninstalled and configurations reset to default."
|
||||
else
|
||||
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||
echo "Error: Config file $CONFIG_FILE not found."
|
||||
fi
|
||||
else
|
||||
echo "WARP is not active. Skipping uninstallation."
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user