Skip to content

Instantly share code, notes, and snippets.

@rpkoller
Last active November 23, 2021 20:17
Show Gist options
  • Select an option

  • Save rpkoller/e99541c1963c4b976565 to your computer and use it in GitHub Desktop.

Select an option

Save rpkoller/e99541c1963c4b976565 to your computer and use it in GitHub Desktop.
Bash script to automate most parts of a WP install
#!/bin/bash -e
echo "-------------------------------------------------------------------------------------"
echo "| Configuration |"
echo "-------------------------------------------------------------------------------------"
echo " MySQL"
echo "-------------------------------------------------------------------------------------"
read -p "MySQL root password (necessary for db and user creation) : " rootpw
echo "-------------------------------------------------------------------------------------"
read -p "MySQL database name to be created : " wpdb
read -p "MySQL username to be created : " wpdbuser
read -p "MySQL password to be created : " wpdbpw
echo "-------------------------------------------------------------------------------------"
echo " WordPress"
echo "-------------------------------------------------------------------------------------"
read -p "WordPress hostname : " wphost
read -p "How many characters the WordPress prefix should have : " wpprefixchar
echo "Which WordPress localization should be used?"
read -p "en_US(default) or de_DE : " wplanguage
echo "-------------------------------------------------------------------------------------"
echo " Downloading the latest WordPress revision..."
echo "-------------------------------------------------------------------------------------"
if [ "$wplanguage" = de_DE ] ; then
curl -O https://downloads.wordpress.org/release/de_DE/latest.zip
tar xfz latest.zip
mv wordpress/* .
rm latest.zip && rm -rf wordpress
else
curl -O http://wordpress.org/latest.tar.gz
tar xfz latest.tar.gz
mv wordpress/* .
rm latest.tar.gz && rm -rf wordpress
fi
echo "-------------------------------------------------------------------------------------"
echo " Setting up MySQL DB and user..."
echo "-------------------------------------------------------------------------------------"
MYSQL=`which mysql`
wpdbinit="create database $wpdb;GRANT ALL PRIVILEGES ON $wpdb.* TO '$wpdbuser'@'$wphost' IDENTIFIED BY '$wpdbpw';FLUSH PRIVILEGES;"
$MYSQL -uroot -p$rootpw -e "$wpdbinit"
cp wp-config-sample.php wp-config.php
echo "-------------------------------------------------------------------------------------"
echo " Adding given informations to the wp-config.php file and creating random salts..."
echo "-------------------------------------------------------------------------------------"
perl -pi -e "s/database_name_here/$wpdb/" wp-config.php
perl -pi -e "s/username_here/$wpdbuser/" wp-config.php
perl -pi -e "s/password_here/$wpdbpw/" wp-config.php
perl -pi -e "s/localhost/$wphost/" wp-config.php
authkey=$(LC_ALL=C tr -cd 'a-zA-Z0-9,;.:_#*+~!@$%&()=?{[]}|><-' < /dev/random | head -c 64)
secauthkey=$(LC_ALL=C tr -cd 'a-zA-Z0-9,;.:_#*+~!@$%&()=?{[]}|><-' < /dev/random | head -c 64)
loggedinkey=$(LC_ALL=C tr -cd 'a-zA-Z0-9,;.:_#*+~!@$%&()=?{[]}|><-' < /dev/random | head -c 64)
noncekey=$(LC_ALL=C tr -cd 'a-zA-Z0-9,;.:_#*+~!@$%&()=?{[]}|><-' < /dev/random | head -c 64)
authsalt=$(LC_ALL=C tr -cd 'a-zA-Z0-9,;.:_#*+~!@$%&()=?{[]}|><-' < /dev/random | head -c 64)
secauthkey=$(LC_ALL=C tr -cd 'a-zA-Z0-9,;.:_#*+~!@$%&()=?{[]}|><-' < /dev/random | head -c 64)
loggedinsalt=$(LC_ALL=C tr -cd 'a-zA-Z0-9,;.:_#*+~!@$%&()=?{[]}|><-' < /dev/random | head -c 64)
noncesalt=$(LC_ALL=C tr -cd 'a-zA-Z0-9,;.:_#*+~!@$%&()=?{[]}|><-' < /dev/random | head -c 64)
perl -pi -e "s'\'AUTH_KEY\', \'put your unique phrase here\''\'AUTH_KEY\', \'$authkey\''" wp-config.php
perl -pi -e "s'\'SECURE_AUTH_KEY\', \'put your unique phrase here\''\'SECURE_AUTH_KEY\', \'$secauthkey\''" wp-config.php
perl -pi -e "s'\'LOGGED_IN_KEY\', \'put your unique phrase here\''\'LOGGED_IN_KEY\', \'$loggedinkey\''" wp-config.php
perl -pi -e "s'\'NONCE_KEY\', \'put your unique phrase here\''\'NONCE_KEY\', \'$noncekey\''" wp-config.php
perl -pi -e "s'\'AUTH_SALT\', \'put your unique phrase here\''\'AUTH_SALT\', \'$authsalt\''" wp-config.php
perl -pi -e "s'\'SECURE_AUTH_SALT\', \'put your unique phrase here\''\'SECURE_AUTH_SALT\', \'$secauthkey\''" wp-config.php
perl -pi -e "s'\'LOGGED_IN_SALT\', \'put your unique phrase here\''\'LOGGED_IN_SALT\', \'$loggedinsalt\''" wp-config.php
perl -pi -e "s'\'NONCE_SALT\', \'put your unique phrase here\''\'NONCE_SALT\', \'$noncesalt\''" wp-config.php
wpprefix=$(LC_ALL=C tr -cd 'a-zA-Z' < /dev/random | head -c $wpprefixchar)_
perl -pi -e "s/wp_/$wpprefix/" wp-config.php
perl -pi -e "s/'WPLANG', ''/'WPLANG', '$wplanguage'/" wp-config.php
echo "-------------------------------------------------------------------------------------"
echo " MySQL"
echo "-------------------------------------------------------------------------------------"
echo " DB Name : $wpdb "
echo " Username : $wpdbuser"
echo " Password : $wpdbpw"
echo "-------------------------------------------------------------------------------------"
echo " WordPress"
echo "-------------------------------------------------------------------------------------"
echo " Hostname : $wphost"
echo " DB Prefix : $wpprefix"
echo "------------------------------------------------------------------------------------"
echo " Generated random salts"
echo "------------------------------------------------------------------------------------"
echo " AUTH_KEY : $authkey"
echo " SECURE_AUTH_KEY : $secauthkey"
echo " LOGGED_IN_KEY : $loggedinkey"
echo " NONCE_KEY : $noncekey"
echo " AUTH_SALT : $authsalt"
echo " SECURE_AUTH_SALT : $secauthkey"
echo " LOGGED_IN_SALT : $loggedinsalt"
echo " NONCE_SALT : $noncesalt"
echo "------------------------------------------------------------------------------------"
open http://localhost:8888/${PWD##*/}/wp-admin/install.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment