#! /bin/sh
#----------------------------------------------------------------------------
# /var/install/config.d/environment.sh - apply script for environment
#
# Creation   :  2004-05-21 max
# Last Update:  $Id: environment.sh 33462 2013-04-13 15:27:03Z hbfl $
#
# Copyright (c) 2001-2013 the eisfair team, team(at)eisfair(dot)org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------
# Generate all necessary config-files based on the entries
# in /etc/config.d/environment

package_name='environment'
wgetrcfile='/etc/wgetrc'
wgetrcfiles_auth='/root/.wgetrc /home/eis/.wgetrc'

### read configuration file ###
. /etc/config.d/${package_name}

### begin writing wgetrc config ###
    cat >${wgetrcfile} <<EOF
ca_directory=/usr/local/ssl/certs
check_certificate=off
inet4_only=on
EOF

### http proxy ###
if [ -n "$HTTP_PROXY" ]
then
    cat >>${wgetrcfile} <<EOF
use_proxy=on
http_proxy=$HTTP_PROXY
https_proxy=$HTTP_PROXY
ftp_proxy=$HTTP_PROXY
EOF

    old_umask=`umask`
    umask 077

    for j in $wgetrcfiles_auth
    do
      if [ -n "$HTTP_PROXY_USER" ]
      then
          {
           echo "proxy_user=$HTTP_PROXY_USER"
           echo "proxy_password=$HTTP_PROXY_PASSWD"
          } > $j
      else
          rm -f $j
      fi
    done

    umask $old_umask
fi

### copy environment ###
grep -v "^HTTP_PROXY" /etc/config.d/${package_name} > /var/run/${package_name}
chown root.root /var/run/${package_name}
chmod 0664 /var/run/${package_name}

exit 0
