From ebf45c2131c8fb69060efcc7572e78792be0042f Mon Sep 17 00:00:00 2001 From: Sanaei Date: Mon, 28 Oct 2024 16:44:22 +0100 Subject: [PATCH] Update install.sh (#1495) * Update install.sh * legacy version --- README.md | 2 +- install.sh | 80 ++++++++++++++++++++++-------------------------------- x-ui.sh | 6 ++-- 3 files changed, 37 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index b28be56e1b..8a6f65f7b0 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ bash <(curl -Ls https://raw.githubusercontent.com/alireza0/x-ui/master/install.sh) ``` -## Install Custom Version +## Install Legacy Version **Step 1:** To install an old version, use following installation command. e.g., version `1.8.0`: diff --git a/install.sh b/install.sh index 8ed9be6688..167ffe42b4 100755 --- a/install.sh +++ b/install.sh @@ -137,69 +137,55 @@ gen_random_string() { } config_after_install() { - local existing_username=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'username: .+' | awk '{print $2}') local existing_password=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'password: .+' | awk '{print $2}') local existing_webBasePath=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'webBasePath: .+' | awk '{print $2}') - # Check if username and password exist - if [[ -n "$existing_username" && -n "$existing_password" ]]; then - # If webBasePath is missing, generate a new one - if [[ ${#existing_webBasePath} -lt 4 ]]; then + if [[ ${#existing_webBasePath} -lt 4 ]]; then + if [[ "$existing_username" == "admin" && "$existing_password" == "admin" ]]; then + local config_webBasePath=$(gen_random_string 15) + local config_username=$(gen_random_string 10) + local config_password=$(gen_random_string 10) + + read -p "Would you like to customize the Panel Port settings? (If not, random port will be applied) [y/n]: " config_confirm + if [[ "${config_confirm}" == "y" || "${config_confirm}" == "Y" ]]; then + read -p "Please set up the panel port: " config_port + echo -e "${yellow}Your Panel Port is: ${config_port}${plain}" + else + local config_port=$(shuf -i 1024-62000 -n 1) + echo -e "${yellow}Generated random port: ${config_port}${plain}" + fi + + /usr/local/x-ui/x-ui setting -username "${config_username}" -password "${config_password}" -port "${config_port}" -webBasePath "${config_webBasePath}" + echo -e "This is a fresh installation, generating random login info for security concerns:" + echo -e "###############################################" + echo -e "${green}Username: ${config_username}${plain}" + echo -e "${green}Password: ${config_password}${plain}" + echo -e "${green}Port: ${config_port}${plain}" + echo -e "${green}WebBasePath: ${config_webBasePath}${plain}" + echo -e "###############################################" + echo -e "${yellow}If you forgot your login info, you can type 'x-ui settings' to check${plain}" + else local config_webBasePath=$(gen_random_string 15) echo -e "${yellow}WebBasePath is missing or too short. Generating a new one...${plain}" /usr/local/x-ui/x-ui setting -webBasePath "${config_webBasePath}" echo -e "${green}New WebBasePath: ${config_webBasePath}${plain}" - else - echo -e "${green}Username, Password, and WebBasePath are already set. Exiting...${plain}" fi - /usr/local/x-ui/x-ui migrate - return 0 - fi - - read -p "Would you like to customize the Panel Port settings? (If not, random settings will be applied) [y/n]: " config_confirm - - local config_webBasePath=$(gen_random_string 15) - local config_username=$(gen_random_string 10) - local config_password=$(gen_random_string 10) - - if [[ "${config_confirm}" == "y" || "${config_confirm}" == "Y" ]]; then - read -p "Please set up the panel port: " config_port - echo -e "${yellow}Your Panel Port is: ${config_port}${plain}" - - echo -e "${yellow}Your Username will be generated randomly: ${config_username}${plain}" - echo -e "${yellow}Your Password will be generated randomly: ${config_password}${plain}" - echo -e "${yellow}Your Web Base Path will be generated randomly: ${config_webBasePath}${plain}" - - echo -e "${yellow}Initializing, please wait...${plain}" - - /usr/local/x-ui/x-ui setting -username "${config_username}" -password "${config_password}" -port "${config_port}" -webBasePath "${config_webBasePath}" - echo -e "${green}Settings applied successfully!${plain}" - - echo -e "###############################################" - echo -e "${green}Username: ${config_username}${plain}" - echo -e "${green}Password: ${config_password}${plain}" - echo -e "${green}Port: ${config_port}${plain}" - echo -e "${green}WebBasePath: ${config_webBasePath}${plain}" - echo -e "###############################################" else - echo -e "${red}Cancel...${plain}" - - if [[ ! -f "/etc/x-ui/x-ui.db" ]]; then - local portTemp=$(shuf -i 1024-62000 -n 1) + if [[ "$existing_username" == "admin" && "$existing_password" == "admin" ]]; then + local config_username=$(gen_random_string 10) + local config_password=$(gen_random_string 10) - /usr/local/x-ui/x-ui setting -username "${config_username}" -password "${config_password}" -port "${portTemp}" -webBasePath "${config_webBasePath}" - echo -e "This is a fresh installation, generating random login info for security concerns:" + echo -e "${yellow}Default credentials detected. Security update required...${plain}" + /usr/local/x-ui/x-ui setting -username "${config_username}" -password "${config_password}" + echo -e "Generated new random login credentials:" echo -e "###############################################" echo -e "${green}Username: ${config_username}${plain}" echo -e "${green}Password: ${config_password}${plain}" - echo -e "${green}Port: ${portTemp}${plain}" - echo -e "${green}WebBasePath: ${config_webBasePath}${plain}" echo -e "###############################################" - echo -e "${yellow}If you forgot your login info, you can type 'x-ui settings' to check after installation${plain}" + echo -e "${yellow}If you forgot your login info, you can type 'x-ui settings' to check${plain}" else - echo -e "${yellow}This is your upgrade, keeping old settings. If you forgot your login info, you can type 'x-ui settings' to check${plain}" - + echo -e "${green}Username, Password, and WebBasePath are properly set. Exiting...${plain}" fi fi diff --git a/x-ui.sh b/x-ui.sh index 0d39b65860..6d09b9c177 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -160,7 +160,7 @@ update() { fi } -custom_version() { +legacy_version() { echo "Enter the panel version (like 1.6.0):" read panel_version @@ -1123,7 +1123,7 @@ show_menu() { ———————————————— ${green}1.${plain} Install ${green}2.${plain} Update - ${green}3.${plain} Custom Version + ${green}3.${plain} Legacy Version ${green}4.${plain} Uninstall ———————————————— ${green}5.${plain} Reset Username and Password @@ -1163,7 +1163,7 @@ show_menu() { check_install && update ;; 3) - check_install && custom_version + check_install && legacy_version ;; 4) check_install && uninstall