setup-proxy.in 1.07 KB
Newer Older
1 2 3 4 5
#!/bin/sh

PREFIX=
. "$PREFIX/lib/libalpine.sh"

Natanael Copa's avatar
Natanael Copa committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

usage() {
	cat <<__EOF__
usage: setup-proxy [-hq] [PROXYURL]

Setup http proxy

options:
 -h  Show this help
 -q  Quiet mode

If PROXYURL is not specified user will be prompted.
__EOF__
        exit 1
}



while getopts "hq" opt; do
	case "$opt" in
	q) quiet=1;;
	h) usage;;
	esac
done

shift $(( $OPTIND - 1))

proxyurl="$1"

35 36 37
PROFILE="$ROOT/etc/profile.d/proxy.sh"

if [ -f "$PROFILE" ] ; then
Natanael Copa's avatar
Natanael Copa committed
38
	. $PROFILE
39 40
fi

Natanael Copa's avatar
Natanael Copa committed
41 42 43 44 45 46 47 48 49
suggest=${http_proxy:-none}
while true; do
	case "$proxyurl" in
		http://*) break;;
		none) proxyurl= ; break;;
	esac
	echon "HTTP/FTP proxy URL? (e.g. 'http://proxy:8080', or 'none') [$suggest] "
	default_read proxyurl $suggest
done
50

Natanael Copa's avatar
Natanael Copa committed
51 52
if [ -z "$proxyurl" ]; then
	rm -f "$PROFILE"
53
else
Natanael Copa's avatar
Natanael Copa committed
54 55 56 57 58 59 60
	cat >"$PROFILE" <<__EOF__
# this file was generated with and might get overwritten by setup-proxy

export http_proxy=$proxyurl
export https_proxy=$proxyurl
export ftp_proxy=$proxyurl
__EOF__
61 62
fi

Natanael Copa's avatar
Natanael Copa committed
63 64 65 66
[ -e "$PROFILE" ] || exit 1

if [ -z "$quiet" ]; then
	echo -e "\nTo make changes active please do login again or source $PROFILE\nwith \". $PROFILE\""
67 68
fi