Update menu.sh
This commit is contained in:
49
menu.sh
49
menu.sh
@ -2,21 +2,24 @@
|
|||||||
|
|
||||||
# Function to install and configure Hysteria2
|
# Function to install and configure Hysteria2
|
||||||
install_and_configure() {
|
install_and_configure() {
|
||||||
|
echo "Installing and configuring Hysteria2..."
|
||||||
bash <(curl https://raw.githubusercontent.com/H-Return/Hysteria2/main/install.sh)
|
bash <(curl -s https://raw.githubusercontent.com/H-Return/Hysteria2/main/install.sh)
|
||||||
|
echo -e "\n\n\n"
|
||||||
|
echo "Installation and configuration 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
|
read -p "Enter the new port number you want to use: " port
|
||||||
# Check if the config.yaml file exists
|
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
||||||
|
echo "Invalid port number. Please enter a number between 1 and 65535."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f "/etc/hysteria/config.yaml" ]; then
|
if [ -f "/etc/hysteria/config.yaml" ]; then
|
||||||
# Update the port in the config.yaml file
|
|
||||||
sed -i "s/listen: :[0-9]*/listen: :$port/" /etc/hysteria/config.yaml
|
sed -i "s/listen: :[0-9]*/listen: :$port/" /etc/hysteria/config.yaml
|
||||||
# Restart the Hysteria2 service
|
|
||||||
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.yaml not found."
|
||||||
fi
|
fi
|
||||||
@ -24,21 +27,16 @@ change_port() {
|
|||||||
|
|
||||||
# Function to show URI if Hysteria2 is installed and active
|
# Function to show URI if Hysteria2 is installed and active
|
||||||
show_uri() {
|
show_uri() {
|
||||||
# Check if the config.yaml file exists
|
|
||||||
if [ -f "/etc/hysteria/config.yaml" ]; then
|
if [ -f "/etc/hysteria/config.yaml" ]; then
|
||||||
# Retrieve values from config.yaml
|
|
||||||
port=$(grep -oP '(?<=listen: :)\d+' /etc/hysteria/config.yaml)
|
port=$(grep -oP '(?<=listen: :)\d+' /etc/hysteria/config.yaml)
|
||||||
sha256=$(grep -oP '(?<=pinSHA256: ").*(?=")' /etc/hysteria/config.yaml)
|
sha256=$(grep -oP '(?<=pinSHA256: ").*(?=")' /etc/hysteria/config.yaml)
|
||||||
obfspassword=$(grep -oP '(?<=password: ).*' /etc/hysteria/config.yaml | head -1)
|
obfspassword=$(grep -oP '(?<=password: ).*' /etc/hysteria/config.yaml | head -1)
|
||||||
authpassword=$(grep -oP '(?<=password: ).*' /etc/hysteria/config.yaml | tail -1)
|
authpassword=$(grep -oP '(?<=password: ).*' /etc/hysteria/config.yaml | tail -1)
|
||||||
|
|
||||||
if systemctl is-active --quiet hysteria-server.service; then
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
# Generate URI Scheme
|
IP=$(curl -s -4 ip.sb)
|
||||||
echo "Generating URI Scheme..."
|
|
||||||
IP=$(curl -4 ip.sb)
|
|
||||||
URI="hy2://$authpassword@$IP:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bing.com#Hysteria2"
|
URI="hy2://$authpassword@$IP:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bing.com#Hysteria2"
|
||||||
|
|
||||||
# Generate and display QR Code in the center of the terminal
|
|
||||||
cols=$(tput cols)
|
cols=$(tput cols)
|
||||||
rows=$(tput lines)
|
rows=$(tput lines)
|
||||||
qr=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
qr=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
@ -47,10 +45,8 @@ show_uri() {
|
|||||||
echo "$qr" | while IFS= read -r line; do
|
echo "$qr" | while IFS= read -r line; do
|
||||||
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
||||||
done
|
done
|
||||||
echo -e "\n"
|
echo -e "\n\n\n"
|
||||||
|
echo "URI: $URI"
|
||||||
# Output the URI scheme
|
|
||||||
echo "$URI"
|
|
||||||
else
|
else
|
||||||
echo "Error: Hysteria2 is not active."
|
echo "Error: Hysteria2 is not active."
|
||||||
fi
|
fi
|
||||||
@ -59,27 +55,24 @@ show_uri() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to Check Traffic Status
|
# Function to check traffic status
|
||||||
traffic_status() {
|
traffic_status() {
|
||||||
|
|
||||||
green='\033[0;32m'
|
green='\033[0;32m'
|
||||||
cyan='\033[0;36m'
|
cyan='\033[0;36m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
# Extract secret from config.yaml
|
|
||||||
secret=$(grep -Po '(?<=secret: ).*' /etc/hysteria/config.yaml | awk '{$1=$1};1')
|
secret=$(grep -Po '(?<=secret: ).*' /etc/hysteria/config.yaml | awk '{$1=$1};1')
|
||||||
|
|
||||||
# If secret is empty, exit with error
|
|
||||||
if [ -z "$secret" ]; then
|
if [ -z "$secret" ]; then
|
||||||
echo "Error: Secret not found in config.yaml"
|
echo "Error: Secret not found in config.yaml"
|
||||||
exit 1
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
response=$(curl -s -H "Authorization: $secret" http://127.0.0.1:25413/traffic)
|
response=$(curl -s -H "Authorization: $secret" http://127.0.0.1:25413/traffic)
|
||||||
if [ -z "$response" ] || [ "$response" = "{}" ]; then
|
if [ -z "$response" ] || [ "$response" = "{}" ]; then
|
||||||
echo -e "Upload (TX): ${green}0B${NC}"
|
echo -e "Upload (TX): ${green}0B${NC}"
|
||||||
echo -e "Download (RX): ${cyan}0B${NC}"
|
echo -e "Download (RX): ${cyan}0B${NC}"
|
||||||
exit 0
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tx_bytes=$(echo "$response" | jq -r '.user.tx // 0')
|
tx_bytes=$(echo "$response" | jq -r '.user.tx // 0')
|
||||||
@ -87,7 +80,6 @@ traffic_status() {
|
|||||||
|
|
||||||
format_bytes() {
|
format_bytes() {
|
||||||
bytes=$1
|
bytes=$1
|
||||||
|
|
||||||
if [ "$bytes" -lt 1024 ]; then
|
if [ "$bytes" -lt 1024 ]; then
|
||||||
echo "${bytes}B"
|
echo "${bytes}B"
|
||||||
elif [ "$bytes" -lt 1048576 ]; then
|
elif [ "$bytes" -lt 1048576 ]; then
|
||||||
@ -103,16 +95,18 @@ 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}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main menu
|
# Main menu
|
||||||
main_menu() {
|
main_menu() {
|
||||||
|
clear
|
||||||
echo "===== Hysteria2 Setup Menu ====="
|
echo "===== Hysteria2 Setup Menu ====="
|
||||||
echo "1. Install and Configure"
|
echo "1. Install and Configure Hysteria2"
|
||||||
echo "2. Change Port"
|
echo "2. Change Port"
|
||||||
echo "3. Show URI"
|
echo "3. Show URI"
|
||||||
echo "4. Check Traffic Status"
|
echo "4. Check Traffic Status"
|
||||||
echo "5. Exit"
|
echo "5. Exit"
|
||||||
|
echo "================================"
|
||||||
|
|
||||||
read -p "Enter your choice: " choice
|
read -p "Enter your choice: " choice
|
||||||
case $choice in
|
case $choice in
|
||||||
@ -120,9 +114,10 @@ main_menu() {
|
|||||||
2) change_port ;;
|
2) change_port ;;
|
||||||
3) show_uri ;;
|
3) show_uri ;;
|
||||||
4) traffic_status ;;
|
4) traffic_status ;;
|
||||||
5) exit ;;
|
5) exit 0 ;;
|
||||||
*) echo "Invalid option. Please try again." ;;
|
*) echo "Invalid option. Please try again." ;;
|
||||||
esac
|
esac
|
||||||
|
read -p "Press any key to return to the menu..."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Loop to display the menu repeatedly
|
# Loop to display the menu repeatedly
|
||||||
|
|||||||
Reference in New Issue
Block a user