60 lines
1.8 KiB
Bash
Executable File
60 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Function to prompt for input with validation
|
|
prompt_for_input() {
|
|
local prompt="$1"
|
|
local var_name="$2"
|
|
read -p "$prompt: " input
|
|
|
|
# Check if input is empty and prompt again
|
|
while [[ -z "$input" ]]; do
|
|
echo "Input cannot be empty. Please enter a value."
|
|
read -p "$prompt: " input
|
|
done
|
|
|
|
# Set the variable
|
|
eval "$var_name='$input'"
|
|
}
|
|
|
|
# Prompt for Mariadb details
|
|
prompt_for_input "Enter the Mariadb database name" DB_NAME
|
|
prompt_for_input "Enter the Mariadb username" DB_USER
|
|
prompt_for_input "Enter the Mariadb password" DB_PASSWORD
|
|
prompt_for_input "Enter the Mariadb root password" ROOT_PASSWORD
|
|
prompt_for_input "Enter the port number (default: 3307)" PORT
|
|
PORT=${PORT:-3307} # Default to 3307 if not specified
|
|
|
|
# Update .env file
|
|
ENV_FILE=".env"
|
|
|
|
if [[ -f "$ENV_FILE" ]]; then
|
|
# Replace the variables in the .env file
|
|
sed -i.bak "s/MARIADB_DATABASE=\"[^\"]*\"/MARIADB_DATABASE=\"$DB_NAME\"/" "$ENV_FILE"
|
|
sed -i.bak "s/MARIADB_USER=\"[^\"]*\"/MARIADB_USER=\"$DB_USER\"/" "$ENV_FILE"
|
|
sed -i.bak "s/MARIADB_PASSWORD=\"[^\"]*\"/MARIADB_PASSWORD=\"$DB_PASSWORD\"/" "$ENV_FILE"
|
|
sed -i.bak "s/MARIADB_ROOT_PASSWORD=\"[^\"]*\"/MARIADB_ROOT_PASSWORD=\"$ROOT_PASSWORD\"/" "$ENV_FILE"
|
|
echo ".env file updated successfully."
|
|
|
|
else
|
|
echo "Error: .env file not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Update compose.yaml file
|
|
COMPOSE_FILE="compose.yaml"
|
|
|
|
if [[ -f "$COMPOSE_FILE" ]]; then
|
|
# Replace 'db1' with the new database name
|
|
sed -i.bak "s/db1/$DB_NAME/g" "$COMPOSE_FILE"
|
|
|
|
# Update the ports section
|
|
sed -i.bak "s/3307:3306/$PORT:3306/" "$COMPOSE_FILE"
|
|
|
|
echo "compose.yaml file updated successfully."
|
|
else
|
|
echo "Error: compose.yaml file not found."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Setup completed successfully."
|