Created
March 24, 2015 19:43
-
-
Save phptek/f7128fa2da3c2d1b0dc1 to your computer and use it in GitHub Desktop.
Stupid SilverStripe project creation script
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 | |
# | |
# Create a new SilverStripe project in seconds. | |
# Russell Michell <russell@silverstripe.com> | |
# | |
# TODO | |
# 1). Add support for a greater range of composer executables | |
# 2). Add support for a greater range of webservers | |
# 3). Ping the repo to ensure it isn't down | |
# SilverStripe Config | |
SSCONFIG_REPO_URL="https://gitorious.silverstripe.com" | |
IFS_OLD=$IFS | |
IFS=";" | |
# | |
# Get the DocumentRoot for Apache Httpd | |
# | |
function getDocRootHttpd { | |
DOCROOT=$( grep -s "^DocumentRoot" $1/httpd.conf | awk -F\" '{ print $2 }' ) | |
echo $DOCROOT | |
} | |
# | |
# Run some system checks | |
# | |
function runSysChecks { | |
# Check GIT | |
echo -e "Checking GIT..." | |
GIT=$( which git ) | |
if [ ! $? -eq 0 ] | |
then | |
echo -e "I can't find GIT on your system. I quit!\n" | |
exit 1 | |
fi | |
# Check Composer | |
echo -e "Checking composer..." | |
COMPOSER=$( which composer ) | |
if [ ! $? -eq 0 ] | |
then | |
echo -e "I can't find composer on your system. I quit!\n" | |
exit 1 | |
fi | |
# Check Webserver's DocumentRoot | |
echo "Checking document root..." | |
CANDIDATE_HTTPD_PATHS="/etc/apache2;/etc/httpd/conf;/usr/local/apache/conf;/usr/local/httpd/conf" | |
for DIR in $CANDIDATE_HTTPD_PATHS | |
do | |
DOCROOT=$( getDocRootHttpd $DIR ) | |
if [ ${#DOCROOT} -gt 1 ] | |
then | |
break | |
fi | |
done | |
if [ ${#DOCROOT} -lt 0 ] | |
then | |
echo -e "I'm unable to determine your webserver's document root. quit!\n" | |
exit 1 | |
fi | |
} | |
# What is the project's name? e.g. my-site.co.nz | |
if [ ${#1} -eq 0 ] | |
then | |
echo -e "I couldn't see a project name. I quit!\n" | |
exit 1 | |
else | |
FOLDER_NAME=$1 | |
fi | |
runSysChecks | |
# Is this a new project? | |
PROJ_ISNEW="0" | |
PROJ_REPO_URI="" | |
if [ ${#2} -gt 0 ] | |
then | |
PROJ_ISNEW="1" | |
else | |
# Not a new project so we expect a value for a GIT repo URI | |
if [ ${#4} -gt 0 ] | |
then | |
PROJ_REPO_URI=$4 | |
fi | |
fi | |
# Restore things to a natural state | |
IFS=$IFS_OLD | |
# If this is a new project, get the correct installer's repo URL | |
if [ ${#PROJ_ISNEW} -eq 1 ] | |
then | |
# What type of project is this? | |
if [ "$3" = "CWP" ] | |
then | |
VCS_PRJ="cwp-installer-basic" | |
VCS_URL="https://gitlab.cwp.govt.nz/cwp/$VCS_PRJ.git" | |
else | |
VCS_PRJ="silverstripe-installer" | |
VCS_URL="https://github.com/silverstripe/$VCS_PRJ.git" | |
fi | |
else | |
VCS_PRJ=$PROJ_REPO_URI | |
VCS_URL="$SSCONFIG_REPO_URL/$VCS_PRJ.git" | |
fi | |
echo "Creating project directory $FOLDER_NAME in $DOCROOT..." | |
# Create the project directory | |
PROJDIR=$DOCROOT/$FOLDER_NAME | |
if [ ! -d $PROJDIR ] | |
then | |
mkdir $PROJDIR | |
PROJPREEXISTED="0" | |
else | |
PROJPREEXISTED="1" | |
echo "Project directory $FOLDER_NAME already exists in $DOCROOT..." | |
fi | |
# Ensure the folder was actually created and didn't fail due to permissions etc | |
if [ ! -d $PROJDIR ] | |
then | |
echo "Couldn't create $PROJDIR. I quit!" | |
fi | |
# Fetch the SilverStripe repo, but only if the project doesn't already exist | |
cd $PROJDIR | |
if [ $PROJPREEXISTED -eq 0 ] | |
then | |
if [ ${#PROJ_ISNEW} -eq 1 ] | |
then | |
echo -e "Installing SilverStripe into $PROJDIR from $VCS_URL..." | |
composer --quiet install $VCS_PRJ | |
else | |
echo -e "Fetching SilverStripe project from $VCS_URL..." | |
git clone $VCS_URL . 2&> /dev/null | |
fi | |
# Check that we were really successful | |
if [ -d "./.git" ] | |
then | |
echo -e "Project fetched successfully...\n" | |
else | |
echo -e "Project fetch failed...\n" | |
fi | |
else | |
if [ -d "./.git" ] | |
then | |
echo -e "Project is already installed. Finishing.\n" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment