#!/bin/sh
#############################
# mu: muLinux builder
# M. Andreoli (c) 1998-2003
#############################

#set -x

# Syntax

usage()
{
clear
cat <<END
mu : mulinux composer, (C) M. Andreoli 
=========================================
Options:

	-unpack|-u		unpack  muLinux images in this dir.
	-rebuild|-r		rebuild muLinux BASE floppy's image	
	-x11,-gcc,-srv,-wks, ...
	-tcl,-vnc,-tex,-perl,-ns1,-ns2 
	-emu			Rebuild an add-on
				
	-install|-i [model]	installation Menu: copy to floppy disk
	-tgz			make muLinux tgz	
	-lsm			make muLinux LSM	

	-login|-l		start a "muLinux Hard-Disk session" 
				Use with care! You can leave "core" around
				in muLinux file-system!
	-iso			create a bootable ISO image of MU (NEW)


Notes
--------
The "MU" script requires command as: "lilo","fdformat" or "mkfs.ext2".
If it fails using yours, please try unpacking the image: "mu -u".
After that, "MU" will try to use its own version of these commands. 
END
exit 1
}

[ $# = 0 ] && usage

#
# Local (configurable) data
#
PWD=${PWD:-`pwd`}
DIR=${PWD}
TREE=$DIR/tree	# mulinux fs tree
MKE2FS="LD_LIBRARY_PATH=`pwd`/tree/lib `pwd`/tree/usr/bin/mkfs.ext2"
#MKE2FS="mkfs.ext2"
TREE=$DIR/tree	# mulinux fs tree
MKFS_OPT="-r0 -F -q -m 0"

NEW_KERNEL=

if [ "`which fsck.ext2`" ] ; then
	FSCK=fsck.ext2
else
	FSCK=echo
fi

TMP=$DIR/tmp
mkdir -p $TMP 2>/dev/null

case "`uname`" in
Linux)
	lsmdate=`date '+%d%b%y'`
	;;
muLinux)
	lsmdate=`date`
	echo "You are using 'mu' under muLinux itself ..." 
	;;
esac	

# Include some mulinux basic config file

. mu.cnf 

#


mount_point=$DIR/mnt
super_floppy=/dev/${FLOPPY}${SIZE}

TGZ=mulinux-$VERSION.tgz

umount $mount_point 2>/dev/null

if [ ! -b $super_floppy ] ; then
	mknod $super_floppy b $MAJOR $MINOR ||{ echo ERROR;exit; }
fi

[ -d $mount_point ] || mkdir $mount_point       || { echo ERROR;exit; }


#--------------------------
# Utilities 
#--------------------------

# the DIRTY hack
# in kernels 2.4.* we have to use a preformatted ext2
# because the ext2 sizes may vary randomly!

create_old_ext2()
{
FS=$1
echo "warning: replacing $FS with old preformatted ext2fs ..."
cat $DIR/etc/ext2.gz | gzip -d > $FS
}



LILO()
{
my_lilo="$DIR/bin/lilo"
export LD_LIBRARY_PATH="$DIR/tree/lib:$DIR/tree/usr/lib"
LD="$DIR/tree/lib/ld-linux.so.1"
LD=""
eval $LD ${my_lilo} $@
}


SUPERFORMAT()
{
cmd=$DIR/bin/fdformat
eval $cmd $@
}



abort()
{
if [ $# -ne 0 ] ; then
	echo "Aborting $@ ..."
else
	echo "Some error occurred. Abort."
fi
exit 1
}


msg()
{
echo "-----------------------------------"
echo "$@"
echo "-----------------------------------"
}

filesize()
{
set -- `du -k $1`
echo $1
}


Format()
{
device=$1
shift 1
msg=$*

case "$device" in
*/dev/${FLOPPY}1722*)
	op=superformat;
	;;
*/dev/${FLOPPY}1440*)
        op=format;
        ;;
*)
        op=superformat
	;;
esac

if [ -z "$msg" ] ; then
	msg="Insert your best diskette."
fi

echo
echo $msg 
echo -n "Do You want to ${op} it (y/n) ? [y]> "
read ans

  if [ "${ans}" = y ] || [ -z "$ans" ] ; then
  msg "$op:  please wait ..."
  SUPERFORMAT $device
  else
  echo "Assuming a floppy-disk pre-${op}ted."
  sleep 1
  echo
  fi

}

# check if loop is supported in the kernel

have_loop()
{
loop=/tmp/loop
mnt=/tmp/mnt; mkdir -p $mnt || exit 
dd if=/dev/zero of=$loop bs=1k count=100 2>/dev/null
mkfs.ext2 -qF $loop 
rc=0
mount -o loop $loop $mnt 2>/dev/null || rc=1
umount $mnt 2>/dev/null


if [ $rc != 0 ] ; then
cat <<END
Sorry: missing loopback device support.
Recompile Your LINUX  kernel and answer YES at CONFIG_BLK_DEV_LOOP prompt.
Exit.
END
        exit
else
        echo "loop filesystem supported: good."
fi

return $rc
}

check_id()
{
if [ "$(id -u)" -ne 0 ] ; then
        msg "You should become 'root'. Abort"
	exit 1
fi
}


prerequisites()
{


have_loop || exit 1

# check -O option (new e2fsprogs > 1.8)

$MKE2FS -h 2>&1 | grep "\-O" > /dev/null
rc=$?

if [ $rc -eq 0 ] ; then
	#echo "your e2fsck support the -O option: assuming -O none"
	MKFS_OPT="$MKFS_OPT -O none"
else
	:
	#echo "your e2fsck do not support -O option"
fi


# The big problem with 2.4.* kernels :-)

ver=$(uname -r)

case $ver in
2.4.*)
export NEW_KERNEL=y
cat <<END
WARNING! Making mulinux BASE images using a 2.4.* kernel series give now
some trouble: images BOOT, ROOT and USR may changes sizes randomly.  
As result, they may not fit in a single floppy disk. Sorry!!

I suggest you to boot muLinux and to run "mu -r" from it.

END

read -p "continue anyway? (y/n) " a
[ "$a" = "n" ] && exit 1
;;
esac
}

#-------------------------
# Configuration functions
#-------------------------


# build a lilo.conf

make_lilo()
{
FF=$1
STARTUP_DEVICE=/dev/$FLOPPY$FF

cat <<END
#
# lilo.conf for muLinux (build by mu script)
#
boot=$STARTUP_DEVICE
install=/boot/boot.b
map=/boot/map
message=/boot/mulinux.msg
backup=/dev/null

read-write
vga=normal
prompt
delay=40
timeout=50

image=/boot/mulinuz
label=mulinux
root=$STARTUP_DEVICE
append="f$FF load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=4600  \
ramdisk_start=$ROOT_OFFSET vga=ask $KERNEL_BOOT_PARAMETERS"


END
}

clean()
{
find $TREE -name core -exec rm -i \{} \;
rm -fr $TREE/tmp/*
rm -f $TREE/var/tmp/*
rm -f $TREE/var/log/*
rm -f $TREE/var/lock/*

}

update_ld_cache()
{
if [ -f $TREE/usr/srv/bin/ldconfig ]; then
	msg "Updating /etc/ld.so.cache ..."
	chroot $TREE /usr/srv/bin/ldconfig
fi
}

rebuild()
{
msg "Check prerequisites ..."
prerequisites
> free
clean



#-------------------------------
# USR partition
#-------------------------------

msg "building USR.bz2 ...please, standby."

# USR_RAW_SIZE is in mu.cnf 

dd if=/dev/zero of=USR bs=1k count=$USR_RAW_SIZE
echo
eval $MKE2FS $MKFS_OPT -i ${USR_INODES} USR 

[ "$NEW_KERNEL" ] && create_old_ext2 USR


umount $mount_point 2>/dev/null
mount -o loop USR $mount_point
rm -r $mount_point/lost*


cd $TREE/usr
usr_list="`/bin/ls| grep -v X11| grep -v emu |grep -v srv | grep -v wks| \
grep -v jvm |\
grep -v local | grep -v tcl |\
grep -v gcc | grep -v c++ | grep -v vnc | \
grep -v tex | grep -v perl | grep -v ns`"
cp -a ${usr_list} $mount_point
df | grep USR
umount $mount_point
cd $DIR
#fsck.ext2 USR
rm USR.bz2 2>/dev/null
bzip2 -9 USR

USR_SIZE=`filesize USR.bz2`

#-------------------------------
# BOOT partition
#-------------------------------

# BOOT_FREE is set in mu.cnf

msg "building BOOT.raw : please, standby ..."

set -- `du -k -s $TREE/startup`

ROOT_OFFSET=`expr $1 + $BOOT_FREE`


dd if=/dev/zero of=BOOT.raw bs=1k count=$ROOT_OFFSET >/dev/null 2>&1
echo
eval $MKE2FS $MKFS_OPT BOOT.raw 2>&1 >/dev/null

[ "$NEW_KERNEL" ] && create_old_ext2 ROOT 

mount -o loop BOOT.raw $mount_point >/dev/null 2>&1 
rm -r $mount_point/lost* 2>/dev/null

cp -af $TREE/startup/* $mount_point



# Second step -> accurate size
set -- `du -k -s $mount_point`
ROOT_OFFSET=`expr $1 + $BOOT_FREE`
umount $mount_point
dd if=/dev/zero of=BOOT.raw bs=1k count=$ROOT_OFFSET
eval $MKE2FS $MKFS_OPT BOOT.raw
mount -o loop BOOT.raw $mount_point
rm -r $mount_point/lost* 2>/dev/null
cp -af $TREE/startup/* $mount_point
umount $mount_point


BOOT_SIZE=`filesize BOOT.raw`

$FSCK -y BOOT.raw >> $DIR/free

#-------------------------------
# ROOT partition
#-------------------------------


msg "building ROOT.gz ... please, standby."

# some link

cd $TREE/dev
rm root 2>/dev/null
ln -s $ROOT_DEVICE root 

# check what gets copied

cd $TREE
root_list=`/bin/ls | grep -v usr | grep -v startup`


# ROOT_RAW_SIZE is set in mu.cnf

cd $DIR
dd if=/dev/zero of=ROOT bs=1k count=$ROOT_RAW_SIZE
echo
eval $MKE2FS $MKFS_OPT -i ${ROOT_INODES}  ROOT  


mount -o loop ROOT $mount_point
rm -r $mount_point/lost*


cd $TREE
cp -a ${root_list} $mount_point

echo $VERSION > $mount_point/etc/version
cat > $mount_point/etc/info <<END
VERSION=$VERSION
DATE="`date`"
END

cd  $DIR 
df | grep ROOT
umount $mount_point

#$FSCK -y ROOT >> $DIR/free

# ROOT size 
 
gzip -9 -f ROOT
rs=`filesize ROOT.gz`
ROOT_SIZE=`expr $rs + 1`	# 1=overlap security
USR_OFFSET=`expr $ROOT_OFFSET + $ROOT_SIZE`

# enlarge ROOT.gz to effective ROOT_SIZE

cp ROOT.gz  ROOT.tmp
dd if=ROOT.tmp bs=${ROOT_SIZE}k conv=sync count=1 of=ROOT.gz
rm ROOT.tmp

# make some lilo.conf

make_lilo 1440 > lilo.1440
make_lilo 1722 > lilo.1722

# some info (put it in BOOT )

cat > info <<END
VERSION=$VERSION
DATE="`date`"
SIZE=$SIZE
# USR
USR_MEDIA=$SIZE
USR_OFFSET=$USR_OFFSET
# on-the-fly
END

cp info $TREE/startup/boot/info

TOT=`expr $USR_OFFSET + $USR_SIZE`

echo "BOOT=$BOOT_SIZE, ROOT=$ROOT_SIZE, USR=$USR_SIZE, Total $TOT" |\
tee /dev/console | cat >> free 

FREE=`expr $SIZE - $TOT`

echo "$FREE k-bytes (uncompressed) free." |tee /dev/console | cat >> free
echo

#-------------------------------
#  Build Standard muLinux   
#-------------------------------

msg "Building BOOT+ROOT+USR base system .."
echo "[ Other model with 'mu -i' ]"

cat free

Format $STARTUP_DEVICE "Insert your best diskette"


echo "Copy BOOT.raw+ROOT+USR ..."
cat BOOT.raw ROOT.gz USR.bz2 > $STARTUP_DEVICE
msg "Add LILO ..."
mount $STARTUP_DEVICE $mount_point
# add info into BOOT
cp info  $mount_point/boot/info
cat lilo.$SIZE | LILO -r $mount_point -C -
umount $mount_point

# take this!
msg "Getting BOOT ... Please, standby."
dd if=$STARTUP_DEVICE of=BOOT bs=1k count=$ROOT_OFFSET

msg "Done. Reboot now and have fun!"

}

#---------------
# addons
#---------------

rebuild_multi_disk_addon()
{
name=$1; shift; mp=$*
cd $TREE

msg "Compressing $mp ..."
tmp=/tmp/a$$

$TAR -cf- $mp | gzip -c > $tmp
set -- `du -sk $tmp`
kb=$1
last=`expr $kb % 1440`
rem=`expr 1440 - $last`
tot=`expr $kb / 1440`
tot=`expr $tot + 1`
echo "Total number of floppies required by $name: $tot"
echo "Kbytes remaining on the last floppy disk for $name: $rem k"
echo
echo "Put volume #1 of /dev/fd0 and hit return ..."
read enter
$TAR -M -cf /dev/fd0 $tmp 
rm $tmp 

}


rebuild_addon()
{
name=$1; shift; mp=$*

[ ! -d $TREE/$mp ] && echo "error" && exit 1

msg "building $name.tgz ($mp) ...please, standby."

clean

cd $TREE
tar -cf- $mp | bzip2 > $DIR/$name.tgz
cd $DIR
SIZE=`filesize $name.tgz`
echo "`du -k $name.tgz`"
}

# INSTALL : model management

install()
{

if [ $# = 0 ] ; then
clear
cat << END
			- MuLinux Floppy Composer -

0)	Boot-prompt-Parameters settings

** BASE floppy models:
1)	BOOT+ROOT+USR (1722K) 
2)	BOOT+ROOT (1440K) and USR (1440K)
3)	BOOT+ROOT (1440K) and USR (1722K)
4)	BOOT+ROOT (1722K) and USR (1722K)
lm)	BOOT+ROOT (1440K) and USR (1440K), USR gzipped (NEW!)

** ADD-ONS:
s) SRV  w) WKS x) X11 g) GCC t) TCL v) VNC tex) TEX 
p) PERL emu) EMU ns1) NS1 ns2) NS2 
j) JVM

q)	quit

NOTE:

- check the 'free' file for best choice. Image must fit in the floppy. 
- 1440K floppy boot faster, compared to 1722K.
- muLinux standard is : BOOT+ROOT+USR and SRV (and/or WKS) 
- Select the "lm" (low memory) model if destination machine is lowmem.

END

	echo -n "Choice [1]> "
	read floppy 
	[ -z "$floppy" ] && floppy="1"
else
	floppy=$1
fi

echo
echo "Choice : $floppy."
echo

case $floppy in
q)
	exit
	;;
0)
	clear
	cat << END

	            - BOOT PROMPT PARAMETERS -	

 IMPORTANT NOTE TO MODULE USERS: Boot Prompt arguments typically only
 apply to hardware drivers that are compiled directly into the kernel.
		
Examples:
	mem=16M			# how much memory you have
	vga=normal|extended	# vga spec.
	aha152x=0x340,11,7,1	# SCSI for Iomega ZIP
	hd=cyls,heads,sects	# disk geometry
	msmouse=irq		# irq for M$ bus mouse
	root=/dev/hdc3		# mount this root	
	no387			# use internal math emulator
	
Blank separated list allowed.

END

	read -p "Enter boot-prompt string :" KERNEL_BOOT_PARAMETERS
	echo "You have entered: $KERNEL_BOOT_PARAMETERS"

	make_lilo 1440 > lilo.1440
	make_lilo 1722 > lilo.1722

	echo "Done."
	sleep 1 
	./mu -i
	;;
1)
        Format /dev/${FLOPPY}1722 "Insert BOOT+ROOT+USR floppy"
        msg "copy BOOT+ROOT+USR ..."
        cat BOOT ROOT.gz USR.bz2 > /dev/${FLOPPY}1722
        echo "Done. Reboot now."
        ;;
2)
        Format /dev/${FLOPPY}1440 "Insert BOOT+ROOT floppy"
        msg "copy BOOT+ROOT ..."
        cat BOOT ROOT.gz > /dev/${FLOPPY}1440
        mount /dev/${FLOPPY}1440 $mount_point
	rm $mount_point/boot/map
        msg "Add LILO loader  ..."
        cat lilo.1440 | LILO -r $mount_point -C -

	echo "USR_MEDIA=1440" >> $mount_point/boot/info
	echo "USR_OFFSET=0" >> $mount_point/boot/info

	umount $mount_point

        Format /dev/${FLOPPY}1440 "Insert USR floppy"
        msg "copy USR.bz2 ..."
        cat USR.bz2 > /dev/${FLOPPY}1440
        echo "Done. Insert boot floppy and Reboot."

        ;;
lm)
        Format /dev/${FLOPPY}1440 "Insert BOOT+ROOT floppy"
        msg "copy BOOT+ROOT ..."
        cat BOOT ROOT.gz > /dev/${FLOPPY}1440
        mount /dev/${FLOPPY}1440 $mount_point
        rm $mount_point/boot/map
        msg "Add LILO loader  ..."
        cat lilo.1440 | LILO -r $mount_point -C -

        echo "USR_MEDIA=1440" >> $mount_point/boot/info
        echo "USR_OFFSET=0" >> $mount_point/boot/info

        umount $mount_point

        Format /dev/${FLOPPY}1440 "Insert USR floppy"
	msg "converting USR.bz2 -> USR.gz on-the-fly, copying ..."
	cat USR.bz2 | bzip2 -ds | gzip -c > /dev/${FLOPPY}1440
        echo "Done. Insert boot floppy and Reboot."

        ;;

3)
        Format /dev/${FLOPPY}1440 "Insert BOOT+ROOT floppy"
        msg "copy BOOT+ROOT ..."
        cat BOOT ROOT.gz > /dev/${FLOPPY}1440
        mount /dev/${FLOPPY}1440 $mount_point
        rm $mount_point/boot/map
        msg "Add LILO loader  ..."
        cat lilo.1440 | LILO -r $mount_point -C -

        echo "USR_MEDIA=1722" >> $mount_point/boot/info
        echo "USR_OFFSET=0" >> $mount_point/boot/info

        umount $mount_point

        Format /dev/${FLOPPY}1722 "Insert USR floppy"
        msg "copy USR.bz2 ..."
        cat USR.bz2 > /dev/${FLOPPY}1722
        echo "Done. Insert boot floppy and Reboot."
	;;
4)
        Format /dev/${FLOPPY}1722 "Insert BOOT+ROOT floppy"
        msg "copy BOOT+ROOT ..."
        cat BOOT ROOT.gz > /dev/${FLOPPY}1722
        mount /dev/${FLOPPY}1722 $mount_point

        echo "USR_MEDIA=1722" >> $mount_point/boot/info
        echo "USR_OFFSET=0" >> $mount_point/boot/info

        umount $mount_point

        Format /dev/${FLOPPY}1722 "Insert USR floppy"
        msg "copy USR.bz2 ..."
        cat USR.bz2 > /dev/${FLOPPY}1722
        echo "Done. Insert boot floppy and Reboot."
	;;
x)
	Format /dev/${FLOPPY}1722 "Insert X11 floppy"	
	msg "copy X11 ..."
	cat X11.tgz > /dev/${FLOPPY}1722
	echo "Done."
	;;
j)
        Format /dev/${FLOPPY}1722 "Insert JVM floppy"
        msg "copy JVM ..."
        cat JVM.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;

ns1)
        Format /dev/${FLOPPY}1722 "Insert NS1 floppy"
        msg "copy NS1 ..."
        cat NS1.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
ns2)
        Format /dev/${FLOPPY}1722 "Insert NS2 floppy"
        msg "copy NS2 ..."
        cat NS2.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
t)
        Format /dev/${FLOPPY}1722 "Insert TCL floppy"
        msg "copy TCL ..."
        cat TCL.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
v)
        Format /dev/${FLOPPY}1722 "Insert VNC floppy"
        msg "copy VNC ..."
        cat VNC.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
tex)
        Format /dev/${FLOPPY}1722 "Insert TEX floppy"
        msg "copy TEX ..."
        cat TEX.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
p)
        Format /dev/${FLOPPY}1722 "Insert PERL floppy"
        msg "copy PERL ..."
        cat PERL.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
emu)
        Format /dev/${FLOPPY}1722 "Insert EMU floppy"
        msg "copy EMU ..."
        cat EMU.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
s)
        Format /dev/${FLOPPY}1722 "Insert SRV floppy"
        msg "copy SRV ..."
        cat SRV.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
w)
        Format /dev/${FLOPPY}1722 "Insert WKS floppy"
        msg "copy WKS ..."
        cat WKS.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
g)
        Format /dev/${FLOPPY}1722 "Insert GCC floppy"
        msg "copy GCC ..."
        cat GCC.tgz > /dev/${FLOPPY}1722
        echo "Done."
        ;;
*)
	echo "Model unsupported."
	sleep 1
	install	
	;;
esac
sync
}


unpack()
{

msg "Unpacking ...."
msg "Check prerequisites ..."
prerequisites

umount $mount_point 2>/dev/null

if [ -d $TREE ] ; then
	echo "Found a $TREE/ dir. Do You want continue anyway? (y/n) [y]"
	read ans ; [ -z "$ans" ] && ans=y
	[ "$ans" = n ] && exit 0 
fi 
rm -r $TREE 2>/dev/null

mkdir -p $TREE 
mkdir -p $TREE/startup

msg "unpack BOOT ..."
cp BOOT $TMP/BOOT || abort
mount -o loop $TMP/BOOT $mount_point
cp -af $mount_point/* $TREE/startup 
umount $mount_point
rm -f $TMP/BOOT

msg "unpack ROOT.gz ..."
cp ROOT.gz $TMP/ROOT.gz || abort

gzip -d $TMP/ROOT.gz 2>/dev/null
mount -o loop $TMP/ROOT $mount_point
cp -af $mount_point/* $TREE 
umount $mount_point
rm -f $TMP/ROOT

msg "unpack USR.bz2"
cp USR.bz2 $TMP || abort
bzip2 -d $TMP/USR.bz2 
mount -o loop $TMP/USR $mount_point

mkdir -p $TREE/usr
cp -af $mount_point/* $TREE/usr
umount $mount_point
rm -f $TMP/USR

for a in `cat $TREE/setup/model/addons`
do
if [ -r $a.tgz ] ; then
msg "unpack $a.tgz"
cat $a.tgz| bzip2 -ds | (cd $TREE; tar -xvf- ) 
fi
done


echo
msg "muLinux tree is now tree/"
echo "Done."
}

make_tgz()
{

msg "Creating main $TGZ"

tar -cf mu.tar \
mu mu.cnf info free lilo.1440 lilo.1722 \
doc CHANGES INSTALL.* mulinux-$VERSION.lsm contrib sources \
bin \
BOOT ROOT.gz USR.bz2 

gzip -c mu.tar > $TGZ 
rm mu.tar 

if [ $(which md5sum) ] ; then
	md5sum *.tgz *.zip > md5sum
else
	> md5sum
fi

make_144_installer

cd $DIR
msg "Creating DOSTOOLS "
rm -f DOSTOOLS.zip
unix2dos < INSTALL.Dos > dos/zip/README.txt
cd dos/zip                                                                          
#tar -h -cf - * | gzip -9 > ../DOSTOOLS.tgz
zip $DIR/DOSTOOLS.zip * 
cd $DIR

echo "Done."
}


make_lsm()
{

cat > mulinux-${VERSION}.lsm <<END
Begin3
Title:		muLinux	
Version:	${VERSION}
Entered-date:  	${lsmdate} 
Description:	Full-configured, application-centric floppy Linux. 
		muLinux is a minimalistic, full-configured, script-based 
		Linux distribution. Basically, muLinux fit on a 
		a single 1722K floppy, but pluggable floppy addons are
		available (currently X11, GCC, ...) 
	        Work on PC 386-4M + swap and install in RAM, UMSDOS & EXT2.
        	BASE floppy: Internet (via PPP) or LAN (via eth);
        	e-mail processing (fetch, read and send), NFS, SAMBA, ftp, 
		IRC, finger, telnet, tcpdump, news and web browsing (lynx);
		PC-PC link via pppd; IP firewall & IP masqueranding; 
        	remote access via modem line (miterm); editing&printing;
        	fdisk,e2fsck, fdformat ; job scheduler (atd), ringd daemon,
        	WWW server, dialin server, serial server, fax server;
		Pion file manager with ftp virtual file system; diald;
        	play & record WAV, CD listening (workbone), say, etc. :)
        	OTHER FEATURES: international keyboards support, BUS mouse,
        	PAP/CHAP authentication, permanent multi-configuration,
        	installation from LINUX/DOS/WINDOWS, PC speaker support,
		NFS-root booting for diskless Xterminal applications,
		DHCP remote host configuration. 

Keywords:	QNX, linux, spaghetti-linux 
Author: 	andreoli@pisoft.it (Michele Andreoli)
Maintained-by:	andreoli@pisoft.it (Michele Andreoli)
Primary-site:	http://sunsite.auc.dk/mulinux/	
		`du -b mulinux-${VERSION}.tgz`	
		`du -b DOSTOOLS.zip`	
		`du -b X11.tgz`	
		`du -b GCC.tgz`	
Alternate-site:	sunsite.unc.edu /pub/Linux/system/recovery
		`du -b mulinux-${VERSION}.tgz`	
		`du -b mulinux-${VERSION}.lsm`	
Platforms:	Dos/Win9x/Linux
Copying-policy:	GPL
End
END

}

# make installer 1.44 floppy

make_144_installer()
{
msg "Creating 1.44 installer"
cd $DIR/dos
dd if=/dev/zero of=zip/syslinux.img bs=1k count=1440
mkdosfs zip/syslinux.img
mnt=$DIR/mnt
mount -o loop zip/syslinux.img $mnt -t msdos
cp -a disk/* $mnt
#cp $DIR/tree/startup/boot/mulinuz $mnt
umount $mnt
msg "Installing SYSLINUX bootloader ..."
dd if=disk/mbr of=zip/syslinux.img conv=notrunc
msg "Getting syslinux.img ..."
}


# run a chroot script able to create the
# iso image of the system in tree/ws

make_iso()
{
ISO=/tmp/mulinux-$VERSION.iso
check_id

clean
msg "ISO Image creation. Please, wait "
BTREE=/tmp/tree; mkdir -p $BTREE
rm -r $TREE/ws 2>/dev/null
msg "creating a copy of tree/ in /tmp ... wait"
cp -a $TREE/* $BTREE
msg "creating the iso image ..."
chroot  $BTREE /usr/clone/clone.iso
msg "moving to $ISO ..."
mv $BTREE/ws/master.iso $ISO
msg "cleanup ..."
rm -r $BTREE 
du $ISO
msg "Finish. You can burn the file [$ISO] with cdrecord or Nero. Good Luck"
}



#---------------------------
# Begin Main
#---------------------------

msg "muLinux V${VERSION}"


case $1 in
-a)
	shift
	rebuild_addon $1 $2
	;;
-x|-x11)
	rebuild_addon X11 usr/X11R6
	;;
-svga)
	rebuild_addon SVGA usr/svga
	;;
-tcl)
	rebuild_addon TCL usr/tcltk
	;;
-vnc)
	rebuild_addon VNC usr/vnc
	;;
-tex)
	rebuild_addon TEX usr/tex
	;;
-gcc)
	rebuild_addon GCC usr/gcc 
	;;
-perl)
	rebuild_addon PERL usr/perl 
	;;
-emu)
	rebuild_addon EMU usr/emu 
	;;
-srv)
	rebuild_addon SRV usr/srv
	;;
-wks)
	rebuild_addon WKS usr/wks
	;;
-ns1)
	rebuild_addon NS1 usr/ns/bin
	;;
-ns2)
        rebuild_addon NS2 usr/ns/lib
        ;;
-jvm)
        rebuild_addon JVM usr/jvm
        ;;
-rebuild|-r) 
	rebuild
	;;
-install|-i) 
	shift 1
	install $1	
	;;
-unpack|-u) 
	unpack	
	;;
-lsm)
	make_lsm
	;;
-tgz) 
	make_lsm
	make_tgz	
	;;
-login|-l)
	echo "Welcome to muLinux V${VERSION}"
	chroot $TREE -ash
	;;
-iso)
	make_iso
	;;
-144)
	make_144_installer
	;;
-h)	usage
	
	;;
*)	usage	
    	;;
esac


# End
