jaedb
7/25/2013 - 4:26 AM

Compile a fresh version of the latest stable SilverStripe. Use install switch to include silverstripe-installer repository.Usage: ./compile.

Compile a fresh version of the latest stable SilverStripe. Use install switch to include silverstripe-installer repository.Usage: ./compile.sh [install]

#!/bin/bash

# Colors
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"


echo
echo -e $COL_CYAN SilverStripe environment compiler v1.3 $COL_RESET
echo -e $COL_CYAN -------------------------------------- $COL_RESET
echo

# Installer
case "$1" in 'install')
	echo -e " Detected install switch, including installer..."
	echo 
	echo -e $COL_BLUE === Installer === $COL_RESET
	git clone git@github.com:silverstripe/silverstripe-installer.git ./install
	
	echo -ne Moving install files into root...
	mv ./install/* ./
	mv ./install/.htaccess ./.htaccess
	echo -e $COL_GREEN done$COL_RESET
	
	echo -ne Removing installer folder...
	rm -rf ./install
	echo -e $COL_GREEN done$COL_RESET	
	echo
	
	echo -e $COL_BLUE === Readme file === $COL_RESET
	echo -ne Fetching readme file...
	curl -s https://gist.github.com/jaedb/8307093/raw > ./README.md 
	echo -e $COL_GREEN done$COL_RESET	
	echo
;;
esac


######## Environment Configuration ########

echo -e $COL_BLUE === _ss_environment file === $COL_RESET

if [ ! -d "mysite" ]; then
	echo -ne " mysite folder does not exist, creating now..."
	mkdir mysite
	echo -e $COL_GREEN done$COL_RESET
else
	echo -e " mysite folder exists, not creating$COL_GREEN ok$COL_RESET"
fi

if [ -f "./_ss_environment.php" ]; then
	echo -e " _ss_environment.php file found, not fetching"
else
	echo -ne " _ss_environment.php not found, fetching now..."
	curl -s https://gist.githubusercontent.com/jaedb/448ddfa9ad9a831838ed/raw > ./_ss_environment.php
	echo -e $COL_GREEN done$COL_RESET
fi
echo


######## SQL dump folder ########

echo -e $COL_BLUE === sql folder === $COL_RESET

## directory exists, cannot clone
if [ -d "SQL" ]; then
	echo -e " SQL folder found, not creating$COL_GREEN ok$COL_RESET"

## if directory not found, then clone em
else
	echo -ne " SQL folder not found, creating now..."
	mkdir SQL
	echo -e $COL_GREEN done$COL_RESET
fi

if [ -e SQL/.htaccess ]; then
	echo -e " SQL/.htaccess file found, not creating$COL_GREEN ok$COL_RESET"
else
	echo -ne " SQL/.htaccess file not found, creating now..."
	echo "Order deny,allow" >> SQL/.htaccess
	echo "Deny from all" >> SQL/.htaccess
	echo -e $COL_GREEN done$COL_RESET
fi

echo -ne " Recursively setting SQL folder permissions to 777..."
chmod 777 SQL -R
echo -e $COL_GREEN done$COL_RESET
echo



######## Assets folder ########

echo -e $COL_BLUE === assets folder === $COL_RESET
if [ -d "assets" ]; then
	echo -e " assets folder found, not creating$COL_GREEN ok$COL_RESET"
else
	echo -ne " assets folder not found, creating now..."
	mkdir assets
	echo -e $COL_GREEN done$COL_RESET
fi

echo -ne " Recursively setting assets folder permissions to 777..."
chmod 777 assets -R
echo -e $COL_GREEN done$COL_RESET
echo


######## DMS Assets folder ########

echo -e $COL_BLUE === dms-assets folder === $COL_RESET
if [ -d "dms-assets" ]; then
	echo -e " dms-assets folder found, not creating$COL_GREEN ok$COL_RESET"
else
	echo -ne " dms-assets folder not found, creating now..."
	mkdir dms-assets
	echo -e $COL_GREEN done$COL_RESET
fi

echo -ne " Recursively setting dms-assets folder permissions to 777..."
chmod 777 dms-assets -R
echo -e $COL_GREEN done$COL_RESET
echo


######## Silverstripe Cache folder ########

echo -e $COL_BLUE === silverstripe-cache folder === $COL_RESET
if [ -d "silverstripe-cache" ]; then
	echo -e " silverstripe-cache folder found, not creating$COL_GREEN ok$COL_RESET"
else
	echo -ne " silverstripe-cache folder not found, creating now..."
	mkdir silverstripe-cache
	echo -e $COL_GREEN done$COL_RESET
fi

echo -ne " Recursively setting silverstripe-cache folder permissions to 777..."
chmod 777 silverstripe-cache -R
echo -e $COL_GREEN done$COL_RESET
echo



######## Silverstripe Cache folder ########

echo -e $COL_BLUE === .gitignore file === $COL_RESET

if [ -f ".gitignore" ]; then
	echo -e " .gitignore found, not fetching$COL_GREEN ok$COL_RESET" 
else
	echo -ne " .gitignore file not found, fetching now..." 
	curl -s https://gist.githubusercontent.com/jaedb/6384933/raw > ./.gitignore
	echo -e $COL_GREEN done$COL_RESET
fi
echo



######## Default dependencies ########

echo -e $COL_CYAN PROJECT DEPENDENCIES $COL_RESET

if [ -f "compile-dependencies.txt" ]; then
	echo -e " compile-dependencies.txt exists, not fetching the default set$COL_GREEN ok$COL_RESET" 
else
	echo -e " compile-dependencies.txt file not found, we will use default set. Constructing now..." 	
	
	echo "SilverStripe Framework;git@github.com:silverstripe/silverstripe-framework.git;framework" >> compile-dependencies.txt
	echo -ne " adding SilverStripe Framework..."
	echo -e "$COL_GREEN done$COL_RESET"
	
	echo "SilverStripe CMS;git@github.com:silverstripe/silverstripe-cms.git;cms" >> compile-dependencies.txt
	echo -ne " adding SilverStripe CMS..."
	echo -e "$COL_GREEN done$COL_RESET"
	
	echo "Userforms;git@github.com:silverstripe/silverstripe-userforms.git;userforms" >> compile-dependencies.txt
	echo -ne " adding Userforms..."
	echo -e "$COL_GREEN done$COL_RESET"
	
	echo "Sortable Gridfield;git@github.com:UndefinedOffset/SortableGridField.git;sortablegridfield" >> compile-dependencies.txt
	echo -ne " adding Sortable Gridfield..."
	echo -e "$COL_GREEN done$COL_RESET"
	
	echo "Gridfield Extensions;git@github.com:silverstripe-australia/silverstripe-gridfieldextensions.git;gridfieldextensions" >> compile-dependencies.txt
	echo -ne " adding Gridfield Extensions..."
	echo -e "$COL_GREEN done$COL_RESET"
	
	echo "BetterButtons;git@github.com:unclecheese/silverstripe-gridfield-betterbuttons.git;betterbuttons" >> compile-dependencies.txt
	echo -ne " adding BetterButtons..."
	echo -e "$COL_GREEN done$COL_RESET"
	
	echo "Emulate User;git@github.com:jaedb/silverstripe-emulateuser.git;emulate-user" >> compile-dependencies.txt
	echo -ne " adding Emulate User..."
	echo -e "$COL_GREEN done$COL_RESET"
fi

DEPENDENCIES_COUNT=`cat compile-dependencies.txt | wc -l`
echo -e " $DEPENDENCIES_COUNT dependencies detected"
echo 

## LOOP THROUGH DEPENDENCIES
while read i; do
	
	NAME=`echo $i| cut -d';' -f 1`
	REPO=`echo $i| cut -d';' -f 2`
	DIR=`echo $i| cut -d';' -f 3`
	
	COMMAND="git clone "
	COMMAND+=$REPO
	COMMAND+=" $DIR"
	
	echo -e $COL_BLUE DEPENDENCY: $NAME$COL_RESET
	
	## directory exists, cannot clone
	if [ -e $DIR ]; then
		echo -e "$COL_YELLOW warning$COL_RESET $DIR folder already exists, cannot clone into existing folder" 
	
	## if directory not found, then clone em
	else
		echo -e " Cloning repository now..." 
		eval $COMMAND
		echo -e $COL_GREEN done$COL_RESET
	fi
echo
	
done < "compile-dependencies.txt"

echo -e " Missing a dependency from your dependencies file? You may be missing a blank line at the end of the file"

# Complete
echo -e $COL_CYAN COMPILE COMPLETE $COL_RESET