PROXY Einstellung für apt, git und npm ein- und ausschalten.

Um unter Debian in wechselnden Umgebungen die Proxy-Unterstützung möglichst unkompliziert ein- bzw. ausschalten zu können, habe ich mir für apt (proxy-apt.sh), git (proxy-git.sh) und npm (proxy-npm.sh) Skripte erstellt.

Aufgerufen werden die Skripte dann jeweils mit der Option on oder off. Im Skript ist jeweils die Variable PROXY_URL an die jeweilige Umgebung anzupassen.

Beispiele:

sh ./proxy-apt.sh on
sh ./proxy-git.sh on
sh ./proxy-npm.sh on

APT : proxy-apt.sh

#!/bin/sh
# Enable or disable proxy support for apt.
# Usage: ./proxy-apt.sh on|off
#
PROXY_URL=http://proxy.company-network.lan:8080
APT_CONFIGFILE_PROXY=/etc/apt/apt.conf.d/02-proxy
#
echo APT proxy support script.
#
case "$1" in 
    [Oo][Nn])
    echo Enabling proxy for ${PROXY_URL}.
        cat >${APT_CONFIGFILE_PROXY} <<EOT
# Set proxy server for apt
Acquire::http::proxy "${PROXY_URL}";
Acquire::https::proxy "${PROXY_URL}";
EOT
    ;;

    [Oo][Ff][Ff])
    echo Disabling proxy support.
    [ -e "${APT_CONFIGFILE_PROXY}" ] && rm "${APT_CONFIGFILE_PROXY}" 
    ;;

    *)
    echo Please supply argument ON or OFF to turn proxy support on or off.
    echo Usage: $0 "ON|OFF"
    echo Example: $0 ON
    ;;

esac
#

GIT : proxy-git.sh

#!/bin/sh
# Enable or disable proxy support for git.
# Usage: ./proxy-git.sh on|off
#
PROXY_URL=http://proxy.company-network.lan:8080
#
echo GIT proxy support script.
# git config --global --get http.proxy
#
case "$1" in 
    [Oo][Nn])
    echo Enabling proxy for ${PROXY_URL}.
    git config --global http.proxy ${PROXY_URL}
    git config --global https.proxy ${PROXY_URL}
    ;;

    [Oo][Ff][Ff])
    echo Disabling proxy support.
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    ;;

    *)
    echo Please supply argument ON or OFF to turn proxy support on or off.
    echo Usage: $0 "ON|OFF"
    echo Example: $0 ON
    ;;

esac
#

NPM : proxy-npm.sh

#!/bin/sh
# Enable or disable proxy support for npm.
# Usage: ./proxy-npm.sh on|off
#
PROXY_URL=http://proxy.company-network.lan:8080
#
echo NPM proxy support script.
#
case "$1" in 
    [Oo][Nn])
	echo Enabling proxy for ${PROXY_URL}.
	npm config set proxy ${PROXY_URL}
	npm config set https-proxy ${PROXY_URL}
	;;

    [Oo][Ff][Ff])
	echo Disabling proxy support.
	npm config delete proxy
	npm config delete https-proxy
	;;

    *)
	echo Please supply argument ON or OFF to turn proxy support on or off.
	echo Usage: $0 "ON|OFF"
	echo Example: $0 ON
	;;

esac
#

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.