Skip to content

Instantly share code, notes, and snippets.

@SimZhou
Last active January 3, 2024 13:28
Show Gist options
  • Save SimZhou/8612c013e9ddb2fe6844f6efac5a6e42 to your computer and use it in GitHub Desktop.
Save SimZhou/8612c013e9ddb2fe6844f6efac5a6e42 to your computer and use it in GitHub Desktop.
A linux shell proxy set/unset script
# Save following lines as '/usr/local/sbin/ssr-on'
# Enable proxy using command: . ssr-on
proxy_list=(
http://username:passwd@192.168.1.2:1080
http://192.168.1.11:1080
)
for proxy in ${proxy_list[@]}; do
ip_addr=$(echo $proxy | sed -re 's|^http://||g;s|.*@||g;s|:[0-9]*/?$||g')
port=$(echo $proxy | awk '{port=gensub(/.*:([0-9]{1,5})\/?/,"\\1","g",$0);print port}')
nc -vz -w 1 $ip_addr $port &> /dev/null && {
export http_proxy=$proxy HTTP_PROXY=$proxy https_proxy=$proxy HTTPS_PROXY=$proxy
git config --global http.proxy $proxy
echo "Proxy Server Set to $proxy" && return
}
done
echo "No Alive Proxy Server Found!"
# to set proxy for apt update, see:
# /etc/apt/apt.conf.d/87proxy # reference: https://askubuntu.com/a/920242/1410764
# Save following lines as '/usr/local/sbin/ssr-off'
# Disable proxy using command: . ssr-off
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
git config --global --unset http.proxy
echo "Proxy Server Dismissed!"
@SimZhou
Copy link
Author

SimZhou commented May 8, 2022

wget supports lowercase http_proxy only, and docker uses uppercase.
So it is recommended to set both upper and lower cases...
Reference: https://unix.stackexchange.com/a/212972/525088

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment