commit dcf261e6227f8df7b26cef3c56e7542bf11d432f Author: leafee98 Date: Thu Sep 14 11:47:43 2023 +0800 Finish the logic diff --git a/proxyenv b/proxyenv new file mode 100755 index 0000000..b610357 --- /dev/null +++ b/proxyenv @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +if [[ -z "$PROXYENV_CONFPATH" ]] ; then + if [[ -e "/etc/proxyenv.conf" ]] ; then + source "/etc/proxyenv.conf" + else + echo "custom configuration location '/etc/proxyenv.conf' not exists" >&2 + echo "exiting...' + exit 1 + fi +else + if [[ -e "$PROXYENV_CONFPATH" ]] ; then + source "$PROXYENV_CONFPATH" + else + echo "custom configuration location '$PROXYENV_CONFPATH' not exists" >&2 + echo "exiting...' + exit 1 + fi +fi + +if [[ -z "$PROXYENV_TARGET_PROXY" ]] ; then + echo "cannot find PROXYENV_TARGET_PROXY" >&2 + echo "exiting...' + exit 1 +fi + +export PROXY="$PROXYENV_TARGET_PROXY" +export HTTP_PROXY="$PROXYENV_TARGET_PROXY" +export HTTPS_PROXY="$PROXYENV_TARGET_PROXY" + +export proxy="$PROXYENV_TARGET_PROXY" +export http_proxy="$PROXYENV_TARGET_PROXY" +export https_proxy="$PROXYENV_TARGET_PROXY" + +export NOPROXY="$PROXYENV_NOPROXY" + +exec "$@" diff --git a/proxyenv.conf b/proxyenv.conf new file mode 100644 index 0000000..307230e --- /dev/null +++ b/proxyenv.conf @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# the HTTP_PROXY and other environments variable's final value +PROXYENV_TARGET_PROXY="http://localhost:8888" + +# the NOPROXY variable's final value +PROXYENV_NOPROXY="localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8"