Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
set -e
function echo_color() {
# Some colors:
# 0-black, 1-red, 3-yellow, 76-green, 26 or 27-blue, 237-grey, 255-white
local background=''
local foreground=''
if [[ $2 != 'no' ]]; then
background="\033[48;5;${2:-237}m"
fi
if [[ $3 != 'no' ]]; then
foreground="\033[38;5;${3:-255}m"
fi
# http://misc.flogisoft.com/bash/tip_colors_and_formatting
echo -e "${foreground}${background}$1\033[0m";
}
function sanitize_version() {
local V=''
if [[ ! -z $1 ]]; then
V=$(git tag -l | grep $1 | tail -1)
fi
if [[ -z $V ]]; then
V=$(get_latest_version)
fi
echo $V
}
function get_latest_version() {
echo $(git tag -l | tail -n1)
}
function core() {
mkdir overlords
pushd overlords > /dev/null
local DIR=$2
local CONTENT=$3
echo_color "=Setting up WordPress..."
git clone git@github.com:WordPress/WordPress.git $DIR
cd $DIR
local VERSION=$(sanitize_version $1)
if [[ -z $VERSION ]]; then
echo_color "Error: This is not a WordPress repository." 256 1
exit 1
fi
git checkout tags/$VERSION
echo_color "Checked out WordPress $VERSION."
# rm -rf .git
cd -
cp $DIR/wp-content $CONTENT
echo_color "Moved wp-content to \"$CONTENT\"."
echo_color "=Copying config files..."
for file in $C10_DOTFILES/wp/*; do
cp $file .
done
mkdir bin
echo_color "=To finish setup you must:" no 3
echo_color "\t* Update wp-config.php with your db info." no 3
if [[ $DIR != 'wp' ]]; then
echo_color "\t* update config.php and wp-cli to change \"wp\" to \"$1\"." no 3
fi
echo_color "\t* Clone the deploy tool (git@github.com:c10b10/wp-deploy-flow.git) in" no 3
echo_color "\t \"bin/deploy\" or remove the \"require\" field in wp-cli.yml. " no 3
echo_color "\t* Update the \"url\" field in wp-cli.yml." no 3
echo_color "\t* Turn everything into a git repo?"
popd > /dev/null
}
read -e -p "The WordPress version (e.g \"3.8.1\" or \"3.8\"). Press return for the latest: " VERSION
VERSION=${VERSION:-''}
read -e -p "The name of the directory (Press return for \"wp\"): " DIR
DIR=${DIR:-wp}
read -e -p "The name of the wp-content directory (Press return for \"content\"): " CONTENT
CONTENT=${CONTENT:-content}
core $VERSION $DIR $CONTENT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment