#!/bin/sh

#makeconfig CC=cc
#make

prg=`basename $0`
arch=${1:-`ls -ld /client | awk -F/ '{print $NF}'`}
sfd=/sw/$arch/sendfile-2.1
sfold=/sw/$arch/sendfile-2.0
sfs=`pwd`

if [ -d $sfold ]; then
  cd $sfold
  echo . | /client/sbin/SWdeinstall -c /sw/clients/$arch
  cd $sfs
  rm -rf $sfold
fi

mkdir $sfd $sfd/bin $sfd/etc $sfd/install $sfd/doc 2>/dev/null
mkdir $sfd/man $sfd/man/man1 $sfd/man/man7 $sfd/man/man8 2>/dev/null
cd src
cp receive sendfile sendmsg utf7encode wlock $sfd/bin/ || exit 1
cp sendfiled $sfd/install/ || exit 1
( cd $sfd/bin; ln -s utf7encode utf7decode 2>/dev/null )
cd ../etc
cp sfconf sfdconf sf_cleanup $sfd/bin/ || exit 1
cp sendfile.deny $sfd/install/ || exit 1
sed 's/msglog = off/msglog = on/
     s|:/usr/bin|:/usr/bin:/client/bin|' sendfile.cf > $sfd/etc/sendfile.cf || exit 1
awk '{if ($0 != "CONFIG") print $0; else system("cat '$sfd/etc/sendfile.cf'")}' \
    sfdconf > $sfd/bin/sfdconf || exit 1
sed "s:receive -l:/client/bin/receive -l:" check_sendfile >$sfd/bin/check_sendfile
if [ $arch = pmax_ul43 ]; then
  sed "s:/bin/sh:/bin/sh5:
       s:SW_INSTALL:$sfd/install:" sf_install >$sfd/bin/sf_install
else
  sed "s:SW_INSTALL:$sfd/install:" sf_install >$sfd/bin/sf_install
fi
chmod 775 $sfd/bin/*
cd ../doc
cp *.1 $sfd/man/man1/
cp *.7 $sfd/man/man7/
cp *.8 $sfd/man/man8/
cp LIESMICH.neu LIESMICH.auch doku.ps $sfd/doc/

cd $sfd
rm -f *~ */*~

if [ "$prg" = swupdate ]; then 
  echo . | /client/sbin/SWrelease 
  echo
  cd bin
  chmod 755 *
  exit
fi

echo . | /client/sbin/SWdeinstall -c /sw/clients/$arch 2>/dev/null
rm Links 2>/dev/null
/client/sbin/SWlink -c /sw/clients/$arch
/client/sbin/SWmklinks -c /sw/clients/$arch
/client/sbin/SWmkreadme
head -5 README >qq
mv qq README
cat <<EOD>>README
Source: ftp.rus.uni-stuttgart.de:/pub/unix/comm/misc/sendfile.tar.gz
Kurzbeschreibung: asynchroner File und Message Transfer
Short-Description: asynchronous file and message transfer
Provider: rus.uni-stuttgart.de
Compiled-By: Ulli Horlacher (framstag@rus.uni-stuttgart.de)
Support: framstag@rus.uni-stuttgart.de
Documentation: man-pages, /client/doc/sendfile-2.1
Copyright: GPL
Status: available
User-Interface: Text

EOD
echo . | /client/sbin/SWrelease
echo . | /client/sbin/SWinstall -c /sw/clients/$arch
echo
cd bin
chmod 755 *
