#!/bin/sh
# Install    Install bu
# Author:    Vincent Stemen
# Copyright: BSD

if [ -f ~/.burc ]; then . ~/.burc; fi
    
version="$(ident bu | awk '/Id/ {print $3}')"
LOGDIR=${LOGDIR:-/var/backups/bu}
docdir=usr/local/share/doc/bu-$version
docs="bu.lsm README white_paper Changelog"

mkdir -p $prefix/$LOGDIR                     || exit
mkdir -p $prefix/$docdir                     || exit
mkdir -p $prefix/usr/local/bin               || exit
install -m 0755 bu $prefix/usr/local/bin     || exit
install -m 0644 $docs $prefix/$docdir        || exit
install -m 0744 Un-install $prefix/$docdir   || exit

cd $prefix/$LOGDIR
saved_include=
saved_exclude=
[ -f Include ] && cp Include Include~ && saved_include=1
[ -f Exclude ] && cp Exclude Exclude~ && saved_exclude=1

cd -
install -m 0644 Exclude Include $prefix/$LOGDIR || exit
cd $prefix/$LOGDIR

echo
if [ $saved_include ]
then
  if diff -q Include Include~ > /dev/null; then
    rm Include~
  else
    echo "Preserving old Include file"
    mv Include Include-$version
    mv Include~ Include
    echo "The new one is installed as $LOGDIR/Include-$version"
  fi
fi
if [ $saved_exclude ]
then
  if diff -q Exclude Exclude~ > /dev/null; then
    rm Exclude~
  else
    echo "Preserving old Exclude file"
    mv Exclude Exclude-$version
    mv Exclude~ Exclude
    echo "The new one is installed as $LOGDIR/Exclude-$version"
  fi
fi

cat << eof

bu is now installed.
The docs and the Un-install script are in /$docdir.
Read the README, then type "bu -h".

eof

