#!/bin/sh
date=`date | awk '{ print $3 $2 substr ($5,3,2)}'`
dir=/u/backup

# jkp's backup script, add important directories here.
#
# Should perhaps also do incremental backups, change TAROPTS
# for that

TAR=tar
TAROPTS="-c -z -f"

if [ $# = 0 ]
then
  echo "Usage: $0 [ diffs ] [ doc ] [ etc ] [ gnu ] [ include ] [ kernel ] [ libsrc ] [ lib ] [ local ] [ man ] [ usrbin ] [ usrminix ] [ lusers ] [ info ] [ locallisp ] [ texinfo ]" 1>&2
  exit 2
fi

for i in "$@"
do
   eval `echo $i`=true
done

if [ "$diffs" ]
then
  echo "Doing diffs"
  cd /usr; $TAR $TAROPTS ${dir}/usr-diffs-${date}.tar.Z diffs diffs-1.3 minixdiffs minixdiffs-1.3
fi

if [ "$doc" ]
then
  echo "Doing doc"
  cd /etc; $TAR $TAROPTS ${dir}/etc-doc-${date}.tar.Z doc
fi

if [ "$etc" ]
then
  # If we start to use passwords, remember to encrypt or remove
  # /etc/passwd from here
  echo "Doing etc, devices, bin and /minix"
  cd /; $TAR $TAROPTS ${dir}/etc-${date}.tar.Z etc minix dev bin
fi

if [ "$lib" ]
then
  echo "Doing lib"
  cd /; $TAR $TAROPTS ${dir}/lib-${date}.tar.Z lib
fi

if [ "$gnu" ]
then
  echo > /usr/gnu/lib/find/find.codes
  echo "Doing gnu"
  cd /usr/gnu; $TAR $TAROPTS ${dir}/usr-gnu-${date}.tar.Z bin lib man
fi

if [ "$include" ]
then
  echo "Doing include"
  cd /usr; $TAR $TAROPTS ${dir}/usr-include-${date}.tar.Z include
fi

if [ "$kernel" ]
then
  echo "Doing kernel"
  cd /usr/src; $TAR $TAROPTS ${dir}/kernel-src-${date}.tar.Z kernel
fi

if [ "$libsrc" ]
then
  echo "Doing lib sources"
  cd /usr/src; $TAR $TAROPTS ${dir}/lib-src-${date}.tar.Z lib
fi

if [ "$local" ]
then
  echo "Doing local"
  cd /usr/local; $TAR $TAROPTS ${dir}/usr-local-${date}.tar.Z bin lib
fi

if [ "$man" ]
then
  echo "Doing man"
  cd /usr; $TAR $TAROPTS ${dir}/usr-man-${date}.tar.Z man
fi

if [ "$usrbin" ]
then
  echo "Doing usr/bin"
  cd /usr; $TAR $TAROPTS ${dir}/usr-bin-${date}.tar.Z bin lib adm/daily doc
fi

if [ "$usrminix" ]
then
  echo "Doing usr/minix"
  cd /usr; $TAR $TAROPTS ${dir}/usr-minix-${date}.tar.Z minix
fi

if [ "$lusers" ]
then
  # add encryption here
  echo "Doing lusers"
  cd /u; $TAR $TAROPTS ${dir}/lusers-homes-${date}.tar.Z users
fi

if [ "$info" ]
then
  echo "Doing emacs info"
  cd /u/gnu/emacs-18.57; tar cf ${dir}/emacs-info-${date}.tar info
fi

if [ "$locallisp" ]
then
  echo "Doing emacs lisp/local"
  cd /u/gnu/emacs-18.57/local; $TAR $TAROPTS ${dir}/emacs-lisp-local-${date}.tar.Z local
fi

if [ "$texinfo" ]
then
  echo "Doing texinfo"
  cd /u/gnu; $TAR $TAROPTS ${dir}/texinfo-${date}.tar.Z info
fi
