Last active
February 5, 2016 16:36
-
-
Save iamsortiz/7a6e37ef87de1b15259a to your computer and use it in GitHub Desktop.
Bootstrap a Wordpress Trellis environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
################################################################################ | |
# | |
# The MIT License (MIT) | |
# | |
# Copyright (c) 2015 Samuel Ortiz Reina (@iamsortiz) | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# | |
################################################################################ | |
################################################################################ | |
# | |
# README.md | |
# | |
# # Trellis helloworld bootstrap script | |
# | |
# **Trellis: https://github.com/roots/trellis** | |
# | |
# GIST URL: https://gist.github.com/iamsortiz/7a6e37ef87de1b15259a | |
# | |
# ## TODO | |
# | |
# * _provision_vagrant(): Test vagrant pluggins installation | |
# * _main(): Include provisioning (¿optional?) | |
# | |
################################################################################ | |
################################################################################ | |
# | |
# CONFIG | |
# | |
################################################################################ | |
TRELLIS_VERSION=0.9.3 | |
BEDROCK_VERSION=1.5.3 | |
################################################################################ | |
# | |
# MAIN FUNCTION | |
# | |
################################################################################ | |
#[WIP] | |
function _main() { | |
_checkout 'trellis' $TRELLIS_VERSION | |
_checkout 'bedrock' $BEDROCK_VERSION | |
} | |
################################################################################ | |
# | |
# AUX FUNCTIONS | |
# | |
################################################################################ | |
#/** | |
#* @summary Executes _main() on target folder and gets back to original folder | |
#* @param $1 {PATH} TARGET_FOLDER (default: $(pwd)) | |
#*/ | |
function _mainWrapper() { | |
TARGET_FOLDER=${1:-$(pwd)} # [ATTRIBUTION] Bash default value for variable (from: http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash) | |
ORIGINAL_FOLDER=$(pwd) | |
mkdir -p $TARGET_FOLDER | |
cd $TARGET_FOLDER | |
_main | |
cd $ORIGINAL_FOLDER | |
} | |
function _checkout() { | |
REPO=$1 | |
VERSION=$2 | |
ORIGINAL_FOLDER=$(pwd) | |
echo "Cloning: $REPO" | |
git clone git@github.com:roots/$REPO.git > /dev/null 2> /dev/null | |
cd $REPO | |
echo -e "\tversion: $VERSION" | |
git checkout tags/$VERSION > /dev/null 2> /dev/null | |
GITSTATUS=$(git status | head -n 1) | |
echo -e "\tgitstatus: $GITSTATUS" | |
rm -rf ./.git | |
cd $ORIGINAL_FOLDER | |
} | |
################################################################################ | |
# | |
# PROVISIONING REQUIREMENTS | |
# | |
################################################################################ | |
#[WIP] | |
function _provision_vagrant () { | |
VAGRANT_VERSION=1.8.1 | |
#Debian 64 bit URL | |
VAGRANT_DEB_URL="https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb" | |
PACKAGE='vagrant' | |
echo "Provisioning package: $PACKAGE" | |
INSTALLED=$(_provision_isDEBInstalled $PACKAGE) | |
if [ "$INSTALLED" = false ]; then | |
_provision_installDEB $VAGRANT_DEB_URL | |
#vagrant plugin install vagrant-bindfs | |
#vagrant plugin install vagrant-hostmanager | |
echo "INSTALL" | |
elif [ "$INSTALLED" = true ]; then | |
echo -e '\t[DONE] Alredy installed' | |
echo -e "\t$(dpkg -s vagrant | grep Version)" | |
else | |
error | |
fi | |
} | |
# [ATTRIBUTION] "true false" based in: http://stackoverflow.com/questions/2953646/how-to-declare-and-use-boolean-variables-in-shell-script | |
function _provision_isDEBInstalled () { | |
PACKAGE=$1 | |
if [ ! -z "$PACKAGE" ]; then | |
CHECK_INSTALLED=$(dpkg -s $PACKAGE 2> /dev/null | grep 'Status: install ok installed') | |
if [ ! -z "$CHECK_INSTALLED" ]; then | |
echo 'true' | |
else | |
echo 'false' | |
fi | |
else | |
error 'Missing first parameter (package name)' | |
echo 'null' | |
fi | |
} | |
function _provision_installDEB () { | |
DEB_URL=$1 | |
TEMPFILE="ERASEME.tmp.deb" | |
curl $DEB_URL -o "$TEMPFILE" | |
sudo dpkg -i $TEMPFILE | |
rm $TEMPFILE | |
} | |
################################################################################ | |
# | |
# ERROR HANDLING | |
# | |
################################################################################ | |
#/** | |
#* @summary Print to error output "alias" | |
#*/ | |
# [ATTRIBUTION] Based in: http://stackoverflow.com/questions/2990414/echo-that-outputs-to-stderr | |
function echoerr () { | |
>&2 echo -e $1 | |
} | |
#/** | |
#* @summary Kills the script with debug data due a blocking error. | |
#*/ | |
function error () { | |
echoerr "[ERROR] $*" | |
bashtrace | |
exit 1 | |
} | |
#/** | |
#* @summary Stacktrace for BASH | |
#*/ | |
# [ATTRIBUTION] from: http://stackoverflow.com/questions/10707173/bash-parameter-quotes-and-eval/10707498#10707498 | |
function bashtrace () { | |
#echoerr "[$( caller )] $*" | |
echoerr "Stacktrace:" | |
# i=2 to skip last 2 calls to visualice just relevant data (assuming those 2 are this one and the error handler) | |
# [ATTRIBUTION] bash array looping from: http://www.cyberciti.biz/faq/bash-for-loop-array/ | |
ARRLENGTH=${#BASH_SOURCE[@]} | |
for ((i=2; i < $ARRLENGTH; i++)); do | |
echoerr "\t${BASH_SOURCE[$i]}:${BASH_LINENO[$i]} at ${FUNCNAME[$i]}()" | |
done | |
} | |
################################################################################ | |
# | |
# SELF EXECUTE | |
# | |
################################################################################ | |
#_mainWrapper $@ | |
_provision_vagrant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment