#!/bin/sh


prefix=$1
installprefix=$2
erl=$3
etcdir=$4

. ../vsn.mk
y=yaws-${YAWS_VSN}
p=${prefix}


# sed mangler
mangle ()
{
    d=$1
    e=$2
    from=$3
    to=$4

    install -d `dirname $to`
    sed -e "s;%yawsdir%;$d;g" -e "s;%erl%;$e;" $from > $to
}



mangle ${prefix}/lib/yaws ${erl} yaws.ss ${installprefix}/bin/yaws
install -d ${installprefix}/lib/yaws/examples/ebin
install -d ${installprefix}/lib/yaws/examples/include
chmod +x ${installprefix}/bin/yaws
if [ -f ${etcdir}/yaws.conf ]; then
   t=${etcdir}/yaws.conf.template
else
   t=${etcdir}/yaws.conf
fi

mangle ${prefix}/lib/yaws ${erl} yaws.conf.template ${t}


if [ -f /etc/gentoo-release ]; then
    install -d  ${etcdir}/init.d/
    install -d ${etcdir}/conf.d/
    cp gentoo/init.d.yaws  ${etcdir}/init.d/yaws
    chmod +x ${etcdir}/init.d/yaws
    sed -e "s;%prefix%;$p;g" gentoo/conf.d.yaws > ${etcdir}/conf.d/yaws
elif [ -f /etc/redhat-release ]; then
    install -d ${etcdir}/init.d
    sed -e "s;%prefix%;$p;g" redhat/yaws.init.d  > ${etcdir}/init.d/yaws
    chmod +x ${etcdir}/init.d/yaws
elif [ -f /etc/suseservers ]; then
    install -d ${etcdir}/init.d
    sed -e "s;%prefix%;$p;g" suse/yaws.init.d  > ${etcdir}/init.d/yaws
    chmod +x ${etcdir}/init.d/yaws
else
    echo "Don't know how to make /etc/init scrips for this system"
    echo "possibly add $1/bin/yaws -D -heart to your /etc/rc.local manually"
fi




