Skip to content

Instantly share code, notes, and snippets.

@m1ch4ls
Created February 26, 2015 13:12
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 m1ch4ls/0f5444a8f2d1e06693a4 to your computer and use it in GitHub Desktop.
Save m1ch4ls/0f5444a8f2d1e06693a4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
alias ls=/bin/ls
function cleanup() {
rm -f /tmp/$$
}
function die() {
echo $1;
exit 1;
}
trap cleanup SIGINT SIGTERM EXIT
[ -w "$DIR/proxies-enabled" ] || die "Permissions denied! Try sudo or login as root."
for proxy in `ls -1 $DIR/proxies-available/`; do
echo -n " $proxy \"\" "
if [ -e "$DIR/proxies-enabled/$proxy" ]; then
echo -n "on"
else
echo -n "off"
fi
done | xargs -0 -I '{}' echo --checklist \"Enable\/disable proxies\" 30 40 20 {} | xargs whiptail 2> /tmp/$$
[ $? != "0" ] && (echo "Configuration not changed."; exit 0)
enabled_proxies=`cat /tmp/$$`
if [[ ! -z "$enabled_proxies" ]]; then
pushd "$DIR/proxies-enabled" > /dev/null
for ep in $enabled_proxies; do
ep=`echo $ep | sed "s/^\([\"']\)\(.*\)\1\$/\2/g"`
[ -L $ep ] || ln -s ../proxies-available/$ep $ep
done
for proxy in `ls -1 $DIR/proxies-enabled`; do
if [ -L $proxy ] && [[ ! "$enabled_proxies" =~ "\"$proxy\"" ]]; then
rm -f $proxy 2> /dev/null
fi
done
popd > /dev/null
echo "Proxy configuration changed, please restart nginx"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment