diff options
author | Jesús <heckyel@hyperbola.info> | 2021-02-10 13:52:52 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-02-10 13:52:52 -0500 |
commit | 7e95c3b667a1b353f8275db886203f272bfcce34 (patch) | |
tree | aefe3b7db69ac78b83b79a70cf43401679812d20 /hyperterm/tools/proxy.sh | |
download | hyperterm-7e95c3b667a1b353f8275db886203f272bfcce34.tar.lz hyperterm-7e95c3b667a1b353f8275db886203f272bfcce34.tar.xz hyperterm-7e95c3b667a1b353f8275db886203f272bfcce34.zip |
first commit
Diffstat (limited to 'hyperterm/tools/proxy.sh')
-rw-r--r-- | hyperterm/tools/proxy.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/hyperterm/tools/proxy.sh b/hyperterm/tools/proxy.sh new file mode 100644 index 0000000..08b4da1 --- /dev/null +++ b/hyperterm/tools/proxy.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +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') + value=$("$@") + if [[ $valid != "$value" ]]; then + >&2 echo "Invalid address" + return 1 + fi + + export http_proxy="http://$1/" + export https_proxy=$http_proxy + export ftp_proxy=$http_proxy + export rsync_proxy=$http_proxy + echo "Proxy environment variable set." + return 0 + fi + + echo -n "username: "; read -r username + if [[ $username != "" ]]; then + echo -n "password: " + read -esr password + local pre="$username:$password@" + fi + + echo -n "server: "; read -r server + echo -n "port: "; read -r port + export http_proxy="http://$pre$server:$port/" + export https_proxy=$http_proxy + export ftp_proxy=$http_proxy + export rsync_proxy=$http_proxy + export HTTP_PROXY=$http_proxy + export HTTPS_PROXY=$http_proxy + export FTP_PROXY=$http_proxy + export RSYNC_PROXY=$http_proxy +} + +function proxy_off(){ + unset http_proxy + unset https_proxy + unset ftp_proxy + unset rsync_proxy + echo -e "Proxy environment variable removed." +} |