#!/bin/ash
# (C) Robert Shingledecker <robert@damnsmalllinux.org> 2004
clear
echo "DSL poorman's Install and Boot Floppy via Net"
echo
echo "No responsibilty for data loss or hardware damage."
echo
echo "You must have created and formatted two empty and unmounted Linux partitions."
echo "1. One large enough to hold the downloaded iso."
echo "2. The other large enough for poorman's install."
echo
echo "You must also have a no bad sectors unmounted floppy inserted into drive."
echo
echo -n "Are you ready to being (y/..): "
read ANS
if test "$ANS" != "y"; then
   exit 1
fi   
echo -n "Enter the partition to hold the iso (eg: hda1): "
read SOURCE
if test "$SOURCE"; then; else
   echo "no source partition entered."
   exit 1
fi   
echo -n "Enter the partition to install into (eg: hda2): "
read TARGET
if test "$TARGET"; then; else
   echo "no target partition entered."
   exit 1
fi   
echo -n "Enter the name of the remote iso file (eg dsl-0.7.1.iso): "
read ISOFILE
if test "$ISOFILE"; then; else
   echo "no iso file entered."
   exit 1
fi   
URL="ibiblio.org/pub/Linux/distributions/damnsmall/current"
mkdir /mnt/$SOURCE
mount -t ext2 /dev/$SOURCE /mnt/$SOURCE
cd /mnt/$SOURCE
echo "Standby fetching the iso..."
wget "ftp://$URL/$ISOFILE"
if test "$?" -eq 1; then
   echo "Could not get iso file at this time."
   echo "Try again later."
   exit 1
fi   
mkdir /mnt/$TARGET
mount -t ext2 /dev/$TARGET /mnt/$TARGET
mkdir /mnt/iso
mount /mnt/$SOURCE/$ISOFILE /mnt/iso -t iso9660 -o loop=/dev/loop0
echo "Installing the compressed image..."
cp -r /mnt/iso/KNOPPIX /mnt/$TARGET
mkdir /mnt/$TARGET/boot
mkdir /mnt/bootimg
echo "Creating the boot floppy..."
dd if=/mnt/iso/KNOPPIX/boot.img of=/dev/fd0
if test "$?" -eq 1; then
   echo "Error trying to create the boot floppy."
   echo "Try again later."
   exit 1
fi   
echo "DSL installation complete."
rm -f "/mnt/$SOURCE/$ISOFILE"
echo "Standby for reboot..."
reboot