#!/bin/bash
# splitInd2HaF V.01 (23.12.2020)     a-weinert.de 
# (c) 2020 Albrecht Weinert weinert-automation.de
# In the current directory the file index.htm wilt be
# split at a line the "<small>listing generated by .."
# into pub-header.htm and pub-footer.htm.

if [ ! -f index.htm ] ; then
  echo "no index.htm: $PWD"
  exit 1
fi
echo "In $PWD"
if [ -f xx00 ] ; then rm xx00 ; fi
[ -f xx01 ] && rm xx01
echo 'csplit index.htm "/^<small>listing generated by/"'
csplit index.htm "/^<small>listing generated by/"
ret=$?
if [ $ret -ne 0 ] ; then
  echo "index.htm: split failed $ret"
  exit $ret
fi
for usedNOmore in pub-header.htm pub-footer.htm pub-header.html pub-footer.html ; do
  if [ ! -f $usedNOmore ] ; then continue; fi
  rm $usedNOmore
  ret=$?
  if [ $ret -ne 0 ] ; then
    echo "could not remove $usedNOmore $ret"
    exit $ret
  fi
done
mv xx00 pub-header.htm
mv xx01 pub-footer.htm
if [ -f pub-header.htm ] && [ -f pub-footer.htm ]; then
 echo "index.htm: pub-header.htm, pub-footer.htm; del"
 rm index.htm
 ret=$?
 if [ $ret -ne 0 ] ; then
  echo "could not remove index.htm $ret"
  exit $ret
 fi
 exit 0
fi
echo "index.htm: renaming split files failed"
exit 44
