Fix change_port.sh
This commit is contained in:
@ -1,16 +1,22 @@
|
|||||||
while true; do
|
# Function to update port number in configuration
|
||||||
read -p "Enter the new port number you want to use: " port
|
update_port() {
|
||||||
|
local port=$1
|
||||||
|
|
||||||
|
# Validate the port number
|
||||||
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
||||||
echo "Invalid port number. Please enter a number between 1 and 65535."
|
echo "Invalid port number. Please enter a number between 1 and 65535."
|
||||||
else
|
return 1
|
||||||
break
|
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
if [ -f "/etc/hysteria/config.json" ]; then
|
# Check if the config file exists and update the port number
|
||||||
jq --arg port "$port" '.listen = ":" + $port' /etc/hysteria/config.json > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json /etc/hysteria/config.json
|
if [ -f "/etc/hysteria/config.json" ]; then
|
||||||
python3 /etc/hysteria/core/cli.py restart-hysteria2 > /dev/null 2>&1
|
jq --arg port "$port" '.listen = ":" + $port' /etc/hysteria/config.json > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json /etc/hysteria/config.json
|
||||||
echo "Port changed successfully to $port."
|
python3 /etc/hysteria/core/cli.py restart-hysteria2 > /dev/null 2>&1
|
||||||
else
|
echo "Port changed successfully to $port."
|
||||||
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
else
|
||||||
fi
|
echo "Error: Config file /etc/hysteria/config.json not found."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
update_port "$1"
|
||||||
Reference in New Issue
Block a user