#!/bin/bash 

# This script was written Fedor Karpelevitch to reconfigure
# the lightweight "oops" proxy server to use a different
# upstream proxy, or to use no proxy at all.

UPSTREAM="$@"
CONFFILE=/etc/oops/oops.cfg


if [ "$UPSTREAM" != "stop" ]; then 
    echo "Setting upstream proxy host ($UPSTREAM)" 

    if [ "$UPSTREAM" != "none" ]; then 
        echo parent	$UPSTREAM > $CONFFILE.N
    fi
    grep -v "^parent " $CONFFILE >> $CONFFILE.N

    mv $CONFFILE.N $CONFFILE

    # echo Reconfiguring oops...
    # /usr/sbin/oopsctl reconfigure
    # echo Oops reconfigured.
    echo Restarting oops
    /etc/init.d/oops restart
    echo Restarted oops
else
    echo Stopping oops
    /etc/init.d/oops stop
fi
