Skip to content

Instantly share code, notes, and snippets.

@marcus-crane
Created October 28, 2020 20:34
Show Gist options
  • Save marcus-crane/1f0f3470b17b516881a5cf6a6cb8d71c to your computer and use it in GitHub Desktop.
Save marcus-crane/1f0f3470b17b516881a5cf6a6cb8d71c to your computer and use it in GitHub Desktop.
A couple of shell scripts for toggling on and off an enterprise proxy
#!/bin/zsh
proxy_host="<ip>:<port>"
proxy_state="$HOME/.proxy"
proxy_script="$HOME/dotfiles/work/proxy.sh"
if [[ ! -f $HOME/.proxy ]]; then
echo "No proxy state file found."
echo "Now creating with default state of 'on'"
echo "on" > $HOME/.proxy
fi
if [[ -f $HOME/.proxy ]]; then
while read -r proxy_status
do
if [[ $proxy_status == "on" ]]; then
if [[ $(scselect | grep Daimler | grep \*) == "" ]]; then
scselect "<Network>" > /dev/null
echo "Changing to <Network> network..."
fi
echo "proxy = $proxy_host" > "$HOME/.curlrc"
echo "use_proxy = yes\nhttp_proxy = $proxy_host\nhttps_proxy = $proxy_host" > "$HOME/.wgetrc"
export HTTP_PROXY=$proxy_host
export HTTPS_PROXY=$proxy_host
fi
if [[ $proxy_status == "off" ]]; then
if [[ $(scselect | grep Home | grep \*) == "" ]]; then
scselect "Home" > /dev/null
echo "Changing to Home network..."
fi
rm "$HOME/.curlrc" &> /dev/null
rm "$HOME/.wgetrc" &> /dev/null
unset HTTP_PROXY
unset HTTPS_PROXY
fi
done <"$HOME/.proxy"
fi
function ptg() {
if [[ -f $HOME/.proxy ]]; then
while read -r proxy_status
do
if [[ $proxy_status == "on" ]]; then
echo "off" > "$proxy_state"
fi
if [[ $proxy_status == "off" ]]; then
echo "on" > "$proxy_state"
fi
source "$proxy_script"
done <"$proxy_state"
else
echo "No proxy status file has been configured"
fi
}
function pst() {
cat "$proxy_state"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment