Skip to content

Commit

Permalink
install.sh - check existing settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSanaei committed Oct 16, 2024
1 parent b36032e commit 744583b
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,46 +137,60 @@ gen_random_string() {
}

config_after_install() {
echo -e "${yellow}Install/update finished! For security, it's recommended to modify panel settings ${plain}"

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
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}"
return 0
fi
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_account=$(gen_random_string 10)
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_account}${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_account}" -password "${config_password}" -port "${config_port}" -webBasePath "${config_webBasePath}"
/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_account}${plain}"
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)

/usr/local/x-ui/x-ui setting -username "${config_account}" -password "${config_password}" -port "${portTemp}" -webBasePath "${config_webBasePath}"
/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 "###############################################"
echo -e "${green}Username: ${config_account}${plain}"
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}"
Expand All @@ -185,14 +199,6 @@ config_after_install() {
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}"

local existing_webBasePath=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'webBasePath: .+' | awk '{print $2}')

if [[ ${#existing_webBasePath} -lt 4 ]]; then
echo -e "${yellow}WebBasePath is empty, generating a random one...${plain}"

/usr/local/x-ui/x-ui setting -webBasePath "${config_webBasePath}"
echo -e "${green}New WebBasePath: ${config_webBasePath}${plain}"
fi
fi
fi

Expand Down

2 comments on commit 744583b

@cr4ckker
Copy link

@cr4ckker cr4ckker commented on 744583b Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this commit user is unable to set custom creds and webbasepath. Even with first installation

@MHSanaei
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cr4ckker
It will be generated randomly.

Please sign in to comment.