Update Use JSON
This commit is contained in:
64
menu.sh
64
menu.sh
@ -1,5 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Ensure necessary packages are installed
|
||||||
|
if ! command -v jq &> /dev/null || ! command -v qrencode &> /dev/null || ! command -v curl &> /dev/null; then
|
||||||
|
echo "Necessary packages are not installed. Please wait while they are being installed..."
|
||||||
|
apt-get update -qq && apt-get install jq qrencode curl -y >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
# Function to install and configure Hysteria2
|
# Function to install and configure Hysteria2
|
||||||
install_and_configure() {
|
install_and_configure() {
|
||||||
echo "Installing and configuring Hysteria2..."
|
echo "Installing and configuring Hysteria2..."
|
||||||
@ -7,17 +13,27 @@ install_and_configure() {
|
|||||||
echo -e "\n\n\n"
|
echo -e "\n\n\n"
|
||||||
echo "Installation and configuration complete."
|
echo "Installation and configuration complete."
|
||||||
}
|
}
|
||||||
# Function to Update Hysteria2
|
|
||||||
update_core() {
|
|
||||||
echo "Starting the update process for Hysteria2..."
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
|
# Function to update Hysteria2
|
||||||
|
update_core() {
|
||||||
|
echo "Starting the update process for Hysteria2..."
|
||||||
|
echo "Backing up the current configuration..."
|
||||||
|
cp /etc/hysteria/config.json /etc/hysteria/config_backup.json
|
||||||
|
sleep 1
|
||||||
echo "Downloading and installing the latest version of Hysteria2..."
|
echo "Downloading and installing the latest version of Hysteria2..."
|
||||||
bash <(curl -fsSL https://get.hy2.sh/) >/dev/null 2>&1
|
bash <(curl -fsSL https://get.hy2.sh/) >/dev/null 2>&1
|
||||||
|
echo "Restoring configuration from backup..."
|
||||||
|
mv /etc/hysteria/config_backup.json /etc/hysteria/config.json
|
||||||
|
echo "Modifying systemd service to use config.json..."
|
||||||
|
sed -i 's|/etc/hysteria/config.yaml|/etc/hysteria/config.json|' /etc/systemd/system/hysteria-server.service
|
||||||
|
systemctl daemon-reload >/dev/null 2>&1
|
||||||
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
sleep 1
|
sleep 1
|
||||||
echo "Hysteria2 has been successfully updated."
|
echo "Hysteria2 has been successfully updated."
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Function to install TCP Brutal
|
# Function to install TCP Brutal
|
||||||
install_tcp_brutal() {
|
install_tcp_brutal() {
|
||||||
echo "Installing TCP Brutal..."
|
echo "Installing TCP Brutal..."
|
||||||
@ -26,30 +42,34 @@ install_tcp_brutal() {
|
|||||||
clear
|
clear
|
||||||
echo "TCP Brutal installation complete."
|
echo "TCP Brutal installation complete."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to change port
|
# Function to change port
|
||||||
change_port() {
|
change_port() {
|
||||||
read -p "Enter the new port number you want to use: " port
|
while true; do
|
||||||
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
read -p "Enter the new port number you want to use: " port
|
||||||
echo "Invalid port number. Please enter a number between 1 and 65535."
|
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
||||||
return
|
echo "Invalid port number. Please enter a number between 1 and 65535."
|
||||||
fi
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
if [ -f "/etc/hysteria/config.yaml" ]; then
|
if [ -f "/etc/hysteria/config.json" ]; then
|
||||||
sed -i "s/listen: :[0-9]*/listen: :$port/" /etc/hysteria/config.yaml
|
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
|
||||||
systemctl restart hysteria-server.service >/dev/null 2>&1
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
echo "Port changed successfully to $port."
|
echo "Port changed successfully to $port."
|
||||||
else
|
else
|
||||||
echo "Error: Config file /etc/hysteria/config.yaml not found."
|
echo "Error: Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to show URI if Hysteria2 is installed and active
|
# Function to show URI if Hysteria2 is installed and active
|
||||||
show_uri() {
|
show_uri() {
|
||||||
if [ -f "/etc/hysteria/config.yaml" ]; then
|
if [ -f "/etc/hysteria/config.json" ]; then
|
||||||
port=$(grep -oP '(?<=listen: :)\d+' /etc/hysteria/config.yaml)
|
port=$(jq -r '.listen' /etc/hysteria/config.json | cut -d':' -f2)
|
||||||
sha256=$(grep -oP '(?<=pinSHA256: ").*(?=")' /etc/hysteria/config.yaml)
|
sha256=$(jq -r '.tls.pinSHA256' /etc/hysteria/config.json)
|
||||||
obfspassword=$(grep -oP '(?<=password: ).*' /etc/hysteria/config.yaml | head -1)
|
obfspassword=$(jq -r '.obfs.salamander.password' /etc/hysteria/config.json)
|
||||||
authpassword=$(grep -oP '(?<=password: ).*' /etc/hysteria/config.yaml | tail -1)
|
authpassword=$(jq -r '.auth.password' /etc/hysteria/config.json)
|
||||||
|
|
||||||
if systemctl is-active --quiet hysteria-server.service; then
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
IP=$(curl -s -4 ip.sb)
|
IP=$(curl -s -4 ip.sb)
|
||||||
@ -62,7 +82,6 @@ show_uri() {
|
|||||||
qr1=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
qr1=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
qr2=$(echo -n "$URI6" | qrencode -t UTF8 -s 3 -m 2)
|
qr2=$(echo -n "$URI6" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
|
|
||||||
|
|
||||||
echo -e "\nIPv4:\n"
|
echo -e "\nIPv4:\n"
|
||||||
echo "$qr1" | while IFS= read -r line; do
|
echo "$qr1" | while IFS= read -r line; do
|
||||||
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
||||||
@ -81,7 +100,7 @@ show_uri() {
|
|||||||
echo "Error: Hysteria2 is not active."
|
echo "Error: Hysteria2 is not active."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Error: Config file /etc/hysteria/config.yaml not found."
|
echo "Error: Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,10 +110,10 @@ traffic_status() {
|
|||||||
cyan='\033[0;36m'
|
cyan='\033[0;36m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
secret=$(grep -Po '(?<=secret: ).*' /etc/hysteria/config.yaml | awk '{$1=$1};1')
|
secret=$(jq -r '.trafficStats.secret' /etc/hysteria/config.json)
|
||||||
|
|
||||||
if [ -z "$secret" ]; then
|
if [ -z "$secret" ]; then
|
||||||
echo "Error: Secret not found in config.yaml"
|
echo "Error: Secret not found in config.json"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -126,6 +145,8 @@ traffic_status() {
|
|||||||
echo -e "Upload (TX): ${green}$(format_bytes "$tx_bytes")${NC}"
|
echo -e "Upload (TX): ${green}$(format_bytes "$tx_bytes")${NC}"
|
||||||
echo -e "Download (RX): ${cyan}$(format_bytes "$rx_bytes")${NC}"
|
echo -e "Download (RX): ${cyan}$(format_bytes "$rx_bytes")${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to uninstall Hysteria2
|
||||||
uninstall_hysteria() {
|
uninstall_hysteria() {
|
||||||
echo "Uninstalling Hysteria2..."
|
echo "Uninstalling Hysteria2..."
|
||||||
sleep 1
|
sleep 1
|
||||||
@ -148,6 +169,7 @@ uninstall_hysteria() {
|
|||||||
echo "Hysteria2 uninstalled!"
|
echo "Hysteria2 uninstalled!"
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main menu
|
# Main menu
|
||||||
main_menu() {
|
main_menu() {
|
||||||
clear
|
clear
|
||||||
|
|||||||
Reference in New Issue
Block a user