Refactor menu.sh

This commit is contained in:
Sarina
2024-07-21 19:16:45 +03:30
parent ad6911ed66
commit 9a2420c82a
2 changed files with 60 additions and 38 deletions

View File

@ -8,3 +8,15 @@ define_colors() {
LPurple='\033[1;35m' LPurple='\033[1;35m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
} }
# 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 }')
}

86
menu.sh
View File

@ -2,21 +2,27 @@
source /etc/hysteria/core/scripts/utils.sh source /etc/hysteria/core/scripts/utils.sh
# Function to get system information # OPTION HANDLERS (ONLY NEEDED ONE)
get_system_info() {
OS=$(lsb_release -d | awk -F'\t' '{print $2}') hysteria2_add_user_handler() {
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') hysteria2_remove_user_handler() {
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 }')
hysteria2_show_user_uri_hanndler() {
}
hysteria2_change_port_handler() {
} }
# Function to modify users # Function to modify users
modify_users() { hysteria2_modify_users() {
modify_script="/etc/hysteria/users/modify.py" modify_script="/etc/hysteria/users/modify.py"
github_raw_url="https://raw.githubusercontent.com/ReturnFI/Hysteria2/main/modify.py" github_raw_url="https://raw.githubusercontent.com/ReturnFI/Hysteria2/main/modify.py"
@ -25,6 +31,10 @@ modify_users() {
python3 "$modify_script" python3 "$modify_script"
} }
warp_configure_handler() {
}
# Function to display the main menu # Function to display the main menu
display_main_menu() { display_main_menu() {
@ -100,34 +110,11 @@ hysteria2_menu() {
read -r choice read -r choice
case $choice in case $choice in
1) python3 /etc/hysteria/core/cli.py install-hysteria2 ;; 1) python3 /etc/hysteria/core/cli.py install-hysteria2 ;;
2) add_user ;; 2) hysteria2_add_user_handler ;;
3) modify_users ;; 3) hysteria2_modify_users ;;
4) show_uri ;; 4) hysteria2_show_user_uri_hanndler ;;
5) python3 /etc/hysteria2/core/cli.py traffic_status ;; 5) python3 /etc/hysteria2/core/cli.py traffic_status ;;
6) remove_user ;; 6) hysteria2_remove_user_handler ;;
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
display_advance_menu
read -r choice
case $choice in
1) install_tcp_brutal ;;
2) install_warp ;;
3) configure_warp ;;
4) uninstall_warp ;;
5) change_port ;;
6) update_core ;;
7) uninstall_hysteria ;;
0) return ;; 0) return ;;
*) echo "Invalid option. Please try again." ;; *) echo "Invalid option. Please try again." ;;
esac esac
@ -154,6 +141,29 @@ display_advance_menu() {
echo -ne "${yellow}➜ Enter your option: ${NC}" echo -ne "${yellow}➜ Enter your option: ${NC}"
} }
# Function to handle Advance menu options
advance_menu() {
clear
local choice
while true; do
display_advance_menu
read -r choice
case $choice in
1) python3 /etc/hysteria/core/cli.py install-tcp-brutal ;;
2) python3 /etc/hysteria/core/cli.py install-warp ;;
3) warp_configure_handler ;;
4) python3 /etc/hysteria/core/cli.py uninstall-warp ;;
5) hysteria2_change_port_handler ;;
6) python3 /etc/hysteria/core/cli.py update-hysteria2 ;;
7) python3 /etc/hysteria/core/cli.py uninstall-hysteria2 ;;
0) return ;;
*) echo "Invalid option. Please try again." ;;
esac
echo
read -rp "Press Enter to continue..."
done
}
# Main function to run the script # Main function to run the script
main() { main() {
main_menu main_menu