1272343Sngie#!/bin/sh
2272343Sngie# $NetBSD: build_image.sh,v 1.1.1.1 2002/09/10 13:58:51 leo Exp $
3272343Sngie# This script is a quick hack to generate the various floppies in the
4272343Sngie# 'installation/floppies' directory. This script cannot be run in the
5272343Sngie# build environment, it is provided as a howto.
6272343Sngie# When msdos support is added to makefs, it makes sense to provide a
7272343Sngie# decent script that can be integrated into the build environment.
8272343Sngie#
9272343Sngie# Leo 10 Sept. 2002.
10272343Sngie
11272343SngieDESTDIR=/tmp/flop_images
12272343SngieTOOLDIR=/tmp/flop_tools
13272343SngieKERNEL_DIR=/tmp/kernels
14272343SngieMNT_DIR=/mnt2
15272343SngieVND_DEV=vnd0
16272343SngieSUDO=sudo
17272343Sngie
18272343SngieIMAGE720="boot BOOT"
19272343SngieIMAGE144="hades_boot HADES milan_isa_boot MILAN-ISAIDE"
20272343SngieIMAGE144="$IMAGE144  milan_pci_boot MILAN-PCIIDE"
21272343SngieTOOLS="chg_pid.ttp file2swp.ttp loadbsd.ttp rawwrite.ttp aptck.ttp"
22272343Sngie
23272343Sngieunpack_tools() {
24272343Sngie	if [ ! -d $TOOLDIR ]; then
25272343Sngie		mkdir $TOOLDIR;
26272343Sngie	fi
27272343Sngie	for i in $TOOLS
28272343Sngie	do
29272343Sngie		cat ${i}.gz.uu | (cd $TOOLDIR; uudecode)
30272343Sngie		gunzip -f $TOOLDIR/${i}.gz
31272343Sngie	done
32272343Sngie}
33272343Sngie
34272343Sngiedo_images() {
35272343Sngie	base_img=$1; geom=$2; shift 2
36272343Sngie
37272343Sngie	while : ; do
38272343Sngie		if [ -z "$1" ]; then
39272343Sngie			break;
40272343Sngie		fi
41272343Sngie		cat ${base_img}.fs.gz.uu | (cd /tmp; uudecode)
42272343Sngie		gunzip /tmp/${base_img}.fs.gz
43272343Sngie		$SUDO vnconfig $VND_DEV /tmp/${base_img}.fs $geom
44272343Sngie		$SUDO mount -t msdos /dev/${VND_DEV}c ${MNT_DIR}
45272343Sngie
46272343Sngie		# Copy the kernel first...
47272343Sngie		cp ${KERNEL_DIR}/netbsd-${2}.gz ${MNT_DIR}/netbsd
48272343Sngie
49272343Sngie		# Thereafter the tools, some may not fit :-(
50272343Sngie		for i in $TOOLS; do
51272343Sngie			cp $TOOLDIR/$i ${MNT_DIR} 2> /dev/null
52272343Sngie			if [ $? -ne 0 ]; then
53272343Sngie				echo "$i does not fit on ${1}.fs"
54272343Sngie				rm -f ${MNT_DIR}/$i
55272343Sngie			fi
56272343Sngie		done
57272343Sngie		echo "Contents of ${1}.fs:\n"; ls -l ${MNT_DIR}
58272343Sngie
59272343Sngie		$SUDO umount ${MNT_DIR}
60272343Sngie		$SUDO vnconfig -u ${VND_DEV}
61272343Sngie		mv /tmp/${base_img}.fs /tmp/$1.fs
62272343Sngie		gzip -9n /tmp/$1.fs
63272343Sngie		mv /tmp/$1.fs.gz $DESTDIR
64272343Sngie		shift 2
65272343Sngie	done
66272343Sngie}
67272343Sngie
68272343Sngie
69272343Sngieif [ ! -d $DESTDIR ]; then
70272343Sngie	mkdir $DESTDIR
71272343Sngiefi
72272343Sngie
73272343Sngieif [ ! -d $KERNEL_DIR ]; then
74272343Sngie	echo "Please put the kernel images in $KERNEL_DIR!!"
75272343Sngie	exit 1
76272343Sngiefi
77272343Sngierm -f $TOOLDIR/* $DESTDIR/*
78272343Sngie
79272343Sngieunpack_tools
80272343Sngiedo_images boot720 "512/18/1/80" ${IMAGE720}
81272343Sngiedo_images boot144 "512/18/2/80" ${IMAGE144}
82272343Sngie
83272343Sngieecho "The images can be found in: $DESTDIR"
84272343Sngie