stechico
6/23/2011 - 3:50 PM

A quick script to switch between running Pow and MacPorts Apache2 on OS X

A quick script to switch between running Pow and MacPorts Apache2 on OS X

#!/bin/sh -e
#/ Usage: pow [on|off]
#/ Toggle between running Pow (http://pow.cx) and Apache on Mac OS X.

# Show Usage
function usage {
    grep '^#/' "$0" | cut -c4-
    exit 2
}
[ -z "$1" -o "$1" = "--help" ] && usage

# Fail fast if we're not on OS X
if [ "$(uname -s)" != "Darwin" ]; then
    echo "You're not on OS X, so methinks you're not running Pow." 1>&2
    exit 1
fi

toggle="$1"
case "$toggle" in
    'on')
        sudo launchctl unload /Library/LaunchDaemons/org.macports.apache2.plist
        launchctl load ~/Library/LaunchAgents/cx.pow.powd.plist &&
            launchctl list | grep pow
        ;;
    'off')
        launchctl unload ~/Library/LaunchAgents/cx.pow.powd.plist
        sudo launchctl load /Library/LaunchDaemons/org.macports.apache2.plist &&
            sudo launchctl list | grep apache
        ;;
    *)
        usage
        ;;
esac