Created
September 19, 2011 19:40
-
-
Save bencates/1227370 to your computer and use it in GitHub Desktop.
Blue Acorn staging site setup 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
#!/usr/bin/env bash | |
### | |
# Blue Acorn staging site setup script | |
# v0.1 | |
# by Ben Cates | |
### | |
domain='local' | |
server='mamp' | |
while getopts b:d:hv opt; do | |
case "$opt" in | |
b) branch=$OPTARG; shift;; | |
h) showHelp=1; break;; | |
d) domain=$OPTARG; shift;; | |
v) echo 'version 0.1'; exit 0;; | |
r) rsync=$OPTARG; shift;; | |
s) server=$OPTARG; shift;; | |
esac | |
done | |
if [[ $# -lt 1 ]]; then | |
showHelp=1 | |
fi | |
if [[ $showHelp ]]; then | |
echo "Usage: basetup [-bdhv]" | |
echo " -b branch Checkout a specific git branch" | |
echo " -d domain Create the local site with a specified domain. Defaults to local" | |
echo " -h Show this help screen" | |
echo " -v Shows the program version" | |
exit 2 | |
fi | |
name=$1 | |
gitPath="ssh://git@192.168.1.110/home/git/git-repositories/$name-git" | |
repoLocation="$HOME/Sites/$name" | |
url="$name.$domain" | |
server='mamp' | |
#cache the sudo password | |
sudo echo 'no-op' > /dev/null | |
if [[ $verbose ]]; then | |
echo $gitPath | |
echo $repoLocation | |
fi | |
## Clone the Git repo ## | |
if [[ -d $repoLocation ]]; then | |
echo "$repoLocation already exists. Quitting." | |
exit 1 | |
fi | |
if [[ $branch ]]; then | |
git clone --branch $branch $gitPath $repoLocation | |
else | |
git clone $gitPath $repoLocation | |
fi | |
## Rsync the staging site on top of it ## | |
if [[ $rsync ]]; then | |
echo "rsyncing not implemented yet" | |
fi | |
## Add entries to /etc/hosts and the apache conf | |
if ! grep -iq $url /etc/hosts; then | |
echo "127.0.0.1 $url" | sudo tee -a /etc/hosts > /dev/null | |
fi | |
## Edit local core files and ignore changes | |
# switch .dev to .local | |
sed -i .bak -e "s/return \$this->_baseUrlCache\[\$cacheKey\];/return str_replace('.dev', '.local', \$->this_baseUrlCache[\$cacheKey]);/" \ | |
"$repoLocation/app/code/core/Mage/Core/Model/Store.php" > /dev/null | |
if [[ $? -eq 0 ]]; then rm "$repoLocation/app/code/core/Mage/Core/Model/Store.php.bak"; fi | |
# re-enable console on nonfirefox browsers | |
sed -i .bak -e '/^if\(.*console.*\)/, /^}$/ s/.*/\/\/ &/' "$repoLocation/js/varien/js.js" > /dev/null | |
if [[ $? -eq 0 ]]; then rm "$repoLocation/js/varien/js.js.bak"; fi | |
#FIXME git ignore changes | |
## Configure and restart server | |
case "$server" in | |
mamp|*) serverFile="/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf";; | |
esac | |
if ! grep -iq $url $serverFile; then | |
vhost=" | |
<VirtualHost *:80> | |
DocumentRoot \"$repoLocation\" | |
ServerName $url | |
<Directory /> | |
Options -Indexes FollowSymLinks | |
AllowOverride all | |
Order allow,deny | |
Allow from all | |
</Directory> | |
</VirtualHost>" | |
echo "$vhost" | tee -a $serverFile > /dev/null | |
fi | |
case "$server" in | |
mamp|*) | |
sudo /Applications/MAMP/bin/stopApache.sh \ | |
sudo /Applications/MAMP/bin/startApache.sh | |
;; | |
esac | |
echo "$name has been successfully cloned into $repoLocation!" | |
echo "You may still need to edit app/etc/local.xml" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment