├── .gitignore ├── proxyenv.conf ├── PKGBUILD ├── LICENSE ├── proxyenv └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /pkg 2 | /src 3 | /proxyenv*.pkg.tar.* 4 | -------------------------------------------------------------------------------- /proxyenv.conf: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # the HTTP_PROXY and other environments variable's final value 4 | PROXYENV_TARGET_PROXY="http://localhost:8888" 5 | 6 | # the NOPROXY variable's final value 7 | PROXYENV_NOPROXY="localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8" 8 | -------------------------------------------------------------------------------- /PKGBUILD: -------------------------------------------------------------------------------- 1 | pkgname='proxyenv-git' 2 | pkgver=0 3 | pkgrel=1 4 | arch=('any') 5 | url="https://git.leafee98.com/leafee98/proxyenv" 6 | pkgdesc="A cross-platform, GPU-accelerated terminal emulator" 7 | license=('MIT') 8 | depends=('bash') 9 | 10 | source=( 11 | "proxyenv" 12 | "proxyenv.conf" 13 | "LICENSE" 14 | ) 15 | 16 | sha256sums=( 17 | 'SKIP' 18 | 'SKIP' 19 | 'SKIP' 20 | ) 21 | 22 | pkgver() { 23 | git describe --tags --long | cut -c 2- | sed -e 's/-/./g' 24 | } 25 | 26 | package() { 27 | install -Dm755 "${srcdir}/proxyenv" "${pkgdir}/usr/bin/proxyenv" 28 | install -Dm644 "${srcdir}/proxyenv.conf" "${pkgdir}/etc/proxyenv.conf" 29 | install -Dm644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/proxyenv/LICENSE" 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Leafee98 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /proxyenv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Just quit queitly when no program specfied 4 | if (( "$#" == 0 )) ; then 5 | exit 0 6 | fi 7 | 8 | if [[ -z "$PROXYENV_CONFPATH" ]] ; then 9 | if [[ -e "/etc/proxyenv.conf" ]] ; then 10 | source "/etc/proxyenv.conf" 11 | else 12 | echo "custom configuration location '/etc/proxyenv.conf' not exists" >&2 13 | echo "exiting..." 14 | exit 1 15 | fi 16 | else 17 | if [[ -e "$PROXYENV_CONFPATH" ]] ; then 18 | source "$PROXYENV_CONFPATH" 19 | else 20 | echo "custom configuration location '$PROXYENV_CONFPATH' not exists" >&2 21 | echo "exiting..." 22 | exit 1 23 | fi 24 | fi 25 | 26 | if [[ -z "$PROXYENV_TARGET_PROXY" ]] ; then 27 | echo "cannot find PROXYENV_TARGET_PROXY" >&2 28 | echo "exiting..." 29 | exit 1 30 | fi 31 | 32 | export PROXY="$PROXYENV_TARGET_PROXY" 33 | export HTTP_PROXY="$PROXYENV_TARGET_PROXY" 34 | export HTTPS_PROXY="$PROXYENV_TARGET_PROXY" 35 | 36 | export proxy="$PROXYENV_TARGET_PROXY" 37 | export http_proxy="$PROXYENV_TARGET_PROXY" 38 | export https_proxy="$PROXYENV_TARGET_PROXY" 39 | 40 | export NOPROXY="$PROXYENV_NOPROXY" 41 | 42 | exec "$@" 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # proxyenv 2 | 3 | This program is designed to be used like proxychains, that is 4 | 5 | `proxyenv ` 6 | 7 | This program used to be a simple bash function, firsted introduced 8 | at [A shell function to set environemt for any single command (Title has been translated)](https://blog.leafee98.com/posts/%E4%B8%BA%E5%8D%95%E4%B8%80%E5%91%BD%E4%BB%A4%E8%AE%BE%E7%BD%AE%E4%BB%A3%E7%90%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E7%9A%84%E7%BB%88%E7%AB%AF%E5%87%BD%E6%95%B0/). 9 | 10 | It works most of the time, but when using other command wrappers like `sudo proxyenv cmd`, 11 | the shell function will not work anymore, because in the context of sudo, the function 12 | proxyenv is inaccessible. 13 | 14 | So I make it as an bash script, which still accessible inside any other program wrappers, 15 | that's this program. 16 | 17 | ## Usage 18 | 19 | ``` 20 | proxyenv 21 | ``` 22 | 23 | ## Configuration 24 | 25 | If environemt `PROXYENV_CONFPATH` is set, the program will use the path indicted by it to 26 | read the proxy actually to be used. Otherwise `/etc/proxyenv.conf` will be used. 27 | 28 | The configuration file (default `/etc/proxyenv.conf`) will be sourced when proxyenv run, 29 | so take care no let this file's permission to open, 755 is suggested. 30 | 31 | For entry detail of configuration file, see `proxyenv.conf` in this repository. 32 | 33 | ## Misc 34 | 35 | ### Which version to use 36 | 37 | Althought there are tags, using the code on branch `main` is always suggested. The tag 38 | was added just to let `git describe` happy, which used in `PKGBUILD` 39 | 40 | ### Install on Archlinux 41 | 42 | Since I add a PKGBUILD at the root of repository, you can use the following command 43 | to build and install this program on Archlinux. 44 | 45 | ``` 46 | makepkg 47 | pacman -U 48 | ``` 49 | --------------------------------------------------------------------------------