Skip to content

Instantly share code, notes, and snippets.

@Mischi
Last active September 25, 2015 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Mischi/e9c76211c3f12b92a2ad to your computer and use it in GitHub Desktop.
Save Mischi/e9c76211c3f12b92a2ad to your computer and use it in GitHub Desktop.
shell script to setup a new wordpress project environment based on bedrock/sage starter theme
#!/bin/sh
#
# Copyright (c) 2015 Fabian Raetz <fabian.raetz@gmail.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
set -e
set -x
scriptdir=$(dirname $0)
projectdir=$scriptdir/..
projectname=$(basename -- "$(dirname -- "$scriptdir")")
setup_trellis_deps() {
ansibledir=$projectdir/ansible
if [ -d "$ansibledir" ]; then
cd $ansibledir
ansible-galaxy install -r requirements.yml -p vendor/roles
cd -
fi
}
setup_theme_deps() {
themedir=$projectdir/site/web/app/themes/$projectname
if [ -d "$themedir" ]; then
cd $themedir
npm install
bower install
gulp
cd -
fi
}
setup_trellis_deps
setup_theme_deps
#!/bin/sh
#
# Copyright (c) 2015 Fabian Raetz <fabian.raetz@gmail.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
set -e
#set -x
#TODO
#npm -g install npm@latest gulp bower
#!/bin/sh
#
# Copyright (c) 2015 Fabian Raetz <fabian.raetz@gmail.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
set -e
set -x
# folder where this script is located
scriptroot=$(dirname $0)
usage() {
echo "usage: ${0##*/} [-Aghlst] projectname"
cat <<EOF
options:
-A setup Sage & Soil, Bedrock, Trellis and initialize git.
-g initialize git repostitory.
-h show help / usage.
-l use latest version of dependencies instead of latest release.
-s setup Sage theme and Soil plugin.
-t setup Trellis
See https://roots.io for more informations!
EOF
exit 0
}
fTrellis=false
fGit=false
fLatest=false
fSage=false
while getopts "Aghlst" OPT; do
case $OPT in
A)
fGit=true
fSage=true
fTrellis=true
;;
g)
fGit=true
;;
h)
usage
;;
l)
fLatest=true
;;
s)
fSage=true
;;
t)
fTrellis=true
;;
*)
usage
;;
esac
done
shift $(($OPTIND - 1))
# ensure that a projectname is provided
[ $# -ne 1 ] && usage
projectdir=$1
projectname=$(basename $1)
setup() {
mkdir -p $projectdir
}
# clone repo and remove .git folder
# save latest commitid in $projectdir
clone_git_repo() {
local verfile=$projectdir/ROOTSVERSIONS.md
local lastrelease=master
local src=$1
local dest=$2
git clone $src $dest
# checkout last release
if ! $fLatest; then
lastrelease=$(git -C $dest tag | tail -1)
git -C $dest checkout -b $lastrelease
fi
echo "=== $src ($lastrelease)" >> $verfile
git -C $dest log --abbrev-commit --pretty=oneline | head -1 >> $verfile
echo >> $verfile
rm -rf $dest/.git
}
setup_bedrock() {
echo "setting up bedrock:"
clone_git_repo https://github.com/roots/bedrock.git \
$projectdir/site
}
setup_trellis() {
echo "setting up trellis:"
local devconf=$projectdir/ansible/group_vars/development/wordpress_sites.yml
clone_git_repo https://github.com/roots/trellis.git \
$projectdir/ansible
# TODO: merge with below
local name=$(echo $projectname | sed -r 's/(.*)\..*/\1/')
sed -e "s/example\.com/$projectname/g" -e "s/example/$name/g" \
$devconf > $devconf-new
mv $devconf-new $devconf
}
setup_theme() {
echo "setting up theme \"$projectname\" (based on sage):"
local themedir=$projectdir/site/web/app/themes/$projectname
local assetmanifest=$themedir/assets/manifest.json
clone_git_repo https://github.com/roots/sage.git $themedir
# TODO: merge with above
local name=$(echo $projectname | sed -r 's/(.*)\..*/\1/')
sed -e "s/example/$name/g" $assetmanifest> $assetmanifest-new
mv $assetmanifest-new $assetmanifest
setup_soil
}
setup_soil() {
# TODO: remmove hardcoded version
cd $projectdir/site
composer require roots/soil 3.5.0
#wp plugin active
cd -
}
setup_git() {
echo "setting up git:"
git -C $projectdir init
git -C $projectdir add .
git -C $projectdir commit -m "Initial commmit of \"$projectname\""
}
copy_setup_scripts() {
echo "copying setup scripts:"
local setupdir=$projectdir/setup
mkdir $setupdir
cp $scriptroot/setup-project-dependencies.sh $setupdir/
}
setup
setup_bedrock
$fTrellis && setup_trellis
$fSage && setup_theme
copy_setup_scripts
$fGit && setup_git
$projectdir/setup/setup-project-dependencies.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment