Skip to content

Instantly share code, notes, and snippets.

@emerleite
Created July 19, 2010 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emerleite/481665 to your computer and use it in GitHub Desktop.
Save emerleite/481665 to your computer and use it in GitHub Desktop.
#!/bin/bash
### BEGIN INFO
# Provides: OSX Apache configuration Clone
# Author: Emerson Macedo - http://github.com/emerleite - http://codificando.com
# Description: Clones apache configuration into new one. Works only on OSX
### END INFO
echo ""
if [ $# -lt 3 ]
then
echo "Usuage: sudo ./osx-clone-apache.sh newconfiguration old_listen new_listen
newconfiguration Ex: http-clone (creates /etc/http-clone/)
old_listen Old http Listen. Ex: 127.0.0.1:80
new_listen New http Listen. Ex: 127.0.0.2:80"
echo ""
exit 1
fi
NEW_HTTP_CONFIG_NAME=$1
OLD_APACHE_LISTEN_CONFIG=$2
NEW_APACHE_LISTEN_CONFIG=$3
if [ -d "/etc/${NEW_HTTP_CONFIG_NAME}" ]
then
echo "Configuration ${NEW_HTTP_CONFIG_NAME} alread exists. Choose another one"
echo ""
exit 1
fi
echo "Clonning your OSX Apache configuration to /etc/${NEW_HTTP_CONFIG_NAME}"
sudo cp -r /etc/apache2 /etc/$NEW_HTTP_CONFIG_NAME
sudo rm -fr /etc/$NEW_HTTP_CONFIG_NAME/other/*
sudo rm -fr /etc/$NEW_HTTP_CONFIG_NAME/passenger_pane_vhosts/*
cd /etc/$NEW_HTTP_CONFIG_NAME
echo "Changing Listen Ip address from ${OLD_APACHE_LISTEN_CONFIG} to ${NEW_APACHE_LISTEN_CONFIG}"
grep "$OLD_APACHE_LISTEN_CONFIG" -r * | cut -d: -f1| uniq | sudo xargs sed -i '' "s,${OLD_APACHE_LISTEN_CONFIG},${NEW_APACHE_LISTEN_CONFIG},g"
echo "Changing paths to new configuration"
grep '/apache2/' -r * | cut -d: -f1| uniq | sudo xargs sed -i '' -E "s,([^libexec].)/apache2/,\1/${NEW_HTTP_CONFIG_NAME}/,g"
echo "Changing Pid and Lock paths"
grep '\.pid' -r * | cut -d: -f1| uniq | sudo xargs sed -i '' "s,.pid,-${NEW_HTTP_CONFIG_NAME}.pid,g"
grep '\.lock' -r * | cut -d: -f1| uniq | sudo xargs sed -i '' "s,.lock,-${NEW_HTTP_CONFIG_NAME}.lock,g"
echo "Creating log dir - /var/log/${NEW_HTTP_CONFIG_NAME}/"
if [ -d "/var/log/${NEW_HTTP_CONFIG_NAME}" ]
then
echo "Log dir already exists. Keeping"
else
sudo mkdir /var/log/$NEW_HTTP_CONFIG_NAME/
sudo chmod a+w /var/log/$NEW_HTTP_CONFIG_NAME/
fi
echo "Done !!!"
cd -
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment