Created
July 8, 2013 01:29
-
-
Save kelseyhightower/5945648 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
declare -r NEW_SITE_IP="162.209.67.97" | |
declare -r OLD_SITE_IP="96.126.112.51" | |
declare -r HOST_FILE="/etc/hosts" | |
declare -r SITE=$1 | |
function report_current_site() { | |
grep -q "" $HOST_FILE | |
if [ $? != 0 ]; then | |
echo "No entries for puppetlabs.com found in ${HOST_FILE}" | |
exit 0 | |
fi | |
grep -q $NEW_SITE_IP $HOST_FILE | |
if [ $? == 0 ]; then | |
echo "Currently pointing to the new site ${NEW_SITE_IP}" | |
fi | |
grep -q $OLD_SITE_IP $HOST_FILE | |
if [ $? == 0 ]; then | |
echo "Currently pointing to the old site ${OLD_SITE_IP}" | |
fi | |
exit 0 | |
} | |
function remove_current_site_entires() { | |
sed -ie '/162.209.67.97 www.puppetlabs.com puppetlabs.com/d' $HOST_FILE | |
sed -ie '/96.126.112.51 www.puppetlabs.com puppetlabs.com/d' $HOST_FILE | |
} | |
function add_site_entry() { | |
remove_current_site_entires | |
if [ $SITE = "new" ]; then | |
echo "Pointing puppetlabs.com to the new site" | |
echo "${NEW_SITE_IP} www.puppetlabs.com puppetlabs.com" >> $HOST_FILE | |
fi | |
if [ $SITE = "old" ]; then | |
echo "Pointing puppetlabs.com to the old site" | |
echo "${OLD_SITE_IP} www.puppetlabs.com puppetlabs.com" >> $HOST_FILE | |
fi | |
exit 0 | |
} | |
if [ $# -ne 1 ]; then | |
echo "Usage: " | |
echo " $0 new" | |
echo " $0 old" | |
echo " $0 check" | |
echo " $0 clean" | |
exit 65 | |
fi | |
if [ $1 = "check" ]; then | |
report_current_site | |
fi | |
if [ $1 = "clean" ]; then | |
remove_current_site_entires | |
fi | |
add_site_entry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment