#!/bin/bash

 PROXY_CONF_ENABLED="/etc/profile.d/proxy.sh"
PROXY_CONF_DISABLED="/etc/profile.d/proxy.sh.disable"



if [[ "$1" != "" ]]
then
    if [[ ""$1 = "-h" ]] || [[ "$1" = "--help" ]]
    then
        echo "usage: proxy_set [-h | --help] | [-e | --enable] | [-d | --disable]"
        exit 0
    fi

    
    if [[ "$1" = "-e" ]] || [[ "$1" = "--enable" ]]
    then
        if [[ -f "${PROXY_CONF_ENABLED}" ]]
        then
            echo "Proxy allready enabled"
            exit 0
        else
            if [[ -f "${PROXY_CONF_DISABLED}" ]]
            then
                mv "${PROXY_CONF_DISABLED}" "${PROXY_CONF_ENABLED}"
            else
                echo "Proxy not found"
                exit 1
            fi
        fi
    else 
        if [[ "$1" = "-d" ]] || [[ "$1" = "--disable" ]]
        then
            if [[ -f "${PROXY_CONF_DISABLED}" ]]
            then
                echo "Proxy allready disabled"
                exit 0
            else
                if [[ -f "${PROXY_CONF_ENABLED}" ]]
                then
                    mv "${PROXY_CONF_ENABLED}" "${PROXY_CONF_DISABLED}"
                else
                    echo "Proxy not found"
                    exit 1
                fi
            fi
        else
            echo "unknonw option: [$1]"
            exit 1
        fi
    fi
fi


if [[ -f "${PROXY_CONF_ENABLED}" ]]
then
    echo "Proxy enabled"
else
    if [[ -f "${PROXY_CONF_DISABLED}" ]]
    then
        echo "Proxy disabled"            
    else
        echo "Proxy not found"
        exit 1
    fi
fi

exit 0
