Skip to content

Instantly share code, notes, and snippets.

@jgleal
Created July 30, 2018 08:56
Show Gist options
  • Save jgleal/6be230b348d39cfd97bf11eaaa4f11f9 to your computer and use it in GitHub Desktop.
Save jgleal/6be230b348d39cfd97bf11eaaa4f11f9 to your computer and use it in GitHub Desktop.
bash script to de/activate corporte proxy
#!/bin/bash
#configurar para que no pregunte
user=""
pass=""
srvPortProxy=""
#
#compruebo que se pase activación(1) o desactivación(0)
if [ $# -eq 0 ]
then
echo "Activo (1) o desactivo (0) el proxy?"
else
if [ $1 = 0 ]
then #desactivo proxy
#variables de entorno
if [ $0 = $BASH_SOURCE ]
then
echo "Ejecuta el script con 'source' para poder eliminar las variables de entorno"
else
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy
fi
#apt
sudo rm -f /etc/apt/apt.conf.d/80proxy
#herramientas
npm config delete proxy
git config --global --unset http.proxy
else #activo proxy
if [ -z $srvPortProxy ]
then
echo -n "Servidor:puerto proxy: "
read srvPortProxy
fi
if [ -z $user ]
then
echo -n "Usuario proxy: "
read user
fi
if [ -z $pass ]
then
echo -n "Contraseña proxy: "
read -s pass
echo ""
fi
urlProxy="http://$user:$pass@$srvPortProxy"
#variables de entorno
if [ $0 = $BASH_SOURCE ]
then
echo "Ejecuta el script con 'source' si deseas establecer variables de entorno (http_proxy, etc.)"
else
export HTTP_PROXY=$urlProxy
export HTTPS_PROXY=$urlProxy
export http_proxy=$urlProxy
export https_proxy=$urlProxy
fi
#apt
sudo rm -f /etc/apt/apt.conf.d/80proxy #me aseguro que no exista
echo "acquire::http::proxy \"$urlProxy\";" | sudo tee -a /etc/apt/apt.conf.d/80proxy > /dev/null
echo "acquire::https::proxy \"$urlProxy\";" | sudo tee -a /etc/apt/apt.conf.d/80proxy > /dev/null
#herramientas
git config --global http.proxy $urlProxy
npm config set proxy $urlProxy
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment