Skip to content

Instantly share code, notes, and snippets.

@rnevius
Created October 11, 2014 16:37
Show Gist options
  • Select an option

  • Save rnevius/2c81c22bc7e2620a9f9b to your computer and use it in GitHub Desktop.

Select an option

Save rnevius/2c81c22bc7e2620a9f9b to your computer and use it in GitHub Desktop.

Revisions

  1. rnevius created this gist Oct 11, 2014.
    88 changes: 88 additions & 0 deletions wp-installer.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    #!/bin/bash -e
    clear

    echo ""
    echo "============================================="
    echo "# #"
    echo "# Welcome to the WordPress Installer #"
    echo "# #"
    echo "============================================="
    echo ""

    read -e -p "Database Name: " db_name
    read -e -p "Database User: " db_user
    read -e -p "Database Password: " db_pass
    echo ""
    read -e -p "Ready to Rock? (y/n): " run

    if [ "$run" == n ]
    then
    echo "Bye..."
    exit
    else
    echo ""
    echo "============================================"
    echo "# Installing WordPress #"
    echo "============================================"
    echo ""
    # Download, extract, and delete the latest, compressed version of WordPress
    wget http://wordpress.org/latest.tar.gz
    tar -xzvf latest.tar.gz --strip-components=1
    rm latest.tar.gz

    # Let's copy the first part of wp-config-sampe.php and start piecing together wp-config.php
    grep -F -B1015 -A1 "@since 2.6.0" wp-config-sample.php > wp-config.php

    # Set database details with perl find and replace
    perl -pi -e "s/database_name_here/$db_name/g" wp-config.php
    perl -pi -e "s/username_here/$db_user/g" wp-config.php
    perl -pi -e "s/password_here/$db_pass/g" wp-config.php

    # Use the WordPress.org secret-key service to download a set of secret keys
    # Save it in a file named keys.salt
    wget https://api.wordpress.org/secret-key/1.1/salt/ -O keys.salt

    # Append the authorization keys to the wp-config.php file
    cat keys.salt >> wp-config.php
    # Get rid of the keys file
    rm keys.salt

    # Finish building the config file by appending the last part of wp-config-sample.php
    grep -F -B1 -A1015 "/**#@-*/" wp-config-sample.php >> wp-config.php

    echo ""
    echo "============================================"
    echo "# Hardening WordPress #"
    echo "============================================"
    echo ""
    # Set the appropriate directory permissions
    find -type d -exec chmod 755 {} \;
    # Set the appropriate file permissions
    find -type f -exec chmod 644 {} \;
    # Set wp-config.php to 440. This is commented out, because it may break some configurations.
    # Uncomment at your own risk.
    # chmod 440 wp-config.php

    echo ""
    echo "============================================"
    echo "# Cleaning Up #"
    echo "============================================"
    echo ""
    # Deletes the currently-running script (self)
    rm ${0##*/}
    # Get rid of the crap default themes...leaving one for fallback
    rm -rf wp-content/themes/twentyfourteen || true
    rm -rf wp-content/themes/twentythirteen || true
    # Get rid of bogus plugins
    rm -rf wp-content/plugins/akismet || true
    rm wp-content/plugins/hello.php || true
    clear

    echo ""
    echo "============================================"
    echo "# WordPress installation complete! #"
    echo "# --- #"
    echo "# Stay classy, WordPress nerds #"
    echo "============================================"
    echo ""
    fi