Skip to content

Instantly share code, notes, and snippets.

@unaibamir
Last active April 4, 2021 00:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save unaibamir/4a047a5ed14532d681a8b389e4ed9ee7 to your computer and use it in GitHub Desktop.
A WP CLI addon script to install & configure WordPress in few seconds
#!/bin/bash
echo "================================================================="
echo "Awesome WordPress Installer!!"
echo "================================================================="
# download WordPress core files
wp core download
echo "Current Directory: ${PWD}"
# check required input is not given
isempty() {
if [ ! $1 ]; then
echo "**** It is required. ****"
exit
fi
}
# takes inputs for config file
wp_config_prompt() {
echo
read -p "Database Name: " DB_NAME
isempty $DB_NAME
HOSTNAME='localhost'
isempty $HOSTNAME
TPREFIX=wp_
read -e -i $TPREFIX -p "Table Prefix: " TABLE_PREFIX
isempty $TABLE_PREFIX
}
# take inputs for installation
wp_install_prompt() {
if [ $HOSTNAME == "localhost" ]; then
URL="$HOSTNAME/"
else
URL="SiteURL"
fi
read -e -i $URL -p "URL: " SITE_URL
isempty $SITE_URL
read -p "Site Title: " TITLE
isempty $TITLE
ADMIN_USER="admin"
read -e -i $ADMIN_USER -p "Admin User Name: " USER
isempty $USER
read -sp "Admin Password: " ADMIN_PASSWORD
isempty $ADMIN_PASSWORD
echo
ADMIN_EMAIL="admin@admin.com"
read -e -i $ADMIN_EMAIL -p "Admin Email: " ADMIN_EMAIL
isempty $ADMIN_EMAIL
}
# create wp-config.php file
core_config() {
wp config create --dbname=$DB_NAME --dbuser={MYSQL_USER_NAME} --dbpass={MYSQL_USER_PASSWORD} --dbhost=$HOSTNAME --dbprefix=$TABLE_PREFIX
}
# create database and install
core_install() {
wp db create
wp core install --url=$SITE_URL --title=$TITLE --admin_user=$USER --admin_password=$ADMIN_PASSWORD --admin_email=$ADMIN_EMAIL
}
plugin_install() {
read -r -p "Do you want to install All in one wp migration plugin? (y/n) " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
wp plugin install all-in-one-wp-migration --activate
fi
}
# exicute wp_config_prompt, core_config and core_install
install() {
wp_config_prompt
wp_install_prompt
core_config
core_install
plugin_install
}
install
clear
echo ""
echo "================================================================="
echo "Installation is complete. Your username/password is listed below."
echo ""
echo "Site URL: $SITE_URL"
echo ""
echo "Username: $ADMIN_USER"
echo "Password: $ADMIN_PASSWORD"
echo ""
echo "================================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment