Created
October 18, 2019 06:10
-
-
Save rhee/5e7234191f245b95ac61490d09f45981 to your computer and use it in GitHub Desktop.
detect-pypi-apt-proxy.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat detect-pypi-apt-proxy.sh | |
set -x | |
PYPI_PROXY_PORT=$1 | |
APT_PROXY_PORT=$2 | |
HOST_IP=$(awk '/^[a-z]+[0-9]+\t00000000/ { printf("%d.%d.%d.%d\n", "0x" substr($3, 7, 2), "0x" substr($3, 5, 2), "0x" substr($3, 3, 2), "0x" substr($3, 1, 2)) }' < /proc/net/route) | |
if test -z "$HOST_IP";then echo "HOST_IP not found" 1>&2; exit 1; fi | |
mkdir -p $HOME/.config/pip && cat > $HOME/.config/pip/pip.conf <<-EOL | |
[global] | |
index-url = http://$HOST_IP:$PYPI_PROXY_PORT/root/pypi/+simple/ | |
[install] | |
trusted-host = $HOST_IP | |
EOL | |
mkdir -p /etc/apt/apt.conf.d && cat > /etc/apt/apt.conf.d/01proxy <<-EOL | |
Acquire::HTTP::Proxy "http://$HOST_IP:$APT_PROXY_PORT"; | |
Acquire::HTTPS::Proxy "false"; | |
EOL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment