#!/bin/bash # # v0.4 # # WPGet by Jason Corradino is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. # Based on a work at ImYourDeveloper.com. # http://creativecommons.org/licenses/by-sa/3.0/ # # Save in your home directory as wpget.sh # # Set in your bash_profile with the following alias (or make one up): # alias wpget=". ~/wpget.sh" # # NOTE!!! # Your user must be in your apache group in order for this to work completely. # Run the following command in OSX to put yourself in the _www group (or whatever group apache is running as): # sudo /usr/sbin/dseditgroup -o edit -a USERNAME -t user _www # # Usage: # Downloads version 3.2.1 into current directory --- wpget 3.2.1 # Downloads most recent version into current directory --- wpget # Downloads version 3.2.1 into home/web directory --- wpget 3.2.1 ~/web/ # # ToDo's # - give ability to discern between version number and destination so that user can download most recent into custom directory txtrst=$(tput sgr0) # Text reset txtred=$(tput setaf 1) # Red txtgrn=$(tput setaf 2) # Green txtblu=$(tput setaf 4) # Blue bold=$(tput bold) function setVersion { if [ -z $1 ]; then downloadString=latest.tar.gz downloadVersion="Current Version" else downloadString=wordpress-$1.tar.gz downloadVersion=$1 fi } function fileExists { wordpressFileExists=false if [ -z $2 ]; then if [ -f wordpress-$1.tar.gz ]; then wordpressFileExists=true fi elif [ -f $2/wordpress-$1.tar.gz ]; then wordpressFileExists=true fi } function downloadWordpress { echo "Downloading, this might take a moment..." response=$(curl --write-out %{http_code} --silent --output ./$1 http://wordpress.org/$1) } function moveAndUntar { if [ -z $2 ]; then tar -zxf $1 mv wordpress/* . rm -Rf wordpress rm $1 chmod -R 775 * chgrp -R _www * else tar -zxf $1 mv wordpress/* $2/ rm -Rf wordpress rm $1 chmod -R 775 $2/* chgrp -R _www $2/* fi } function mysqlCreateDatabase { MYSQL="$(which mysql)" echo "What is your mysql user?" read -p "> " mysqlUser echo "What is your mysql host?" read -p "> " mysqlHost echo "What is your database to be named?" read -p "> " newDatabase response=$($MYSQL -u $mysqlUser -h $mysqlHost -p -Bse "CREATE DATABASE IF NOT EXISTS $newDatabase") } setVersion $1 fileExists $1 $2 if [ $wordpressFileExists == false ]; then downloadWordpress $downloadString $2 fi if [ $response != 200 ]; then echo "${txtred}File not found!${txtrst}" echo "${txtred}${bold}Exiting${txtrst}" rm wordpress-$downloadString.tar.gz else echo "${txtgrn}Downloaded WordPress version '$downloadVersion', continuing... ${txtrst}" moveAndUntar $downloadString $2 echo "${txtgrn}Moved and uncompressed${txtrst}" while true; do echo "Would you like to set up a mysql database?" read -p "yes/no) " yn case $yn in [Yy]* ) mysqlCreateDatabase; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done echo "${txtblu}Done${txtrst}" fi