1#!/bin/sh
2# $NetBSD: build_image.sh,v 1.2 2009/04/03 22:36:34 perry Exp $
3# This script is a quick hack to generate the various floppies in the
4# 'installation/floppies' directory. This script cannot be run in the
5# build environment, it is provided as a howto.
6# When msdos support is added to makefs, it makes sense to provide a
7# decent script that can be integrated into the build environment.
8#
9# Leo 10 Sept. 2002.
10
11DESTDIR=/tmp/flop_images
12TOOLDIR=/tmp/flop_tools
13KERNEL_DIR=/tmp/kernels
14MNT_DIR=/mnt2
15VND_DEV=vnd0
16SUDO=sudo
17
18IMAGE720="boot BOOT"
19IMAGE144="hades_boot HADES milan_isa_boot MILAN-ISAIDE"
20IMAGE144="$IMAGE144  milan_pci_boot MILAN-PCIIDE"
21TOOLS="chg_pid.ttp file2swp.ttp loadbsd.ttp rawwrite.ttp aptck.ttp"
22
23unpack_tools() {
24          if [ ! -d $TOOLDIR ]; then
25                    mkdir $TOOLDIR;
26          fi
27          for i in $TOOLS
28          do
29                    cat ${i}.gz.uu | (cd $TOOLDIR; uudecode)
30                    gunzip -f $TOOLDIR/${i}.gz
31          done
32}
33
34do_images() {
35          base_img=$1; geom=$2; shift 2
36
37          while : ; do
38                    if [ -z "$1" ]; then
39                              break;
40                    fi
41                    cat ${base_img}.fs.gz.uu | (cd /tmp; uudecode)
42                    gunzip /tmp/${base_img}.fs.gz
43                    $SUDO vnconfig $VND_DEV /tmp/${base_img}.fs $geom
44                    $SUDO mount -t msdos /dev/${VND_DEV}c ${MNT_DIR}
45
46                    # Copy the kernel first...
47                    cp ${KERNEL_DIR}/netbsd-${2}.gz ${MNT_DIR}/netbsd
48
49                    # Thereafter the tools, some may not fit :-(
50                    for i in $TOOLS; do
51                              cp $TOOLDIR/$i ${MNT_DIR} 2> /dev/null
52                              if [ $? -ne 0 ]; then
53                                        echo "$i does not fit on ${1}.fs"
54                                        rm -f ${MNT_DIR}/$i
55                              fi
56                    done
57                    echo "Contents of ${1}.fs:\n"; ls -l ${MNT_DIR}
58
59                    $SUDO umount ${MNT_DIR}
60                    $SUDO vnconfig -u ${VND_DEV}
61                    mv /tmp/${base_img}.fs /tmp/$1.fs
62                    gzip -9n /tmp/$1.fs
63                    mv /tmp/$1.fs.gz $DESTDIR
64                    shift 2
65          done
66}
67
68
69if [ ! -d $DESTDIR ]; then
70          mkdir $DESTDIR
71fi
72
73if [ ! -d $KERNEL_DIR ]; then
74          echo "Please put the kernel images in $KERNEL_DIR!!"
75          exit 1
76fi
77rm -f $TOOLDIR/* $DESTDIR/*
78
79unpack_tools
80do_images boot720 "512/18/1/80" ${IMAGE720}
81do_images boot144 "512/18/2/80" ${IMAGE144}
82
83echo "The images can be found in: $DESTDIR"
84