Update Menu
This commit is contained in:
252
menu.sh
252
menu.sh
@ -8,10 +8,32 @@ if ! command -v jq &> /dev/null || ! command -v qrencode &> /dev/null || ! comma
|
|||||||
apt-get update && apt-get install jq qrencode curl pwgen uuid-runtime -y
|
apt-get update && apt-get install jq qrencode curl pwgen uuid-runtime -y
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Function to get system information
|
||||||
|
get_system_info() {
|
||||||
|
OS=$(lsb_release -d | awk -F'\t' '{print $2}')
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
# Fetching detailed IP information in JSON format
|
||||||
|
IP_API_DATA=$(curl -s https://ipapi.co/json/ -4)
|
||||||
|
ISP=$(echo "$IP_API_DATA" | jq -r '.org')
|
||||||
|
IP=$(echo "$IP_API_DATA" | jq -r '.ip')
|
||||||
|
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4 "%"}')
|
||||||
|
RAM=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to define colors
|
||||||
|
define_colors() {
|
||||||
|
green='\033[1;34m'
|
||||||
|
cyan='\033[0;36m'
|
||||||
|
red='\033[0;31m'
|
||||||
|
yellow='\033[0;33m'
|
||||||
|
LPurple='\033[1;35m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
}
|
||||||
|
|
||||||
# Function to install and configure Hysteria2
|
# Function to install and configure Hysteria2
|
||||||
install_and_configure() {
|
install_and_configure() {
|
||||||
if systemctl is-active --quiet hysteria-server.service; then
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
echo -e "\033[0;31mError:\033[0mHysteria2 is already installed and running."
|
echo -e "${red}Error:${NC}Hysteria2 is already installed and running."
|
||||||
echo
|
echo
|
||||||
echo "If you need to update the core, please use the 'Update Core' option."
|
echo "If you need to update the core, please use the 'Update Core' option."
|
||||||
else
|
else
|
||||||
@ -29,14 +51,14 @@ update_core() {
|
|||||||
echo "Backing up the current configuration..."
|
echo "Backing up the current configuration..."
|
||||||
cp /etc/hysteria/config.json /etc/hysteria/config_backup.json
|
cp /etc/hysteria/config.json /etc/hysteria/config_backup.json
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to back up configuration. Aborting update."
|
echo "${red}Error:${NC} Failed to back up configuration. Aborting update."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to download or install the latest version. Restoring backup configuration."
|
echo "${red}Error:${NC} Failed to download or install the latest version. Restoring backup configuration."
|
||||||
mv /etc/hysteria/config_backup.json /etc/hysteria/config.json
|
mv /etc/hysteria/config_backup.json /etc/hysteria/config.json
|
||||||
systemctl restart hysteria-server.service >/dev/null 2>&1
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
return 1
|
return 1
|
||||||
@ -45,14 +67,14 @@ update_core() {
|
|||||||
echo "Restoring configuration from backup..."
|
echo "Restoring configuration from backup..."
|
||||||
mv /etc/hysteria/config_backup.json /etc/hysteria/config.json
|
mv /etc/hysteria/config_backup.json /etc/hysteria/config.json
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to restore configuration from backup."
|
echo "${red}Error:${NC} Failed to restore configuration from backup."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Modifying systemd service to use 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
|
sed -i 's|/etc/hysteria/config.yaml|/etc/hysteria/config.json|' /etc/systemd/system/hysteria-server.service
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to modify systemd service."
|
echo "${red}Error:${NC} Failed to modify systemd service."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -60,7 +82,7 @@ update_core() {
|
|||||||
systemctl daemon-reload >/dev/null 2>&1
|
systemctl daemon-reload >/dev/null 2>&1
|
||||||
systemctl restart hysteria-server.service >/dev/null 2>&1
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to restart Hysteria2 service."
|
echo "${red}Error:${NC} Failed to restart Hysteria2 service."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -85,7 +107,7 @@ change_port() {
|
|||||||
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.json not found."
|
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,10 +161,10 @@ show_uri() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Error: Hysteria2 is not active."
|
echo "${red}Error:${NC} Hysteria2 is not active."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Error: Config file /etc/hysteria/config.json not found."
|
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +177,7 @@ traffic_status() {
|
|||||||
secret=$(jq -r '.trafficStats.secret' /etc/hysteria/config.json)
|
secret=$(jq -r '.trafficStats.secret' /etc/hysteria/config.json)
|
||||||
|
|
||||||
if [ -z "$secret" ]; then
|
if [ -z "$secret" ]; then
|
||||||
echo "Error: Secret not found in config.json"
|
echo "${red}Error:${NC} Secret not found in config.json"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -267,7 +289,7 @@ install_warp() {
|
|||||||
systemctl restart hysteria-server.service >/dev/null 2>&1
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
echo "WARP installed and outbound added to config.json."
|
echo "WARP installed and outbound added to config.json."
|
||||||
else
|
else
|
||||||
echo "Error: Config file /etc/hysteria/config.json not found."
|
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -325,7 +347,7 @@ configure_warp() {
|
|||||||
esac
|
esac
|
||||||
systemctl restart hysteria-server.service >/dev/null 2>&1
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
else
|
else
|
||||||
echo "Error: Config file /etc/hysteria/config.json not found."
|
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
# Function to add a new user to the configuration
|
# Function to add a new user to the configuration
|
||||||
@ -338,7 +360,7 @@ add_user() {
|
|||||||
if [[ "$username" =~ ^[a-z0-9]+$ ]]; then
|
if [[ "$username" =~ ^[a-z0-9]+$ ]]; then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo -e "\033[0;31mError:\033[0m Username can only contain lowercase letters and numbers."
|
echo -e "${red}Error:${NC} Username can only contain lowercase letters and numbers."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -348,7 +370,7 @@ add_user() {
|
|||||||
systemctl restart hysteria-server.service >/dev/null 2>&1
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
echo -e "\033[0;32mUser $username added successfully.\033[0m"
|
echo -e "\033[0;32mUser $username added successfully.\033[0m"
|
||||||
else
|
else
|
||||||
echo -e "\033[0;31mError:\033[0m Config file /etc/hysteria/config.json not found."
|
echo -e "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
# Function to remove a user from the configuration
|
# Function to remove a user from the configuration
|
||||||
@ -375,12 +397,12 @@ remove_user() {
|
|||||||
read -p "Enter the number of the user to remove: " selected_number
|
read -p "Enter the number of the user to remove: " selected_number
|
||||||
|
|
||||||
if ! [[ "$selected_number" =~ ^[0-9]+$ ]]; then
|
if ! [[ "$selected_number" =~ ^[0-9]+$ ]]; then
|
||||||
echo "Error: Invalid input. Please enter a number."
|
echo "${red}Error:${NC} Invalid input. Please enter a number."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$selected_number" -lt 1 ] || [ "$selected_number" -gt "$i" ]; then
|
if [ "$selected_number" -lt 1 ] || [ "$selected_number" -gt "$i" ]; then
|
||||||
echo "Error: Invalid selection. Please enter a number within the range."
|
echo "${red}Error:${NC} Invalid selection. Please enter a number within the range."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -391,86 +413,140 @@ remove_user() {
|
|||||||
systemctl restart hysteria-server.service >/dev/null 2>&1
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
echo "User $selected_user removed successfully."
|
echo "User $selected_user removed successfully."
|
||||||
else
|
else
|
||||||
echo "Error: Config file /etc/hysteria/config.json not found."
|
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
# Hysteria2 menu
|
# Function to display the main menu
|
||||||
hysteria2_menu() {
|
display_main_menu() {
|
||||||
clear
|
clear
|
||||||
echo "===== Hysteria2 Menu ====="
|
tput setaf 7 ; tput setab 4 ; tput bold ; printf '%40s%s%-12s\n' "◇───────────ㅤ🚀ㅤWelcome To Hysteria2 Managementㅤ🚀ㅤ───────────◇" ; tput sgr0
|
||||||
echo "1. Install and Configure"
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
echo "2. Add User"
|
|
||||||
echo "3. Show URI"
|
|
||||||
echo "4. Check Traffic Status"
|
|
||||||
echo "5. Remove User"
|
|
||||||
echo "6. Change Port"
|
|
||||||
echo "7. Update Core"
|
|
||||||
echo "8. Uninstall Hysteria2"
|
|
||||||
echo "9. Back to Main Menu"
|
|
||||||
echo "=========================="
|
|
||||||
|
|
||||||
read -p "Enter your choice: " choice
|
echo -e "${green}• OS: ${NC}$OS ${green}• ARCH: ${NC}$ARCH"
|
||||||
case $choice in
|
echo -e "${green}• ISP: ${NC}$ISP ${green}• CPU: ${NC}$CPU"
|
||||||
1) install_and_configure ;;
|
echo -e "${green}• IP: ${NC}$IP ${green}• RAM: ${NC}$RAM"
|
||||||
2) add_user ;;
|
|
||||||
3) show_uri ;;
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
4) traffic_status ;;
|
|
||||||
5) remove_user ;;
|
echo -e "${yellow} ☼ Main Menu ☼ ${NC}"
|
||||||
6) change_port ;;
|
|
||||||
7) update_core ;;
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
8) uninstall_hysteria ;;
|
echo -e "${green}[1] ${NC}↝ Hysteria2 Menu"
|
||||||
9) return ;;
|
echo -e "${cyan}[2] ${NC}↝ Advance Menu"
|
||||||
*) echo "Invalid option. Please try again." ;;
|
echo -e "${red}[0] ${NC}↝ Exit"
|
||||||
esac
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
echo
|
echo -ne "${yellow}➜ Enter your option: ${NC}"
|
||||||
read -p "Press any key to return to the Hysteria2 menu..."
|
|
||||||
hysteria2_menu
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Advance menu
|
# Function to handle main menu options
|
||||||
advance_menu() {
|
|
||||||
clear
|
|
||||||
echo "===== Advance Menu ====="
|
|
||||||
echo "1. Install TCP Brutal"
|
|
||||||
echo "2. Install WARP"
|
|
||||||
echo "3. Configure WARP"
|
|
||||||
echo "4. Back to Main Menu"
|
|
||||||
echo "========================="
|
|
||||||
|
|
||||||
read -p "Enter your choice: " choice
|
|
||||||
case $choice in
|
|
||||||
1) install_tcp_brutal ;;
|
|
||||||
2) install_warp ;;
|
|
||||||
3) configure_warp ;;
|
|
||||||
4) return ;;
|
|
||||||
*) echo "Invalid option. Please try again." ;;
|
|
||||||
esac
|
|
||||||
echo
|
|
||||||
read -p "Press any key to return to the Advance menu..."
|
|
||||||
advance_menu
|
|
||||||
}
|
|
||||||
|
|
||||||
# Main menu
|
|
||||||
main_menu() {
|
main_menu() {
|
||||||
clear
|
clear
|
||||||
echo "===== Main Menu ====="
|
local choice
|
||||||
echo "1. Hysteria2"
|
while true; do
|
||||||
echo "2. Advance"
|
define_colors
|
||||||
echo "3. Exit"
|
get_system_info
|
||||||
echo "====================="
|
display_main_menu
|
||||||
|
read -r choice
|
||||||
read -p "Enter your choice: " choice
|
case $choice in
|
||||||
case $choice in
|
1) hysteria2_menu ;;
|
||||||
1) hysteria2_menu ;;
|
2) advance_menu ;;
|
||||||
2) advance_menu ;;
|
0) exit 0 ;;
|
||||||
3) exit 0 ;;
|
*) echo "Invalid option. Please try again." ;;
|
||||||
*) echo "Invalid option. Please try again." ;;
|
esac
|
||||||
esac
|
echo
|
||||||
echo
|
read -rp "Press Enter to continue..."
|
||||||
read -p "Press any key to return to the main menu..."
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Loop to display the menu repeatedly
|
# Function to display the Hysteria2 menu
|
||||||
while true; do
|
display_hysteria2_menu() {
|
||||||
|
clear
|
||||||
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
|
|
||||||
|
echo -e "${yellow} ☼ Hysteria2 Menu ☼ ${NC}"
|
||||||
|
|
||||||
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
|
|
||||||
|
echo -e "${green}[1] ${NC}↝ Install and Configure Hysteria2"
|
||||||
|
echo -e "${cyan}[2] ${NC}↝ Add User"
|
||||||
|
echo -e "${cyan}[3] ${NC}↝ Show URI"
|
||||||
|
echo -e "${cyan}[4] ${NC}↝ Check Traffic Status"
|
||||||
|
echo -e "${cyan}[5] ${NC}↝ Remove User"
|
||||||
|
echo -e "${cyan}[6] ${NC}↝ Change Port"
|
||||||
|
echo -e "${cyan}[7] ${NC}↝ Update Core"
|
||||||
|
echo -e "${cyan}[8] ${NC}↝ Uninstall Hysteria2"
|
||||||
|
|
||||||
|
echo -e "${red}[0] ${NC}↝ Back to Main Menu"
|
||||||
|
|
||||||
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
|
|
||||||
|
echo -ne "${yellow}➜ Enter your option: ${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to handle Hysteria2 menu options
|
||||||
|
hysteria2_menu() {
|
||||||
|
clear
|
||||||
|
local choice
|
||||||
|
while true; do
|
||||||
|
define_colors
|
||||||
|
get_system_info
|
||||||
|
display_hysteria2_menu
|
||||||
|
read -r choice
|
||||||
|
case $choice in
|
||||||
|
1) install_and_configure ;;
|
||||||
|
2) add_user ;;
|
||||||
|
3) show_uri ;;
|
||||||
|
4) traffic_status ;;
|
||||||
|
5) remove_user ;;
|
||||||
|
6) change_port ;;
|
||||||
|
7) update_core ;;
|
||||||
|
8) uninstall_hysteria ;;
|
||||||
|
0) return ;;
|
||||||
|
*) echo "Invalid option. Please try again." ;;
|
||||||
|
esac
|
||||||
|
echo
|
||||||
|
read -rp "Press Enter to continue..."
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to handle Advance menu options
|
||||||
|
advance_menu() {
|
||||||
|
clear
|
||||||
|
local choice
|
||||||
|
while true; do
|
||||||
|
define_colors
|
||||||
|
display_advance_menu
|
||||||
|
read -r choice
|
||||||
|
case $choice in
|
||||||
|
1) install_tcp_brutal ;;
|
||||||
|
2) install_warp ;;
|
||||||
|
3) configure_warp ;;
|
||||||
|
4) return ;;
|
||||||
|
*) echo "Invalid option. Please try again." ;;
|
||||||
|
esac
|
||||||
|
echo
|
||||||
|
read -rp "Press Enter to continue..."
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to get Advance menu
|
||||||
|
display_advance_menu() {
|
||||||
|
clear
|
||||||
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
|
echo -e "${yellow} ☼ Advance Menu ☼ ${NC}"
|
||||||
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
|
echo -e "${green}[1] ${NC}↝ Install TCP Brutal"
|
||||||
|
echo -e "${cyan}[2] ${NC}↝ Install WARP"
|
||||||
|
echo -e "${cyan}[3] ${NC}↝ Configure WARP"
|
||||||
|
echo -e "${red}[4] ${NC}↝ Back to Main Menu"
|
||||||
|
echo -e "${LPurple}◇──────────────────────────────────────────────────────────────────────◇${NC}"
|
||||||
|
echo -ne "${yellow}➜ Enter your option: ${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main function to run the script
|
||||||
|
main() {
|
||||||
main_menu
|
main_menu
|
||||||
done
|
}
|
||||||
|
|
||||||
|
# Run the main function
|
||||||
|
main
|
||||||
|
|||||||
Reference in New Issue
Block a user