#!/bin/sh

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

if [ "${1}" = "" ]; then
  echo "Usage: $0 old-zfs-be" >/dev/stderr;
  exit 69;
fi

echo "${0}: mounting old BE ${1} on /mnt"
mount -t zfs "${1}" /mnt || exit

if [ -r /mnt/boot/entropy ]; then
  echo "${0}: copying boot entropy file from old BE";
  cat /mnt/boot/entropy > /boot/entropy || exit;
fi

if [ -r /mnt/entropy ]; then
  echo "${0}: copying early entropy file from old BE";
  cat /mnt/entropy > /entropy || exit;
fi

if [ -r /mnt/root/.history ]; then
  echo "${0}: copying csh history file from old BE";
  cat /mnt/root/.history > /root/.history || exit;
fi

if [ -r /mnt/root/.bash_history ]; then
  if [ ! -f /root/.bash_history ]; then
    echo "${0}: creating, chmodding, and linking new bash history file";
    touch /root/.bash_history;
    chmod 0600 /root/.bash_history;
    ln /root/.bash_history /.bash_history;
  fi;

  echo "${0}: copying bash history file from old BE";
  cat /mnt/root/.bash_history > /root/.bash_history || exit;
fi

echo "${0}: unmounting old BE on /mnt"
umount /mnt || exit

echo "${0}: updating files in /etc/mail"
cd /etc/mail || exit
make all install || exit

echo "${0}: done"

# EOF
