1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- function proxy_on() {
- export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
- if (( $# > 0 )); then
- valid=$(echo $@ | sed -n 's/\([0-9]\{1,3\}.\)\{4\}:\([0-9]\+\)/&/p')
- if [[ $valid != $@ ]]; then
- >&2 echo "Invalid address"
- return 1
- fi
- export
- http_proxy="http://$1/" \
- https_proxy=$http_proxy \
- ftp_proxy=$http_proxy \
- rsync_proxy=$http_proxy
- echo "Proxy environment variable set."
- return 0
- fi
- echo -n "username: "; read username
- if [[ $username != "" ]]; then
- echo -n "password: "
- read -es password
- local pre="$username:$password@"
- fi
- echo -n "server: "; read server
- echo -n "port: "; read port
- export http_proxy="http://$pre$server:$port/" \
- https_proxy=$http_proxy \
- ftp_proxy=$http_proxy \
- rsync_proxy=$http_proxy \
- HTTP_PROXY=$http_proxy \
- HTTPS_PROXY=$http_proxy \
- FTP_PROXY=$http_proxy \
- RSYNC_PROXY=$http_proxy
- }
- function proxy_off(){
- unset http_proxy https_proxy ftp_proxy rsync_proxy \
- HTTP_PROXY HTTPS_PROXY FTP_PROXY RSYNC_PROXY
- echo -e "Proxy environment variable removed."
- }
|