Skip to content

Instantly share code, notes, and snippets.

@davidroberto
Created December 5, 2016 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidroberto/e0d8e3ce58d74995ce74bdd86c70a559 to your computer and use it in GitHub Desktop.
Save davidroberto/e0d8e3ce58d74995ce74bdd86c70a559 to your computer and use it in GitHub Desktop.
Bash script for wp install : create database, start mamp, download WP, define wp debug, generate password, install wp, clone a gulp based blank theme, generate posts etc...
#!/bin/bash -e
# define developpement root path
devdir=''
# define commercial dir
commdir=''
# define database root password
dbpass=''
# define Wordpress admin user
wpuser=''
# define WordPress Admin Email
adminemail=''
# define the blank theme link
blankthemelink='https://github.com/davidroberto/wp-skeleton-theme.git'
# define image to be uploaded in first post
firstimage = ''
# define image to be uploaded in first post
secondimage = ''
# define image to be uploaded in first post
thirdimage = ''
# define image to be uploaded in first post
fourthimage = ''
# define image to be uploaded in first post
fifthimage = ''
# define image to be uploaded in first post
sixthimage = ''
clear
echo -e "================================================================="
echo -e "WordPress Installer"
echo "================================================================="
# accept user input for the database name
echo "Database Name: "
read -e dbname
# accept the name of the website
echo "Site Name: "
read -e sitename
# accept the name of the website folder
echo "Site Folder: "
read -e sitefolder
# accept the name of the theme name
echo "Theme Name: "
read -e themename
# accept the slug of the theme name
echo "Theme slug:"
read -e themenameslug
# add a simple yes/no confirmation before we proceed
echo "Run Install? (y/n)"
read -e run
# if the user didn't say no, then go ahead and install
if [ "$run" == n ] ; then
exit
else
# starting mamp
echo "----- Startin MAMP... -----"
open -a Mamp
cd /Applications/MAMP/bin
./start.sh
cd ~
# cd into the www folder
echo "----- Create root folder and download wordpress... -----"
cd $devdir
# create the wp root folder & cd into the wp root folder
mkdir $sitefolder
# cd into the wp root folder
cd $devdir$sitefolder
# download the WordPress core files / french version
wp core download --locale=fr_FR --force
# create the wp-config file and enable WP_CONFIG and WP_DEBUG_LOG
echo "----- Configure wp config and enable WP_DEBUG -----"
wp core config --dbname=$dbname --dbuser=root --dbpass=$dbpass --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
PHP
# generate random 12 character password
password=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12)
# create database
echo "----- Create database -----"
wp db create
# install Wordpress
echo "----- Install Wordpress... -----"
wp core install --url="http://localhost:8888/$sitefolder" --title="$sitename" --admin_user="$wpuser" --admin_password="$password" --admin_email="$adminemail"
# clone wp skeleton theme
echo "----- Clone wp skeleton theme and activate it... -----"
cd wp-content/themes/
git clone $blankthemelink $themenameslug
# clone wp skeleton theme
echo "----- Rename theme in style.css and change path constants in functions.php... -----"
sed -i "" "s/wp-skeleton-theme/$themenameslug/" "$themenameslug/style.css"
sed -i "" "s/wp-skeleton-theme/$themenameslug/" "$themenameslug/functions.php"
# activate the theme
echo "----- Activate the theme... -----"
wp theme activate $themenameslug
# assign first menu
echo "----- create and assign menu... -----"
wp menu create "Top Menu"
wp menu location assign top-menu primary
# plugins and themes cleanup
echo "----- delete base plugins and base theme... -----"
wp post delete 1 --force # Article exemple - no trash. Comment is also deleted
wp post delete 2 --force # page exemple
wp plugin delete hello
wp theme delete twentytwelve
wp theme delete twentythirteen
wp theme delete twentyfourteen
wp theme delete twentyfifteen
wp theme delete twentysixteen
wp option update blogdescription ''
# create homepage page
echo "----- Create homepage page -----"
wp post create --post_type=page --post_title='Accueil' --post_status=publish
# change home page on front
echo "----- Change Homepage -----"
wp option update show_on_front page
wp option update page_on_front 3
# Generate 10 posts with lorem ipsum
echo "----- Generate posts with lorem ipsum fetched content -----"
curl http://loripsum.net/api/5 | wp post generate --post_content --count=10
# Import a local image and set it to be the post thumbnail for a post
echo "----- import images for posts -----"
wp media import $firstimage --post_id=3 --title="A downloaded picture" --featured_image
# Import a local image and set it to be the post thumbnail for a post
wp media import $secondimage --post_id=4 --title="A downloaded picture" --featured_image
# Import a local image and set it to be the post thumbnail for a post
wp media import $thirdimage --post_id=5 --title="A downloaded picture" --featured_image
# Import a local image and set it to be the post thumbnail for a post
wp media import $fouthimage --post_id=6 --title="A downloaded picture" --featured_image
# Import a local image and set it to be the post thumbnail for a post
wp media import $fifthimage --post_id=7 --title="A downloaded picture" --featured_image
# Import a local image and set it to be the post thumbnail for a post
wp media import $sixthimage --post_id=8 --title="A downloaded picture" --featured_image
# Permalinks to /%postname%/
echo "----- Active permalinks to postname -----"
wp rewrite structure "/%postname%/" --hard
wp rewrite flush --hard
# Initialize git and commit
echo "----- Initialize git and commit -----"
cd ../..
git init # git project
git add -A # Add all untracked files
git commit -m "Initial commit" # Commit changes
# open in browser, finder and Sublime Text
echo "----- open in browser, finder and Sublime Text -----"
# Open in browser
open http://localhost:8888/$sitefolder
open http://localhost:8888/$sitefolder/wp-admin
# Open in Sublime text
cd wp-content/themes/
open -a "Sublime Text" $themenameslug
# Create a text file with all the credentials
echo "----- Create a text file with all the credentials -----"
echo "Website:
Front-office: http://localhost:8888/$sitefolder
Back-office: http://localhost:8888/$sitefolder/wp-admin
Id: $wpuser
Password: $password
Database:
Name: $dbname
Username: root
Host: localhost
Password: $dbpass" > ~/Desktop/$sitefolder.txt
open ~/Desktop/$sitefolder.txt
# Run gulp in new tab
echo "----- Install gulp dependencies and run it in new tab -----"
cd $themenameslug
npm install
ttab -wd $devdir/$sitefolder/wp-content/themes/$themenameslug gulp
clear
echo "================================================================="
echo "Installation is done!"
echo ""
echo "Username: $wpuser"
echo "Password: $password"
echo ""
echo "================================================================="
fi
@kepon85
Copy link

kepon85 commented Jan 13, 2022

Replace :

wp theme delete twentytwelve
wp theme delete twentythirteen
wp theme delete twentyfourteen
wp theme delete twentyfifteen
wp theme delete twentysixteen

Per
wp theme delete --all (not delete active theme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment