#!/bin/sh

LIBS="ld-linux.so libc.so libcom_err.so libdl.so libe2p.so libext2fs.so"
USRLIBS="libnewt.so libslang.so rpmrc"
BINS="awk bash cat cp cpio df egrep grep gunzip ldd ln mknod mount ping ps route rpm sed umount vi wc gzip ls mke2fs ash cat rm open fdisk badblocks"
SBINS="cp df ldconfig"
TARGET="/mnt/sparc/RedHat/instimage"

usage () {
    echo "updinst: <imagetree>" 2>&1
    exit 1
}

if [ -z "$1" ]; then
    usage
fi

if [ ! -d "$1/misc/src/install" ]; then
    echo "$1 is not a valid directory" 2>&1
    usage
fi

PATH=$1/misc/src/install:/usr/sbin:/usr/bin:/bin:/sbin

rm $TARGET/lib/*
for n in $LIBS; do
	cp -a /lib/${n}* $TARGET/lib
done

for n in $USRLIBS; do
	rm $TARGET/usr/lib/${n}*
done
for n in $USRLIBS; do
	cp -a /usr/lib/${n}* $TARGET/usr/lib
done

for n in $BINS; do
	rm -f $TARGET/usr/bin/$n
	cp -af `which $n` $TARGET/usr/bin
done

for n in $SBINS; do
	rm -f $TARGET/sbin/$n
	cp -af `which $n` $TARGET/sbin
done

