#!/bin/bash
#
# This program is part of the three backup (tbackup) package,
# (c) 1993,1994 Koen Holtman.


# add /auxbin to path if it exists.
if [ -e /auxbin ]; then
 export PATH=/auxbin:$PATH
fi

cd /

if [ "$1" != "`basename $1`" -o  "$2" != "`basename $2`" -o \
     ! -d "$1" -o ! -d "$2" ]; then
 echo "usage: swaproot newsystem oldsystem"
 echo " Moves contents of / to /oldsystem, and contents of /newsystem to /."
 echo " Excludes /proc from the move."
 exit 1
fi

ls / | \
  gawk -v n=$1 -v o=$2 \
   '! (($0=="proc") || ($0==n) || ($0==o)) { print "/" $1 "  /" o "/" $1 }' \
  >/tmp/swaproot.list

ls $1 | \
  gawk -v n=$1 -v o=$2 \
   '! ($0=="proc") { print "/" n "/" $1 " " "/" $1 }' \
  >>/tmp/swaproot.list

echo "Swapping systems..."

sync
sleep 1

/usr/lib/tbackup/bin/mvmany < /tmp/swaproot.list

rm /$2/tmp/swaproot.list

sync

echo "Note: To get fully functional shell, you may have to type ctrl-d to a login"
echo "prompt and then log in."
