#!/bin/sh

#makeconfig CC=cc
#make

prg=`basename $0`
arch=${1:-`ls -ld /client | awk -F/ '{print $NF}'`}
sfd=/sw/$arch/sendfile-1.6
sfold=/sw/$arch/sendfile-1.5
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/man $sfd/man/man1 $sfd/install $sfd/doc 2>/dev/null
cd src
cp receive sendfile sendmsg utf7encode $sfd/bin/ || exit 1
cp sendfiled $sfd/install/ || exit 1
( cd $sfd/bin; ln -s utf7encode utf7decode 2>/dev/null )
cd ../etc
cp sf_cleanup $sfd/bin/ || exit 1
cp nosendfile sendfile.cf $sfd/install/ || 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 LIESMICH.neu LIESMICH.auch doku.ps $sfd/doc/

cd $sfd

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-1.6
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 *
