Skip to content

Instantly share code, notes, and snippets.

@aloncarmel
Last active August 29, 2015 14:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aloncarmel/bfb1fa7f1dd65f024d70 to your computer and use it in GitHub Desktop.
Save aloncarmel/bfb1fa7f1dd65f024d70 to your computer and use it in GitHub Desktop.
Install wordpress from shell for quick deployment on server
#!/bin/bash
# Command line WordPress installation script by Anatoliy Dimitrov
# Get input
filesystem_directory=$1
blog_title='ClientConnect WebAsset Wordpress'
admin_email=$2
admin_pass=$3
dbname=$4
dbuser=$5
dbpassword=$6
dbhost=$7
blogurl=$8
# Validate input
if [ $# != 8 ]
then
echo "Usage: `basename $0` filesystem_directory admin_email admin_passw blogdb_name blogdb_usr blogdb_pass blogdb_host blog_url"
exit 1
fi
# blog vars
db_name=$dbname
db_user=$dbuser
db_password=$dbpassword
db_host=$dbhost
# Create directory for blog
#tar -C $filesystem_directory -zxf latest.tar.gz --strip-components=1
mkdir $filesystem_directory && wget -qO $filesystem_directory/latest.tar.gz "http://wordpress.org/latest.tar.gz" && tar -C $filesystem_directory -zxf $filesystem_directory/latest.tar.gz --strip-components=1 && mkdir $filesystem_directory/wp-content/uploads
# Extract the installation archive, download the file before and save as latest.tar.gz
touch $filesystem_directory/htaccess.txt
touch $filesystem_directory/robots.txt
# Fix the ownership of the files
#chown nobody: $filesystem_directory -R
# Rename the default config file
mv $filesystem_directory/wp-config-sample.php $filesystem_directory/wp-config.php
# Substitute the default database values
sed -i "s/database_name_here/$db_name/g" $filesystem_directory/wp-config.php
sed -i "s/username_here/$db_user/g" $filesystem_directory/wp-config.php
sed -i "s/password_here/$db_password/g" $filesystem_directory/wp-config.php
sed -i "s/localhost/$db_host/g" $filesystem_directory/wp-config.php
# Get the salts and keys
grep -A50 'table_prefix' $filesystem_directory/wp-config.php > $filesystem_directory/wp-temp-config
sed -i '/**#@/,/$p/d' $filesystem_directory/wp-config.php
# Set blog url in config
echo "define('WP_HOME','$blogurl');" >> $filesystem_directory/wp-config.php
echo "define('WP_SITEURL','$blogurl');" >> $filesystem_directory/wp-config.php
wget https://api.wordpress.org/secret-key/1.1/salt/ -O - >> $filesystem_directory/wp-config.php
cat $filesystem_directory/wp-temp-config >> $filesystem_directory/wp-config.php
#Extract the themes and plugins
unzip WebAssetsTheme.zip -d $filesystem_directory/wp-content/themes/ && unzip WebAssetsPlugins.zip -d $filesystem_directory/wp-content/plugins/
mysql -h $dbhost -u $dbuser --password=$dbpassword -e "CREATE DATABASE $dbname"
# Populate the database
php -r "include '$filesystem_directory/wp-admin/install.php';
wp_install('$blog_title', 'admin', '$admin_email', 1, '', '$admin_pass');" > /dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment