#!/bin/bash

. bk_functions

yesno "Create utility diskette?"

if [ "$?" != 0 ]
then
	exit
fi

yesno "$DISKETTEDEV will be destroyed! Continue?"

if [ "$?" != 0 ]
then
	exit
fi

msgbox "Insert diskette in $DISKETTEDEV"

infobox "Creating ext2 filesystem on $DISKETTEDEV"

mke2fs $DISKETTEDEV >/tmp/bootkit.log 2>&1
if [ $? -ne 0	]
then
	msgbox "mke2fs failed!"
	bkViewLog /tmp/bootkit.log
	exit
fi

#
infobox "Mounting floppy on $MOUNTPOINT"

mount -t ext2 $DISKETTEDEV $MOUNTPOINT >> /tmp/bootkit.log 2>&1

if [ $? -ne 0 ]
then
	msgbox "Unable to mount floppy!"
  	bkViewLog /tmp/bootkit.log
	exit
fi

# copy the directories containing files
for i in ./util_conf/files.*
do
	infobox "Copying files for $i directory"

	while read fname
	do	
		cp -dpP $fname $MOUNTPOINT >>/tmp/bootkit.log 2>&1
	done < $i
done

# create empty directories required
infobox "Creating additional directories"

if [ -f ./util_conf/dirs.extra ]
then
	while read dirname
	do
		if [ ! -d "$MOUNTPOINT$dirname" ]
		then
			mkdir $MOUNTPOINT$dirname >>/tmp/bootkit.log 2>&1
		fi
	done < ./util_conf/dirs.extra
fi

# Copy any additional files or links found in the "util_skel" directory
infobox "Copying additional user-defined files"
cp -pR ./util_skel/* $MOUNTPOINT >> /tmp/bootkit.log 2>&1

infobox "Syncing floppy disk"
sync
sleep 2

umount $MOUNTPOINT

msgbox "Utility diskette creation completed"

# Give the user a chance to view the log file
bkViewLog /tmp/bootkit.log

