aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2012-03-05 16:01:22 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2012-03-05 16:06:48 +0000
commit752c73a67e2620ca764993ea34f072d5908a6612 (patch)
tree2fb45dde415443440b9679000bd65d3a96f08ce2
parent1f731313ece70171c4b5f2bed00898a4519abc3d (diff)
downloadalpine-conf-752c73a67e2620ca764993ea34f072d5908a6612.tar.bz2
alpine-conf-752c73a67e2620ca764993ea34f072d5908a6612.tar.xz
setup-proxy: (over?)simplify
We want avoid asking questions and in the proxy case most people will pick 'none'. For those who needs proxy there is still a possibility to specify the entire proxy url in one shot, rather than asking lot of questions.
-rw-r--r--setup-proxy.in101
1 files changed, 52 insertions, 49 deletions
diff --git a/setup-proxy.in b/setup-proxy.in
index 4d62ea0..1b1b008 100644
--- a/setup-proxy.in
+++ b/setup-proxy.in
@@ -3,63 +3,66 @@
PREFIX=
. "$PREFIX/lib/libalpine.sh"
+
+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"
+
PROFILE="$ROOT/etc/profile.d/proxy.sh"
if [ -f "$PROFILE" ] ; then
- proxyserver=`grep "^# proxyserver" $PROFILE | cut -f 2 -d '='`
- proxyuser=`grep "^# proxyuser" $PROFILE | cut -f 2 -d '='`
- proxypass=`grep "^# proxypass" $PROFILE | cut -f 2 -d '='`
+ . $PROFILE
fi
-echon "name of proxyserver ? (e.g proxy.domain.loc:8080) [$proxyserver] "
-default_read proxyserver $proxyserver
-if echo $proxyserver | grep -q ":"; then
- echon "port of proxyserver ? [8080] "
- default_read proxyport "8080"
- proxyserver=$proxyserver:$proxyport
-fi
+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
-if [ "$proxyuser" = "" ] ; then
- needauth="no"
-else
- needauth="yes"
-fi
-echon "do you need authentication ? [$needauth] "
-default_read needauth $needauth
-
-if [ "$needauth" = "yes" ]; then
- echon "username ? (e.g felix) leave empty if not required [$proxyuser] "
- default_read proxyuser $proxyuser
-
- if [ -n "$proxyuser" ] ; then
- echon "password for proxyserver ? [$proxypass] "
- default_read proxypass $proxypass
- else
- proxypass=""
- fi
+if [ -z "$proxyurl" ]; then
+ rm -f "$PROFILE"
else
- proxyuser=""
- proxypass=""
+ 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__
fi
-(
- echo "# proxyserver=$proxyserver"
- echo "# proxyuser=$proxyuser"
- echo "# proxypass=$proxypass"
-) > $PROFILE
-
-if [ "$proxyuser" = "" ] ; then
- (
- echo "export http_proxy=http://$proxyserver/"
- echo "export https_proxy=http://$proxyserver/"
- echo "export ftp_proxy=http://$proxyserver/"
- ) >> $PROFILE
-else
- (
- echo "export http_proxy=http://$proxyuser:$proxypass@$proxyserver/"
- echo "export https_proxy=http://$proxyuser:$proxypass@$proxyserver/"
- echo "export ftp_proxy=http://$proxyuser:$proxypass@$proxyserver/"
- ) >> $PROFILE
+[ -e "$PROFILE" ] || exit 1
+
+if [ -z "$quiet" ]; then
+ echo -e "\nTo make changes active please do login again or source $PROFILE\nwith \". $PROFILE\""
fi
-echo -e "\nto make changes active please do login again or source $PROFILE with \". $PROFILE\""