-echo "Welcome to ${OPSYSTEM}."
-echo ""
-echo "This program is designed to help you put ${OPSYSTEM} on your hard disk,"
-echo "in a simple and rational way. You'll be asked several questions,"
-echo "and it would probably be useful to have your disk's hardware"
-echo "manual, the installation notes, and a calculator handy."
-echo ""
-echo "In particular, you will need to know some reasonably detailed"
-echo "information about your disk's geometry, because there is currently"
-echo "no way this this program can figure that information out."
-echo ""
-echo "As with anything which modifies your hard drive's contents, this"
-echo "program can cause SIGNIFICANT data loss, and you are advised"
-echo "to make sure your hard drive is backed up before beginning the"
-echo "installation process."
-echo ""
-echo -n "Proceed with installation? [n] "
-read resp
-case $resp in
+set_arbitrary_defaults() {
+cyls_per_disk=$DEFCYLN
+tracks_per_cyl=$DEFHEAD
+sects_per_track=$DEFSECT
+unused_last_part=3
+part_cnt=4
+}
+
+
+get_fdisk_data() {
+cyls_per_disk=
+part_id=
+got_sysid=
+part_cnt=0
+sysid_cnt=0
+have_opsys_part=
+unused_last_part=
+extent_max=0
+extent_max_part=
+
+fdisk /dev/r${drivename}d >fdisk.out 2>fdisk.err
+if [ $? -gt 0 ]; then
+ echo "Can't open /dev/r${drivename}d for reading!"
+ set_arbitrary_defaults
+ >fdisk.out
+ >fdisk.err
+ return 2
+elif [ -s fdisk.err ]; then
+ echo "Disk doesn't appear to be initialized..."
+ no_part_table=1
+fi
+while read data; do
+ if [ ! "$cyls_per_disk" ]; then
+ cyls_per_disk=`expr "$data" : '[^=]*=\([0-9]*\)'`
+ tracks_per_cyl=`expr "$data" : '[^=]*=[^=]*=\([0-9]*\)'`
+ sects_per_track=`expr "$data" : '[^=]*=[^=]*=[^=]*=\([0-9]*\)'`
+ continue
+ fi
+ if [ "$got_sysid" ]; then
+ start_part=`expr "$data" : '[^0-9]*\([0-9]*\)'`
+ size_part=`expr "$data" : '[^0-9]*[0-9]*[^0-9]*\([0-9]*\)'`
+ extent_part=`expr $start_part + $size_part`
+ if [ $extent_part -gt $extent_max ]; then
+ extent_max=$extent_part
+ extent_max_part=$part_id
+ fi
+ eval start${part_id}=$start_part
+ eval size${part_id}=$size_part
+ sysid_cnt=`expr $sysid_cnt + 1`
+ got_sysid=
+ part_id=
+ elif [ "$part_id" ]; then
+ sysid=`expr "$data" : 'sysid \([0-9]*\)'`
+ if [ "$no_part_table" -o "$sysid" = "0" -o \
+ "$(expr "$data" : '\(<UNUSED>\)')" = "<UNUSED>" ]; then
+ unused_last_part=$part_id
+ part_id=
+ continue
+ fi
+ [ "$sysid" = "$OPSYSID" ] && have_opsys_part=$part_id
+ eval sysid${part_id}=$sysid
+ got_sysid=1
+ else
+ part_id=`expr "$data" : 'The data[^0-9]*\([0-9]*\)'`
+ beg_cyl=`expr "$data" : '[ ]*beg[^0-9]*\([0-9]*\)'`
+ end_cyl=`expr "$data" : '[ ]*end[^0-9]*\([0-9]*\)'`
+ if [ "$part_id" ]; then
+ part_cnt=`expr $part_cnt + 1`
+ elif [ "$beg_cyl" ]; then
+ if [ $beg_cyl -gt $cyls_per_disk ]; then
+ no_part_table=1
+ sysid_cnt=0
+ have_opsys_part=0
+ unused_last_part=`expr $part_cnt - 1`
+ fi
+ elif [ "$end_cyl" ]; then
+ if [ $end_cyl -gt $cyls_per_disk ]; then
+ no_part_table=1
+ sysid_cnt=0
+ have_opsys_part=0
+ unused_last_part=`expr $part_cnt - 1`
+ fi
+ fi
+ fi
+done <fdisk.out
+if [ ! "$cyls_per_disk" ]; then
+ set_arbitrary_defaults
+ return 2
+fi
+>fdisk.out
+>fdisk.err
+return 0
+}
+
+analyze_fdisk_data() {
+# Case I: >1024 cylinders
+force_offset=
+if [ $cyls_per_disk -gt 1024 ]; then
+ echo
+ echo "WARNING: >1024 cylinders."
+ echo -n "Overwriting existing partitions - okay? [y] "
+ read resp junk
+ [ ! "$resp" ] && resp=y
+ case "$resp" in
+ y*|Y*)
+ RUN_FDISK=""
+ force_offset=1
+ opsys_off=0
+ cyls_per_opsys=${cyls_per_disk}
+ opsys_part=${unused_last_part:-3}
+ return 0
+ ;;
+ *)
+ echo
+ echo "If the number of disk cylinders does not exceed 1024, then ${OPSYSTEM}"
+ echo "can be installed alongside other operating systems on a single disk."
+ echo "Otherwise, it is system-dependent whether this will work or not."
+ echo "In the worst case, ${OPSYSTEM} MUST be installed at the beginning of"
+ echo "the disk, and existing partitions will be lost."
+ echo
+ echo "For now, we will assume that >1024 cylinders creates no problems..."
+ # FALL THROUGH
+ ;;
+ esac
+fi
+# Case II: no partitions used
+if [ $sysid_cnt -eq 0 ]; then
+ echo
+ echo "WARNING: partition table is either missing or corrupt."
+ echo "Existing partitions will be lost."
+ part_cnt=${part_cnt:-4}
+ RUN_FDISK="overwrite"
+ opsys_off=1
+ cyls_per_opsys=`expr ${cyls_per_disk} - 1`
+ opsys_part=${unused_last_part:-3}
+ return 0
+# Case IIIa: overwrite an existing 386BSD/NetBSD/FreeBSD partition
+elif [ "$have_opsys_part" ]; then
+ echo
+ echo "386/Net/FreeBSD partition already exists!"
+ echo -n "Overwriting existing partition - okay? [y] "
+ read resp junk
+ [ ! "$resp" ] && resp=y
+ case "$resp" in
+ y*|Y*)
+ # Set existing partiton values as default (after adjusting to
+ # cylinder boundaries)
+ eval opsys_size=\$size${have_opsys_part}
+ eval opsys_start=\$start${have_opsys_part}
+ [ $opsys_size -eq 50000 ] && opsys_size=$disksize
+ opsys_off=`expr $opsys_start / $cylindersize`
+ opsys_adjusted=`expr $opsys_off \* $cylindersize`
+ if [ $opsys_adjusted -lt $opsys_start -o $opsys_off -eq 0 ]; then
+ opsys_off=`expr $opsys_off + 1`
+ opsys_adjusted=`expr $opsys_off \* $cylindersize`
+ opsys_size=`expr $opsys_size - $opsys_adjusted + $opsys_start`
+ fi
+ cyls_per_opsys=`expr $opsys_size / $cylindersize`
+ opsys_part=${have_opsys_part}
+ RUN_FDISK="fdisk -u"
+ return 0
+ ;;
+ *)
+ have_opsys_part=
+ # FALL THROUGH
+ ;;
+ esac
+fi
+
+# Case IIIb: no partitions available
+if [ $sysid_cnt -eq $part_cnt -a ! "$have_opsys_part" ]; then
+ echo
+ echo "No unused partitions."
+ echo "$OPSYSTEM cannot selectively overwrite existing partitions."
+ echo -n "Install $OPSYSTEM and overwrite the entire disk? [n] "
+ read resp junk
+ case "$resp" in