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

PREFIX=
4 5 6
for i in ./libalpine.sh $PREFIX/lib/libalpine.sh; do
	[ -e $i ] && . $i && break
done
7 8

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

12
		Setup http proxy
13

14 15 16
		options:
		 -h  Show this help
		 -q  Quiet mode
17

18 19
		If PROXYURL is not specified user will be prompted.
	__EOF__
20
	exit 1
21 22 23 24
}



25
while getopts "hp:q" opt; do
26 27 28
	case "$opt" in
	q) quiet=1;;
	h) usage;;
29
	p) ROOT=$OPTARG;;
30 31 32 33 34 35 36
	esac
done

shift $(( $OPTIND - 1))

proxyurl="$1"

37 38 39
PROFILE="$ROOT/etc/profile.d/proxy.sh"

if [ -f "$PROFILE" ] ; then
40
	. $PROFILE
41 42
fi

43 44 45 46 47 48
suggest=${http_proxy:-none}
while true; do
	case "$proxyurl" in
		http://*) break;;
		none) proxyurl= ; break;;
	esac
49 50
	ask "HTTP/FTP proxy URL? (e.g. 'http://proxy:8080', or 'none')" $suggest
	proxyurl=$resp
51
done
52

53 54
if [ -z "$proxyurl" ]; then
	rm -f "$PROFILE"
55
else
56
	mkdir -p "${PROFILE%/*}"
57 58
	cat >"$PROFILE" <<-__EOF__
		# this file was generated with and might get overwritten by setup-proxy
59

60 61 62 63
		export http_proxy=$proxyurl
		export https_proxy=$proxyurl
		export ftp_proxy=$proxyurl
	__EOF__
64 65
fi

66 67 68 69
[ -e "$PROFILE" ] || exit 1

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