setup-proxy.in 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/bin/sh

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

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 '='`
fi

echon "name of proxyserver ? (e.g proxy.domain.loc:8080) [$proxyserver] "
default_read proxyserver $proxyserver
Natanael Copa's avatar
Natanael Copa committed
16
if echo $proxyserver | grep -q ":"; then
17 18 19 20 21
  echon "port of proxyserver ? [8080] "
  default_read proxyport "8080"
  proxyserver=$proxyserver:$proxyport
fi

Natanael Copa's avatar
Natanael Copa committed
22
if [ "$proxyuser" = "" ] ; then
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  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
else
  proxyuser=""
  proxypass=""
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
fi

echo -e "\nto make changes active please do login again or source $PROFILE with \". $PROFILE\""