#!/bin/sh
# $Id: 9.restore_usr.sh,v 1.6 2004/07/09 10:41:08 drizzt Exp $

. ./config.sh

USR_CLOOP=cloop/usr.cloop
USR_ISO=old_usr.iso

VAR_CLOOP=cloop/var.cloop
VAR_ISO=old_var.iso

MFS_GZIP=boot/mfsroot.gz
MFS=boot/mfsroot

cd $FREESBIEBASEDIR
/usr/local/bin/extract_compressed_fs ${USR_CLOOP} > ${USR_ISO}
/usr/local/bin/extract_compressed_fs ${VAR_CLOOP} > ${VAR_ISO}
#Now we have to mount old_usr.iso
/bin/chflags -R noschg usr/ var/
/bin/rm -rf usr/* var/*
gunzip -f $MFS_GZIP
MD_USR=`/sbin/mdconfig -a -t vnode -f ${USR_ISO}`
MD_VAR=`/sbin/mdconfig -a -t vnode -f ${VAR_ISO}`
MD_MFS=`/sbin/mdconfig -a -t vnode -f $MFS`
/bin/mkdir tmp tmp1 tmp2
/sbin/mount -t cd9660 /dev/${MD_USR} tmp/
/sbin/mount -t cd9660 /dev/${MD_VAR} tmp1/
/sbin/mount /dev/${MD_MFS} tmp2/
/usr/bin/find ./tmp/ -depth -print | /usr/bin/cpio -pudm $FREESBIEBASEDIR/usr
/usr/bin/find ./tmp1/ -depth -print | /usr/bin/cpio -pudm $FREESBIEBASEDIR/usr
/usr/bin/find ./tmp2/ -depth -print | /usr/bin/cpio -pudm $FREESBIEBASEDIR/usr
/bin/mv -f usr/tmp/* usr/
/bin/mv -f usr/tmp1/* var/
/bin/mv -f usr/tmp2/* ./
/bin/rm -r usr/tmp*
/sbin/umount tmp
/sbin/umount tmp1
/sbin/umount tmp2
/sbin/mdconfig -d -u $MD_USR
/sbin/mdconfig -d -u $MD_VAR
/sbin/mdconfig -d -u $MD_MFS
/bin/rm -f ${USR_CLOOP} ${USR_ISO} ${VAR_CLOOP} ${VAR_ISO} $MFS
/bin/rmdir tmp tmp1 tmp2
