#!/usr/bin/env bash
# PORTBUILD generated by manup.mreschke.com on 2013-04-09 01:41:22

# Variables below can NOT reference other variables, manup will not expand them.
# So fileurl="http://manup.mreschke.net/nwq/haproxy/haproxy-1.5-dev18-6.tar.gz"
# Though all variables can be accessed in the build_* functions.
# The ONLY exception to this rule is the config=(...) array, where $prefix is available

# There are also more bash variables available than you see here.
# The /usr/local/lib/manup/functions.sh is sourced before this file. Check it out.
# There are also a few set by manup, like $prefix, $fakeroot, $is_installed, $installed_ver
# Visit http://manup.mreschke.com for details

# All variables and build_* function must be present, even if empty.
# Since a bash function cannot be empty, just put in some placeholder
# like null=nothing

# Remember that manup comes with auto-destdir (http://www.dwheeler.com/auto-destdir/).
# So you should use 'make-redir DESTDIR=$fakeroot install' instead of just make.

# These files will be overwritten with every 'manup sync' command.

name=haproxy
ver=1.5-dev18
rel=6
fileurl="http://manup.mreschke.net/nwq/haproxy/haproxy-1.5-dev18-6.tar.gz"
filesize=1154261
md5sum="a5a8eb209e6d00c7cd6e68a59f73cdd2"
dep=()
depopt=()
configs=(/etc/haproxy/haproxy.cfg /etc/haproxy/test.cfg)
desc="The Reliable, High Performance TCP/HTTP Load Balancer"

port_configure() {
	null=nothing
}
port_build() {
	make TARGET=linux2628 USE-STATIC_PCRE=1 USE_OPENSSL=1
}
port_fakeroot() {
	make-redir DESTDIR=$fakeroot PREFIX=$prefix install
}
port_preinstall() {
	null=nothing
}
port_install() {
	cd $fakeroot; tar cf - . | (cd / ; tar -xvf -)
}
port_postinstall() {
	
if [ ! -e /etc/haproxy ]; then
  groupadd haproxy
  useradd -g haproxy -s /bin/false haproxy

cat > /etc/default/haproxy << "EOF"
# Set ENABLED to 1 if you want the init script to start haproxy.
ENABLED=1
# Add extra flags here.
#EXTRAOPTS="-de -m 16"
EOF

cat > /etc/rsyslog.d/haproxy.conf << "EOF"
$ModLoad imudp
$UDPServerRun 514
$UDPServerAddress 127.0.0.1
 
local0.* -/var/log/haproxy_info.log
local1.* -/var/log/haproxy_status.log
& ~ 
# & ~ means not to put what matched in the above line anywhere else for the rest of the rules
# http://serverfault.com/questions/214312/how-to-keep-haproxy-log-messages-out-of-var-log-syslog

# Actually found haproxy was being added to /var/log/syslog too, I modified the /etc/rsyslog.conf and set the line *.*;auth,authpriv.none,local0.none,local1.none which stopped it
# also the line about /var/log/message, append the local0.none and local1.none
EOF

  chmod a+x /etc/init.d/haproxy
  update-rc.d haproxy defaults

  mkdir -p /etc/haproxy/ssl/certs/
fi
if [ ! -e /etc/haproxy/errors ]; then
  mkdir -p /etc/haproxy/errors
  cp ../files/errors/* /etc/haproxy/errors/
fi
if [ ! -e /etc/haproxy/haproxy.cfg ]; then
  cp --no-clobber ../files/haproxy.cfg /etc/haproxy
  cp --no-clobber ../files/new-csr /etc/haproxy/ssl/
  cp --no-clobber ../files/new-self-signed /etc/haproxy/ssl/
  cp --no-clobber ../files/haproxy.service /etc/init.d/haproxy
fi

}
port_preuninstall() {
	null=nothing
}
port_postuninstall() {
	null=nothing
}
