This commit is contained in:
hhftechnologies 2024-11-27 15:48:52 +05:30
parent 7328f25e68
commit 58ede549dc

View file

@ -52,24 +52,21 @@ download_formatter
# Function to collect WordPress and backup variables
collect_variables() {
# Clear any existing values
unset DATABASE WP_DIR SCRIPTS_DIR S3_BUCKET_NAME S3_FOLDER_NAME
echo "Please provide the following information:"
echo "----------------------------------------"
# Database name
while [ -z "$DATABASE" ]; do
read -r -p "Enter database name: " DATABASE
if [ -z "$DATABASE" ]; then
echo "Database name cannot be empty. Please try again."
fi
done
echo -n "Enter database name: "
read -r DATABASE
echo "Received database name: $DATABASE"
# WordPress directory
while [ -z "$WP_DIR" ]; do
read -r -p "Enter WordPress installation path (e.g., /home/username/htdocs/domain.com): " WP_DIR
if [ -z "$WP_DIR" ]; then
echo "WordPress path cannot be empty. Please try again."
fi
done
echo -n "Enter WordPress installation path (e.g., /home/username/htdocs/domain.com): "
read -r WP_DIR
echo "Received WordPress path: $WP_DIR"
# Derive WordPress content directories
UPLOADS_DIR="${WP_DIR}/wp-content/uploads"
@ -78,13 +75,9 @@ collect_variables() {
WPCONTENT_DIR="${WP_DIR}/wp-content"
echo -e "\nBackup Locations:"
# Scripts directory
while [ -z "$SCRIPTS_DIR" ]; do
read -r -p "Enter scripts directory path (e.g., /home/username/scripts): " SCRIPTS_DIR
if [ -z "$SCRIPTS_DIR" ]; then
echo "Scripts directory path cannot be empty. Please try again."
fi
done
echo -n "Enter scripts directory path (e.g., /home/username/scripts): "
read -r SCRIPTS_DIR
echo "Received scripts path: $SCRIPTS_DIR"
# Backup directory
BACKUP_DIR="${SCRIPTS_DIR}/backups"
@ -94,28 +87,19 @@ collect_variables() {
# S3cmd path
S3_CMD="/usr/local/bin/s3cmd"
if [ ! -f "$S3_CMD" ]; then
while [ ! -f "$S3_CMD" ]; do
read -r -p "s3cmd not found at default location. Enter s3cmd path: " S3_CMD
if [ ! -f "$S3_CMD" ]; then
echo "Invalid path. File does not exist. Please try again."
fi
done
echo -n "s3cmd not found at default location. Enter s3cmd path: "
read -r S3_CMD
echo "Received s3cmd path: $S3_CMD"
fi
# S3 bucket information
while [ -z "$S3_BUCKET_NAME" ]; do
read -r -p "Enter S3 bucket name (e.g., my-bucket): " S3_BUCKET_NAME
if [ -z "$S3_BUCKET_NAME" ]; then
echo "S3 bucket name cannot be empty. Please try again."
fi
done
echo -n "Enter S3 bucket name (e.g., my-bucket): "
read -r S3_BUCKET_NAME
echo "Received bucket name: $S3_BUCKET_NAME"
while [ -z "$S3_FOLDER_NAME" ]; do
read -r -p "Enter S3 folder name (e.g., backups): " S3_FOLDER_NAME
if [ -z "$S3_FOLDER_NAME" ]; then
echo "S3 folder name cannot be empty. Please try again."
fi
done
echo -n "Enter S3 folder name (e.g., backups): "
read -r S3_FOLDER_NAME
echo "Received folder name: $S3_FOLDER_NAME"
S3_BUCKET="s3://${S3_BUCKET_NAME}/${S3_FOLDER_NAME}/"
@ -131,6 +115,33 @@ collect_variables() {
echo "Backup Directory: $BACKUP_DIR"
echo "S3 Bucket Path: $S3_BUCKET"
# Confirm information
echo -n "Is this information correct? (y/n): "
read -r confirm
if [[ $confirm != [Yy]* ]]; then
echo "Please run the script again with correct information."
return 1
fi
# Export variables so they're available to other functions
export DATABASE WP_DIR UPLOADS_DIR THEMES_DIR PLUGINS_DIR WPCONTENT_DIR
export BACKUP_DIR SCRIPTS_DIR CURRENT_DATE S3_CMD S3_BUCKET
return 0
}
# Current date for backup naming
CURRENT_DATE=$(date +"%Y-%m-%d")
# Display collected information
echo -e "\nSummary of collected information:"
echo "----------------------------------------"
echo "Database Name: $DATABASE"
echo "WordPress Directory: $WP_DIR"
echo "Scripts Directory: $SCRIPTS_DIR"
echo "Backup Directory: $BACKUP_DIR"
echo "S3 Bucket Path: $S3_BUCKET"
# Confirm information
read -p "Is this information correct? (y/n): " confirm
if [[ $confirm != [Yy]* ]]; then