Skip to content

Instantly share code, notes, and snippets.

@c10b10
Created February 7, 2014 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c10b10/8872011 to your computer and use it in GitHub Desktop.
Save c10b10/8872011 to your computer and use it in GitHub Desktop.
#!/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() {
local DIR=$2
local CONTENT=$3
local CONTAINER=$4
if [[ ! -z $CONTAINER ]]; then
mkdir $CONTAINER
pushd $CONTAINER > /dev/null
fi
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 -R $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?" no
if [[ ! -z $CONTAINER ]]; then
popd > /dev/null
fi
CONTAINER=${CONTAINER:-the current working directory}
echo_color "WordPress $VERSION has been set up in $CONTAINER." no 76
}
read -e -p "The WordPress version (e.g \"3.5.2\" or \"3.8\"). Press return for the latest: " VERSION
VERSION=${VERSION:-''}
read -e -p "The name of the wordpress (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}
read -e -p "The name of the container directory (Press return if you want to use cwd): " CONTAINER
CONTAINER=${CONTAINER:-''}
core "$VERSION" "$DIR" "$CONTENT" "$CONTAINER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment