head	1.3;
access;
symbols;
locks; strict;
comment	@# @;


1.3
date	93.11.06.20.27.49;	author md;	state Exp;
branches;
next	1.2;

1.2
date	93.06.25.15.55.54;	author md;	state Exp;
branches;
next	1.1;

1.1
date	93.05.18.20.11.59;	author md;	state Exp;
branches;
next	;


desc
@@


1.3
log
@Correct amount of available disk space on 1.2M floppy.
@
text
@#!/bin/sh
# $Header: /usr/src/sys/rtdist/RCS/netroot,v 1.2 1993/06/25 15:55:54 md Exp md $
# $ACIS:miniroot 12.2$
# $Source: /usr/src/sys/rtdist/RCS/netroot,v $
#
# 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1986,1987,1988
# LICENSED MATERIALS - PROPERTY OF IBM
# REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
#
#	miniroot - script to build an installation miniroot
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/ibm:.
export PATH
CMD=`basename ${0}`
USAGE="
usage: ${CMD} [options]

available options:
	-f<special>	disk partition to use	[/dev/fd0]
	-m<mdir>	mountpoint to use	[/mnt]
	-k<file>	kernel binary to use	[/sys/GENERIC.rtminiroot/vmunix]
	-d<rdir>	"root" directory tree	[/]
	-local		use local datafiles (eg, /etc/hosts)
"
#
# uses Makefile to make the "local" (miniroot specific) utilities.
# Unless local is specified, tries to use /usr/src versions of datafiles
#
DEVICE=/dev/fd0
RDEVICE=/dev/rfd0
FS=/mnt
VMUNIX=/sys/GENERIC.rtminiroot/vmunix
SRC=/usr/src
ROOT=
TBUILD=/tmp/mroot.net.image

for i
do
	case "${i}" in
	-f?*)	DEVICE=`expr "${i}" : '-.\(.*\)'`;;
	-m?*)	FS=`expr "${i}" : '-.\(.*\)'`;;
	-k?*)	VMUNIX=`expr "${i}" : '-.\(.*\)'`;;
	-d?*)	ROOT=`expr "${i}" : '-.\(.*\)'`;;
	-local)	SRC=;;
	*)	echo "${CMD}:${i}:unknown option ${USAGE}" >&2
		exit 1;;
	esac
done

# /etc/services, /etc/protocols, and /etc/disktab are data files that
# may not have had the newest versions installed yet
DATAFILES=
for i in /etc/disktab /etc/protocols /etc/services
do
	if [ ! -f ${ROOT}${SRC}/${i} ]
	then DATAFILES="${DATAFILES} ${ROOT}${i}"
	else DATAFILES="${DATAFILES} ${ROOT}${SRC}/${i}"
	fi
done

echo "${CMD}: checking if all required files exist....." >&2
# /etc/group, /etc/passwd, and /etc/hosts datafiles are stripped.
if [ ! -f ${ROOT}${SRC}/etc/group ]
then
	GROUP=/etc/group
	echo "${CMD}: warning!:using local /etc/group" >&2
else
	GROUP=${ROOT}${SRC}/etc/group
fi

if [ ! -f ${ROOT}${SRC}/etc/passwd ]
then
	PASSWD=/etc/passwd
	echo "${CMD}: warning!:using local /etc/passwd" >&2
else
	PASSWD=${ROOT}${SRC}/etc/passwd
fi

if [ ! -f ${ROOT}${SRC}/etc/hosts ]
then
	HOSTS=/etc/hosts
	echo "${CMD}: warning!:using local /etc/hosts" >&2
else
	HOSTS=${ROOT}${SRC}/etc/hosts
fi

if [ ! -f ${ROOT}${SRC}/dev/MAKEDEV ]
then MAKEDEV=/dev/MAKEDEV
else MAKEDEV=${ROOT}${SRC}/dev/MAKEDEV
fi

BOOT=${ROOT}/usr/mdec/bootfd
BOOTBLOCK=${ROOT}/usr/mdec/fd1.2mboot

# root directory
DIST=/sys/dist

# original /bin files
BIN="${ROOT}/bin/sh"

# local /bin files
LOCALBIN="${DIST}/bin/sync.sh ${DIST}/bin/cat.sh ${DIST}/bin/mkdir.sh \
	${DIST}/bin/chmod.sh ${DIST}/bin/echo.sh \
	${DIST}/bin/ln.sh ${DIST}/bin/ls.sh ${DIST}/bin/df.sh \
	${DIST}/bin/rmdir.sh ${DIST}/bin/date.sh ${DIST}/bin/kill.sh"

# orginal /etc files
# ETC="${ROOT}/sbin/fsck ${ROOT}/sbin/restore ${ROOT}/sbin/routed"

# /sbin files
SBIN="${ROOT}/sbin/restore ${ROOT}/sbin/route"

# local /sbin files
# LOCALSBIN="${DIST}/sbin/dtype ${DIST}/sbin/init"

# local /etc files
LOCALETC="${DIST}/etc/onechar ${DIST}/etc/fstab \
	${DIST}/etc/sizeck.sh ${DIST}/etc/whichdev.sh \
	${DIST}/etc/ask.sh ${DIST}/etc/yesno.sh \
	${DIST}/etc/rc.sh ${DIST}/etc/halt.sh ${DIST}/etc/reboot.sh \
	${DIST}/etc/umount.sh ${DIST}/etc/mask.sh \
	${DIST}/etc/mkconfig.sh ${DIST}/etc/type.sh"

# local /lib files
LOCALLIB="${DIST}/lib/install.driver.sh ${DIST}/lib/install.mainmenu.sh \
	${DIST}/lib/install.options.sh ${DIST}/lib/install.welcome.sh"

# local /usr/bin files
LOCALUSRBIN="${DIST}/usr/bin/sleep.sh ${DIST}/usr/bin/basename.sh"

# local /usr/ucb files
LOCALUCB="${DIST}/usr/ucb/page.sh"

# original /usr/mdec files
MDEC="${ROOT}/usr/mdec/boothd ${ROOT}/usr/mdec/hd* ${ROOT}/usr/mdec/installboot"

# original /usr/ibm files
# local /usr/ucb files
IBM="${ROOT}/usr/ibm/ftc"

# and of course the GLOB
# XXX: route should be here, but the linked in object is bad....
#	For now we'll use the local /sbin version of route.
LOCALGLOB="${DIST}/glob/glob"
GLOBLINKS="sbin/newfs sbin/mfs sbin/ifconfig sbin/mount \
	usr/bin/rsh sbin/init sbin/dtype bin/dd bin/test bin/[ \
	etc/syscall bin/expr bin/stty bin/cp bin/rm"

MISSING=
for i in ${VMUNIX} ${DEVICE} ${BOOT} ${BOOTBLOCK} ${DATAFILES} ${GROUP} ${PASSWD} \
        ${HOSTS} ${MAKEDEV} ${BIN} ${LOCALBIN} ${ETC} ${LOCALETC} ${LOCALLIB} \
        ${LOCALUSRBIN} ${LOCALUCB} ${MDEC} ${IBM} ${LOCALGLOB}
do
	test -f ${i} || MISSING="${MISSING} ${i}"
done

if [ "${MISSING}" ]
then
	echo "${CMD}: cannot find" ${MISSING} >&2
	exit 1
fi

if [ `whoami` != root ]
then
	echo "${CMD}: can only be run by root" >&2
	exit 1
fi

case "${DEVICE}" in
/dev/fd[01])
	# format diskette (fdformat will ask before formatting)
	RDEVICE=`echo ${DEVICE} | sed s'@@fd@@rfd@@'`
	fdformat -h ${RDEVICE};;
esac

# make a bootable file system
while : rebuild filesystem?
do
    echo -n "${CMD}: rebuild filesystem on" ${DEVICE} " [yn]?">&2
    read answer
    case $answer in
    	"n")	break;;

    	"y")	${ROOT}/usr/mdec/installboot ${BOOTBLOCK} ${BOOT} ${DEVICE}
		${ROOT}/sbin/newfs ${DEVICE} 
		${ROOT}/sbin/tunefs -m 0 -o space ${DEVICE} 
		break;;

    	*)	echo "Please answer 'y' or 'n'" >&2
    esac
done

echo "${CMD}: checking for a valid filesystem on" ${DEVICE} >&2
if ${ROOT}/sbin/fsck -n ${RDEVICE}
then : all is well
else
	echo "${CMD}: fsck ${RDEVICE} failed" >&2
	exit 1
fi

trap 'EXIT=${?}; cd /; umount ${DEVICE} > /dev/null 2>&1; exit ${EXIT}' 0 1 2 15

# create the temporary build directory
if [ -d ${TBUILD} ]; then
while : remove build tree?
do
    echo -n "${CMD}: the" ${TBUILD} "build directory exist.  Remove it?">&2
    read answer
    case $answer in
    	"n")	break;;

    	"y")	rm -rf ${TBUILD} || exit ${?}
		break;;

    	*)	echo "Please answer 'y' or 'n'" >&2
		continue;;
    esac
done
fi

if mkdir ${TBUILD}
then : all is well
else
	echo "${CMD}: can't create ${TBUILD}" >&2
	exit 1
fi

echo "${CMD}: making build tree in ${TBUILD}......" >&2

# set up the directories; make the device special files
cd ${TBUILD}
chmod 775 .
chgrp staff .
mkdir bin etc sbin dev lib mnt mnt/site tmp usr usr/bin usr/ucb usr/mdec usr/ibm
cd dev
sh -${-} ${MAKEDEV} std st0 fd0 hd0 hd1 hd2 sc0 sc1
cd ..

# install kernel binary, use ${TBUILD} to make install happy
install -c -s ${VMUNIX} ${TBUILD}/vmunix || exit ${?}
ln vmunix boot || exit ${?}

# set up the bin, sbin, etc, usr/bin, usr/ucb, and usr/mdec directories
for i in ${BIN}
do
	install -c ${i} bin/`basename ${i}` || exit ${?}
done
for i in ${LOCALBIN}
do
	install -c ${i} bin/`basename ${i} .sh` || exit ${?}
done

for i in ${SBIN}
do
	j=`basename ${i}`
	install -c ${i} sbin/$j || exit ${?}
done
for i in ${LOCALSBIN}
do
	j=`basename ${i} .sh`
	install -c ${i} sbin/$j || exit ${?}
done
#ln sbin/newfs sbin/mfs || exit ${?}

for i in ${LOCALETC}
do
	j=`basename ${i} .sh`
	install -c ${i} etc/$j || exit ${?}
	ln etc/$j sbin/$j
done

for i in ${DATAFILES}
do
	sed '/^#/d' ${i} > etc/`basename ${i} .sh` || exit ${?}
done

# use whatever hosts file we found above
egrep -v '^#' ${HOSTS}			> etc/hosts || exit ${?}

# create minimal /etc/group and /etc/passwd
egrep '^wheel:|^staff:'	${GROUP}	> etc/group || exit ${?}
egrep '^root:'		${PASSWD}	> etc/passwd || exit ${?}

for i in ${LOCALUSRBIN}
do
	install -c ${i} usr/bin/`basename ${i} .sh` || exit ${?}
done

for i in ${LOCALUCB}
do
	install -c ${i} usr/ucb/`basename ${i} .sh` || exit ${?}
done

for i in ${MDEC}
do
	install -c ${i} usr/mdec/`basename ${i}` || exit ${?}
done

for i in ${IBM}
do
	install -c ${i} usr/ibm/`basename ${i}` || exit ${?}
done

for i in ${LOCALLIB}
do
	install -c ${i} lib/`basename ${i} .sh` || exit ${?}
done
# XXX (TEMP)
install -c ${DIST}/lib/install.driver.net.sh lib/install.driver || exit ${?}

# do the GLOB
install -c ${DIST}/glob/glob ${TBUILD}/glob || exit ${?}
for i in ${GLOBLINKS}
do
	ln ${TBUILD}/glob ${TBUILD}/$i || exit ${?}
done

install -c ${DIST}/restore.tape.sh ${TBUILD}/restore.tape || exit ${?}
install -c ${DIST}/restore.net.sh ${TBUILD}/restore.net || exit ${?}
install -c ${DIST}/xconf.sh ${TBUILD}/xconf || exit ${?}
#ln restore.tape restore.net || exit ${?}

tsize=`du -ks ${TBUILD} | awk '{ print $1}'`
maxsize=1049
if [ $tsize -gt $maxsize ]; then
	echo "${CMD}: build tree is" $tsize "KB which is larger than $maxsize KB" >&2
	exit
else
	echo "${CMD}: copying build tree (" $tsize "KB)......" >&2
fi

cd /
mount ${DEVICE} ${FS} || exit ${?}
rmdir ${FS}/lost+found 2>/dev/null
cd ${TBUILD}
find . -depth -print | cpio -pdlmv ${FS} || exit ${?}
sync; sync
cd /
df ${DEVICE}
umount ${DEVICE}
if fsck -n ${RDEVICE}
then : fsck succeeded
	echo "${CMD}: completed successfully" >&2
else
	echo "${CMD}: fsck ${RDEVICE} failed" >&2
	exit 1
fi
@


1.2
log
@Changes from Roger.
@
text
@d2 1
a2 1
# $Header: /sys/rtdist/RCS/miniroot,v 1.5 1993/01/07 21:05:33 md Exp $
d4 1
a4 1
# $Source: /sys/rtdist/RCS/miniroot,v $
d324 4
a327 2
if [ $tsize -gt 1043 ]; then
	echo "${CMD}: build tree is" $tsize "KB which larger than 1043Kb" >&2
d329 1
a329 1
	echo "${CMD}: copying build tree (" $tsize "Kb)......" >&2
a330 2

#exit
@


1.1
log
@Initial revision
@
text
@d111 1
a111 1
SBIN="${ROOT}/sbin/restore"
d142 2
d145 3
a147 3
GLOBLINKS="sbin/newfs sbin/mfs sbin/ifconfig sbin/route sbin/mount \
	usr/bin/rsh sbin/init sbin/dtype bin/dd bin/test etc/syscall \
	bin/expr"
@
