Advertisement
Guest User

Untitled

a guest
May 25th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.65 KB | None | 0 0
  1. #!/bin/bash -e
  2. clear
  3.  
  4. # based on the script by Christopher Geary - http://www.ltconsulting.co.uk/automated-wordpress-installation-with-bash-wp-cli/
  5.  
  6. # New site username
  7. wpuser='webmaster'
  8.  
  9. echo "================================================================="
  10. echo " Symbiosis WordPress Installer!"
  11. echo " try not to break things! "
  12. echo "================================================================="
  13. echo ""
  14.  
  15. # accept user input for the MySQL password
  16. echo "MySQL root user password: "
  17. read -e rootpw
  18.  
  19.  
  20. # accept user input for the databse name
  21. echo "Database User and Database Name: "
  22. read -e dbname
  23.  
  24.  
  25.  
  26. # accept the name of our website
  27. echo "Site Name: "
  28. read -e sitename
  29.  
  30. # accept a comma separated list of pages
  31. echo "Add Pages: "
  32. read -e allpages
  33.  
  34. # add a simple yes/no confirmation before we proceed
  35. echo "Run Install? (y/n)"
  36. read -e run
  37.  
  38. # if the user didn't say no, then go ahead an install
  39. if [ "$run" == n ] ; then
  40.     exit
  41. else
  42.  
  43. # Create the Database for the website
  44.  
  45. # generate random 12 character password
  46. dbpass=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12)
  47.  
  48. MYSQL_HISTFILE=/dev/null mysql -u root -p$rootpw
  49. CREATE DATABASE $dbname;
  50. show databases;
  51. create user $dbname;
  52. grant all on $dbname.* to '$dbname'@'localhost' identified by '$dbpass';
  53. quit;
  54.  
  55.  
  56. # download the WordPress core files (locale codes can be found here - http://wpcentral.io/internationalization/)
  57. wp core download --locale=en_GB
  58.  
  59. # create the wp-config file with our standard setup
  60. wp core config --dbname=$dbname --dbuser=$dbname --dbpass=$dbpass --extra-php <<PHP
  61. define( 'WP_DEBUG', true );
  62. define( 'DISALLOW_FILE_EDIT', true );
  63. PHP
  64.  
  65. # parse the current directory name
  66. currentdirectory=$pwd | cut -d/ -f3
  67.  
  68. # generate random 12 character password
  69. password=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12)
  70.  
  71. # copy password to clipboard
  72. echo $password | pbcopy
  73.  
  74. # create database, and install WordPress
  75. wp db create
  76. wp core install --url="http://localhost/$currentdirectory" --title="$sitename" --admin_user="$wpuser" --admin_password="$password" --admin_email="user@example.org"
  77.  
  78. # discourage search engines
  79. wp option update blog_public 0
  80.  
  81. # show only 6 posts on an archive page
  82. wp option update posts_per_page 6
  83.  
  84. # delete sample page, and create homepage
  85. wp post delete $(wp post list --post_type=page --posts_per_page=1 --post_status=publish --pagename="sample-page" --field=ID --format=ids)
  86. wp post create --post_type=page --post_title=Home --post_status=publish --post_author=$(wp user get $wpuser --field=ID --format=ids)
  87.  
  88. # set homepage as front page
  89. wp option update show_on_front 'page'
  90.  
  91. # set homepage to be the new page
  92. wp option update page_on_front $(wp post list --post_type=page --post_status=publish --posts_per_page=1 --pagename=home --field=ID --format=ids)
  93.  
  94. # create all of the pages
  95. export IFS=","
  96. for page in $allpages; do
  97.     wp post create --post_type=page --post_status=publish --post_author=$(wp user get $wpuser --field=ID --format=ids) --post_title="$(echo $page | sed -e 's/^ *//' -e 's/ *$//')"
  98. done
  99.  
  100. # set pretty urls
  101. wp rewrite structure '/%postname%/' --hard
  102. wp rewrite flush --hard
  103.  
  104. # delete akismet and hello dolly
  105. wp plugin delete akismet
  106. wp plugin delete hello
  107.  
  108. # install lt-tables plugin
  109. wp plugin install https://github.com/ltconsulting/lt-tables/archive/master.zip --activate
  110.  
  111. # install some plugins
  112. wp plugin install 404-to-Start --activate
  113. wp plugin install Advanced-Automatic-Updates --activate
  114. wp plugin install Anti-spam --activate
  115.  
  116.  
  117.  
  118. # install the company starter theme
  119. wp theme install ~/Documents/lt-theme.zip --activate
  120.  
  121. clear
  122.  
  123. # create a navigation bar
  124. wp menu create "Main Navigation"
  125.  
  126. # add pages to navigation
  127. export IFS=" "
  128. for pageid in $(wp post list --order="ASC" --orderby="date" --post_type=page --post_status=publish --posts_per_page=-1 --field=ID --format=ids); do
  129.     wp menu item add-post main-navigation $pageid
  130. done
  131.  
  132. # assign navigaiton to primary location
  133. wp menu location assign main-navigation primary
  134.  
  135. clear
  136.  
  137. echo "================================================================="
  138. echo "Installation is complete. Your username/password is listed below."
  139. echo ""
  140. echo "Username: $wpuser"
  141. echo "Password: $password"
  142. echo ""
  143. echo "================================================================="
  144.  
  145. # Open the new website with Google Chrome
  146. /usr/bin/open -a "/Applications/Google Chrome.app" "http://localhost/$currentdirectory/wp-login.php"
  147.  
  148. # Open the project in TextMate
  149. /Applications/TextMate.app/Contents/Resources/mate /Applications/MAMP/htdocs/$currentdirectory/wp-content/themes/lt-theme
  150.  
  151. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement