#!/bin/sh
############################################################################
##                                                                         #
##   This program is free software; you can redistribute it and/or modify  #
##   it under the terms of the GNU General Public License as published by  #
##   the Free Software Foundation; either version 2 of the License, or     #
##   (at your option) any later version.                                   #
##                                                                         #
############################################################################

bootcdroot=/var/lib/bootcd
drbl_version=`cat drbl_version | grep -e "^Version:" | awk '{ print $2; }'`
kernel_version=2.4.25
kernel_version_0=2.4.22-openmosix
LC_ALL=C

# drbl_version
if [ "$drbl_version" = "" ]; then
  ## try /etc/drbl_version
  if [ -f /etc/drbl_version ]; then
    drbl_version=`cat /etc/drbl_version | grep -e "^Version:" | awk '{ print $2; }'`
  fi
  ##
  if [ "$drbl_version" = "" ]; then 
    echo "Incorrect version in drbl_version, abort..."
    exit
  fi
fi

# must be root
ID=`id -u`
if [ "$ID" != "0" ]; then
  echo "You must be root to use this script."
  echo "Use sudo to enable it for users."
  exit 1
fi

# function: set_non_interactive
set_non_interactive() {

  chroot $bootcdroot apt-get -y install expect

  # non_interactive
  if [ "$1" = "true" ]; then

    cp setdebconf-v0.9 $bootcdroot/root

    cat <<-EOF > $bootcdroot/etc/apt/apt.conf
APT 
{
  // Options for apt-get
  Get 
  {
     Download-Only "false";
     Assume-Yes "true";
     Fix-Broken "true";
  };

  Immediate-Configure "false";
  Force-LoopBreak "true";
};

// Options for the downloading routines
Acquire
{
  Retries "0";
};

// Things that effect the APT dselect method
DSelect 
{
  Clean "auto";   // always|auto|prompt|never
};

DPkg 
{
  // Probably don't want to use force-downgrade..
  Options {"--force-overwrite";}
}
EOF

    cat <<-EOF > $bootcdroot/root/debconf_noninteractive
#!/bin/sh
# \\
exec expect "\$0" \${1+"\$@"}
spawn /usr/sbin/dpkg-reconfigure --frontend=readline debconf
expect "What interface should be used for configuring packages?"
send "5\r"
#expect "Ignore questions with a priority less than.."
expect "See only questions that are of what priority and higher?"
send "1\r"
expect "Show all old questions again and again?"
send "no\r"
expect eof
EOF
    chmod 755 $bootcdroot/root/debconf_noninteractive
    chroot $bootcdroot /root/debconf_noninteractive
    rm -rf $bootcdroot/root/debconf_noninteractive

  # interactive (dialog)
  else

    cat <<-EOF > $bootcdroot/etc/apt/apt.conf
DPkg 
{
  Options { "--force-overwrite"; }
}
EOF

    cat <<-EOF > $bootcdroot/root/debconf_dialog
#!/bin/sh
# \\
exec expect "\$0" \${1+"\$@"}
spawn /usr/sbin/dpkg-reconfigure --frontend=readline debconf
expect "What interface should be used for configuring packages?"
send "1\r"
#expect "Ignore questions with a priority less than.."
expect "See only questions that are of what priority and higher?"
send "3\r"
expect "Show all old questions again and again?"
send "no\r"
expect eof
EOF
    chmod 755 $bootcdroot/root/debconf_dialog
    chroot $bootcdroot /root/debconf_dialog
    rm -f $bootcdroot/root/debconf_dialog
  fi

}

# function: use_mirror
use_mirror() {

  if [ "$1" = "original" ]; then

    cat <<-EOF > $bootcdroot/etc/apt/sources.list
deb http://http.us.debian.org/debian woody main contrib non-free
deb http://non-us.debian.org/debian-non-US woody/non-US main contrib non-free
deb http://non-us.debian.org/debian-security woody/updates main contrib non-free
deb ftp://ftp.oregonstate.edu/pub/kde/stable/3.1/Debian stable main
deb http://www.debian.or.jp/~kmuto/x430 ./
EOF

  else
  
    cat <<-EOF > $bootcdroot/etc/apt/sources.list
deb $1/debian woody main contrib non-free
deb $1/debian-non-US woody/non-US main contrib non-free
deb $1/debian-security woody/updates main contrib non-free
deb $1/apt/kde/3.1 woody main
#deb $1/apt/xfree86-4.3/woody ./
deb $1/apt/drbl ./
EOF
 
  fi
}

no_bootstrap="false"
non_interactive="false"
mirror_site="http://opensource.nchc.org.tw"
noiso="false"

while [ "$1" != "" ]; do
  case "$1" in
    "--no_bootstrap")
      no_bootstrap="true"
      ;;
    "--non_interactive")
      non_interactive="true"
      shift
      case "$1" in
	    "base") cd_to_created=1 ;;
        "drbl") cd_to_created=2 ;;
	    "democd") cd_to_created=3 ;;
        "cluster") cd_to_created=4 ;;
	    *) cd_to_created=2 ;;
      esac
      ;;
    "--interactive")
      non_interactive="false"
      ;;
    "--use-mirror")
      shift
      mirror_site="$1"
      ;;
    "--bootcdroot")
      shift
      bootcdroot="$1"
      ;;
    "--noiso")
      noiso="true"
      ;;
  esac
  shift
done

# install packages and create the directory for cd
if [ "$no_bootstrap" = "true" ]; then
  echo
else
  # Blake,2003/09/24, use 1.0.2 cloop-utils
  #apt-get install bootcd debootstrap binutils wget cloop-utils -y
  apt-get install bootcd debootstrap binutils wget zlib1g build-essential -y
  # Blake, 2003/11/28, drbl debian apt repository
  #dpkg -i ../../deb/cloop-utils_1.02-1_i386.deb
  apt-get install cloop-utils -y
  if [ -e $bootcdroot ]; then
    if [ "$non_interactive" = "false" ]; then
      echo -n "$bootcdroot exists! Do you want to remove it [Y/n]? "
      read ANS
	# Blake, 2004/02/19, for 4 steps installation
    else
      ANS="y"
    fi
	
    if [ "$ANS" = "y" -o "$ANS" = "Y" -o "$ANS" = "" ]; then 
      rm -rf $bootcdroot
    fi
  fi

  # base system
  if [ "$mirror_site" = "original" ]; then debian_mirror="http://http.us.debian.org/debian"
  else debian_mirror="$mirror_site/debian"
  fi

  # Blake, 2004/02/19, for 4 steps installation
  mkdir -p $bootcdroot
  if [ -e base.tgz ]; then
    tar -C $bootcdroot -zxf base.tgz  
  else
    debootstrap --arch i386 woody $bootcdroot $debian_mirror
  fi
  mkdir -p $bootcdroot/opt/drblcd
 
  # base system setup - name
  cat <<-EOF > $bootcdroot/etc/hosts
127.0.0.1	livecd	localhost
140.110.17.49	opensource.nchc.org.tw drbl.nchc.org.tw openoffice.nchc.org.tw
140.110.17.100	fsgrid.nchc.org.tw
EOF
  cat <<-EOF > $bootcdroot/etc/hostname
drblcd
EOF
  rm -f $bootcdroot/etc/resolv.conf
  touch $bootcdroot/etc/resolv.conf

  # base system setup - /etc/apt/source.list
  # Blake, 2004/01/16, use_mirror
  use_mirror $mirror_site
  chroot $bootcdroot apt-get update
 
  # base system setup - /etc/profile & /etc/profile.d
  mkdir -p $bootcdroot/etc/profile.d
  cp common/profile $bootcdroot/etc/

  # base system setup - networking alias
  cp common/init.d/networking-alias $bootcdroot/etc/init.d
  ln -fs ../init.d/networking-alias $bootcdroot/etc/rcS.d/S41networking-alias
  touch $bootcdroot/etc/network/interfaces.alias

  # base system setup - /etc/apt/apt.conf
  # Blake, 2004/01/16, set_non_interactive
  set_non_interactive $non_interactive

  # Blake, 2003/11/28, drbl debian apt repository
  chroot $bootcdroot apt-get -y install kernel-image-$kernel_version kernel-headers-$kernel_version < /dev/null
  if [ "$NO_DEB_TO_SRC" = "" ]; then 
    kernel_image=`ls $bootcdroot/var/cache/apt/archives/kernel-image-$kernel_version*`
    mv $kernel_image $bootcdroot/usr/src
    kernel_headers=`ls $bootcdroot/var/cache/apt/archives/kernel-headers-$kernel_version*`
    mv $kernel_headers $bootcdroot/usr/src
  fi

  # Blake, 2003/12/31, kernel_version_0
  chroot $bootcdroot apt-get -y install kernel-image-$kernel_version_0 kernel-headers-$kernel_version_0 < /dev/null
  if [ "$NO_DEB_TO_SRC" = "" ]; then 
    kernel_image_0=`ls $bootcdroot/var/cache/apt/archives/kernel-image-$kernel_version_0*`
    mv $kernel_image_0 $bootcdroot/usr/src
    kernel_headers_0=`ls $bootcdroot/var/cache/apt/archives/kernel-headers-$kernel_version_0*`
    mv $kernel_headers_0 $bootcdroot/usr/src

    # Blake, 2004/03/12, in 2.4.25, xfs is included
    # Blake, 2003/09/25, XFS patch
    #cp xfs-2.4.22-all-i386 $bootcdroot/usr/src
  fi

  # discover, usbmgr & some addon modules (bcm440x)
  #mount -t proc proc $bootcdroot/proc
  #chroot $bootcdroot apt-get -y install usbmgr
  #cp ../../hwdata/usbmgr/usbmgr.conf $bootcdroot/etc/usbmgr

  # Blake, 2003/11/14, replace usbmgr with hotplug and install knoppix's knoppix-hotlpug for usbstorage
  if [ ! -e hwdata ]; then ln -fs ../../hwdata hwdata; fi

  chroot $bootcdroot apt-get -y install hotplug usbutils
  cp hwdata/hotplug/usb.agent $bootcdroot/etc/hotplug/
  cp hwdata/hotplug/hotplug.functions $bootcdroot/etc/hotplug/
  mkdir -p $bootcdroot/etc/hotplug/usb
  cp hwdata/hotplug/usb-storage $bootcdroot/etc/hotplug/usb/
  cp hwdata/hotplug/usb-storage.removal $bootcdroot/etc/hotplug/usb

  if [ -L hwdata ]; then rm -f hwdata; fi
  
  #dpkg --root $bootcdroot --install ../../deb/hotplug-knoppix_0.5-1_i386.deb
  # Blake, 2004/01/07, to fixed usb mouse unload problem
  rm -f $bootcdroot/etc/rc6.d/K89hotplug
  rm -f $bootcdroot/etc/rc0.d/K89hotplug

  # Blake, 2003/11/28, drbl debian apt repository
  ## Blake, 2003/11/14, install knoppix's automount 
  #chroot $bootcdroot apt-get -y install autofs
  #dpkg --root $bootcdroot --install ../../deb/automount-knoppix_0.5-4_i386.deb
  chroot $bootcdroot apt-get install -y autofs automount-knoppix
  #cp $boorcdroot/etc/auto.master.distrib.dpkg-new $bootcdroot/etc/auto.master
  #mkdir -p $bootcdroot/mnt/auto
  cat <<-EOF > $bootcdroot/root/autofs.sh
#!/bin/sh
apt-get install autofs
/etc/init.d/autofs stop
cp /etc/auto.master.distrib.dpkg-new /etc/auto.master
mkdir -p /mnt/auto
EOF
  chmod 755 $bootcdroot/root/autofs.sh 
  mount -t proc proc $bootcdroot/proc
  chroot $bootcdroot /root/autofs.sh
  umount $bootcdroot/proc
  rm -f $bootcdroot/autofs.sh

  cat <<-EOF > $bootcdroot/etc/auto.mnt
# Knoppix automounter file for Directory /mnt
floppy	--fstype=auto,sync,exec,umask=000	:/dev/fd0
cdrom	--fstype=auto,exec,ro	:/dev/cdrom
EOF
  cat <<-EOF > $bootcdroot/etc/filesystems
ext3
ext3
iso9660
reiserfs
vfat
xfs
minix
EOF
  # Blake, 2003/11/28, drbl debian apt repository 
  chroot $bootcdroot apt-get -y install mkdesktophdicons-knoppix scanpartitions-knoppix rebuildfstab-knoppix  
  cp common/init.d/rebuildfstab $bootcdroot/etc/init.d
  #ln -fs ../init.d/rebuildfstab $bootcdroot/etc/rcS.d/S90rebuildfstab

  # Blake, 2003/11/28, drbl debian apt repository
  chroot $bootcdroot apt-get -y install discover
  mv $bootcdroot/etc/rcS.d/S15discover $bootcdroot/etc/rcS.d/S12discover

  # Blake, 2003/09/25, remove the file that the postinst of discover created
  rm -f $bootcdroot/etc/modutils/alsa
  chroot $bootcdroot /sbin/update-modules

  # Blake, 2004/0115, use install.sh in isapnp_scan to install isapnp
  #cp ../../hwdata/isapnp_scan/isapnp_scan $bootcdroot/etc/init.d/
  #ln -s ../init.d/isapnp_scan $bootcdroot/etc/rcS.d/S16isapnp_scan
  #cp ../../hwdata/isapnp_scan/isapnp_scan.pl $bootcdroot/sbin/
  #mkdir -p $bootcdroot/etc/hwdata
  #cp ../../hwdata/isapnp_scan/isapnp.lst $bootcdroot/etc/hwdata
  if [ ! -e hwdata ]; then ln -fs ../../hwdata hwdata; fi

  cp -r hwdata/isapnp_scan $bootcdroot/root
  cat <<-EOF > $bootcdroot/root/isapnp_scan.sh
#!/bin/sh
cd /root/isapnp_scan
./install.sh $kernel_version
EOF
  chmod 755 $bootcdroot/root/isapnp_scan.sh
  chroot $bootcdroot /root/isapnp_scan.sh
  rm -rf $bootcdroot/root/isapnp_scan
  rm -f $bootcdroot/root/isapnp_scan.sh

  if [ -L hwdata ]; then rm -f hwdata; fi

  # setupx
  chroot $bootcdroot apt-get -y install videogen read-edid
  cp ../../hwdata/setupx/setupx $bootcdroot/etc/init.d
  ln -fs ../init.d/setupx $bootcdroot/etc/rc2.d/S98setupx
  mkdir -p $bootcdroot/etc/hwdata
  cp ../../hwdata/setupx/vidlist $bootcdroot/etc/hwdata

  # Blake, 2003/11/28, drbl debian apt repository
  ## Blake, 2003/09/22, ACPI
  #dpkg --root $bootcdroot --install ../../deb/acpi_0.06-3_i386.deb
  #dpkg --root $bootcdroot --install ../../deb/acpid_1.0.2-3_i386.deb
  chroot $bootcdroot apt-get -y install acpi acpid
  cat <<-EOF > $bootcdroot/etc/default/acpid
# Specify modules to load on acpid's startup
# MODULES may be uncommented to load "none", contain the string "all"
# to load all acpi related modules or simply a space seperated list
# of modules to be probed.
#MODULES="ospm_processor ospm_thermal ospm_fan ospm_button"
MODULES="processor thermal fan button"
EOF
  # Blake, 2004/03/05, start acpid before apmd
  mv $bootcdroot/etc/rc2.d/S20acpid $bootcdroot/etc/rc2.d/S19acpid
  # Blake, 2004/01/08, start acpid when single user mode
  ln -fs ../init.d/acpid $bootcdroot/etc/rc1.d/S19acpid

  # Blake, 2004/03/05, apmd
  mount -t proc proc $bootcdroot/proc
  chroot $bootcdroot apt-get -y install apmd
  umount $bootcdroot/proc
  mv $bootcdroot/etc/init.d/apmd $bootcdroot/etc/init.d/apmd.real
  cat <<-EOF >> $bootcdroot/etc/default/apmd
# APM parameters: power_off, realmode_power_off
#  power_off=1: Enable power off
#  realmode_power_off=1: Switch to real mode before powering off
APM_PARAMS="power_off=1"
EOF
  cat <<-EOF > $bootcdroot/etc/init.d/apmd
#!/bin/sh
if [ -d /proc/acpi ]; then exit; fi
if [ -f /etc/default/apmd ]; then
  . /etc/default/apmd
fi
case "\$1" in
  "start")
    /sbin/modprobe apm \$APM_PARAMS
    /etc/init.d/apmd.real start
	;;
  "stop")
    /etc/init.d/apmd.real stop
    #/sbin/rmmod apm
	;;
  *)
    /etc/init.d/apm.real \$1
	;;
esac
EOF
  chmod 755 $bootcdroot/etc/init.d/apmd 
  ln -fs ../init.d/apmd $bootcdroot/etc/rc1.d/S20apmd

  # Blake, 2003/09/17
  cp snddevices $bootcdroot/root
  cat <<-EOF > $bootcdroot/root/alsa.sh
#!/bin/sh
apt-get -y install coreutils
apt-get -y install alsa-base alsa-utils
mv /etc/init.d/alsa /etc/init.d/alsa.real
cat <<-ALSA > /etc/init.d/alsa
#!/bin/sh
/etc/init.d/alsa.real \\\$1
exit 0
ALSA
chmod 755 /etc/init.d/alsa
apt-get install alsa-base
/root/snddevices
EOF
  chmod 755 $bootcdroot/root/alsa.sh
  chroot $bootcdroot /root/alsa.sh
  rm $bootcdroot/root/alsa.sh
  rm $bootcdroot/root/snddevices

  ##
  while read module
  do
    if [ "$module" = "" ]; then continue; fi
	if [ "$(echo "$module" | grep -e "^#")" != "" ]; then continue; fi
  
    if [ "$(echo "$module" | grep -e "\.tar\.gz$" )" != "" ]; then
	  tar -C $bootcdroot/usr/src -xzf ../../repository/drbl/kernel/$module
	#elif [ "$(echo "$module" | grep -e "\.deb$")" != "" ]; then
	#  dpkg --force-overwrite --root $bootcdroot -i ../../deb/$module
	#  cp ../../deb/$module $bootcdroot/usr/src
    else
      echo "===>$module<==="
      chroot $bootcdroot apt-get install -y $module < /dev/null
      module_deb=`ls $bootcdroot/var/cache/apt/archives/$module*.deb`
      cp $module_deb $bootcdroot/usr/src
	fi
  done < MODULES

  #tar -C kernel/ -xvzf kernel/sis7019_release_2003_7_15.tgz
  #cp kernel/sis7019/sis7019.o $bootcdroot/lib/modules/2.4.18/kernel/drivers/sound
  #rm -rf kernel/sis7019
  #dpkg --root $bootcdroot -i kernel/sis7019_1.0.1-1_i386.deb
  chroot $bootcdroot /sbin/depmod -F /boot/System.map-$kernel_version -a $kernel_version
  chroot $bootcdroot /sbin/depmod -F /boot/System.map-$kernel_version_0 -a $kernel_version_0

  # Blake, 2003/12/31, $bootcdroot/vmlinuz
  rm -f $bootcdroot/vmlinuz*
  for vmlinuz in `ls $bootcdroot/boot/vmlinuz-*`; do
    vmlinuz=${vmlinuz##/*/}
    ln -fs boot/$vmlinuz $bootcdroot/$vmlinuz
  done
  ln -fs boot/vmlinuz-$kernel_version $bootcdroot/vmlinuz

  #umount $bootcdroot/proc

  # Blake, 2003/11/28, drbl debian apt repository
  chroot $bootcdroot apt-get -y install cloop-utils

  # modutils
  ## just skip any check becasue we don't need it when we boot from CD
  #cp $bootcdroot/etc/init.d/modutils $bootcdroot/opt/drblcd
  cp $bootcdroot/etc/init.d/modutils $bootcdroot/etc/init.d/modutils.orig
  cat <<-EOF > $bootcdroot/etc/init.d/modutils
#!/bin/sh
EOF

  # hdparm
  chroot $bootcdroot apt-get -y install hdparm
  # Blake, 2004/02/16
  cp $bootcdroot/etc/init.d/hdparm $bootcdroot/etc/init.d/hdparm.real
  cp common/init.d/hdparm $bootcdroot/etc/init.d/
  mv $bootcdroot/etc/rcS.d/S07hdparm $bootcdroot/etc/rcS.d/S14hdparm
  #ln -s ../init.d/hdparm $bootcdroot/etc/rc2.d/S15hdparm
  # Blake, 2004/02/07 ...
  #rm -f $bootcdroot/etc/rcS.d/S07hdparm

  # drbl_version
  today=$(date -R)
  eval "sed -e 's/\${RELEASE_DATE}/$today/' drbl_version > $bootcdroot/etc/drbl_version"
fi

# base system setup - /etc/apt/apt.conf
# Blake, 2004/01/16, set_non_interactive
set_non_interactive $non_interactive

# which one do you like ??
# chroot to install the one you like
if [ "$non_interactive" = "false" ]; then
  echo "1: base cd"
  echo "2: drbl cd"
  echo "3: demo cd"
  echo "4: cluster cd"
  echo -n "Which one you like [2]? "
  read ANS
else
  ANS=$cd_to_created
fi
case $ANS in
  1)
    cp -r base/* $bootcdroot/root
    cdprefix="basecd"
    ;;
  3)
    # let democd has the same packages as drblcd
    mkdir -p $bootcdroot/opt/drblcd/pkg
    cp -r drbl/* $bootcdroot/root 
 
    cp -r demo/* $bootcdroot/root
  
    # Blake, 2003/11/23, use "deb" way
    #cd ../../script
    #dpkg-buildpackage
    #cp ../drbl-script_*_i386.deb $bootcdroot/root
    #debian/rules clean
    #rm -f ../drbl-script_*

    # Blake, 2004/08/12, put each script in its package
    cd ../../script
    make
    cp *.deb $bootcdroot/root
    make clean

    # Blake, 2004/03/15, drbl-patch
    cd ../patch
    dpkg-buildpackage
    cp ../drbl-patch_*_i386.deb $bootcdroot/root
    debian/rules clean
    rm -f ../drbl-patch_* 

    cd ../src
    dpkg-buildpackage
    cp ../drbl-installer_*_i386.deb $bootcdroot/root
    debian/rules clean
    rm -f ../drbl-installer_*
 
    cd drblcd

    # cdprefix
    cdprefix="democd"
    ;;
  4)
    cp -r cluster/* $bootcdroot/root 
    cdprefix="cluster"
    ;;
  *)
    # mkinitrd-net
    mkdir -p $bootcdroot/opt/drblcd/pkg

    # Blake, 2003/11/23, use "deb" way
    #cd ../../script
    #dpkg-buildpackage
    #cp ../drbl-script_*_i386.deb $bootcdroot/opt/drblcd/pkg
    #debian/rules clean
    #rm -f ../drbl-script_*

    # Blake, 2004/08/12, put each script in its package
    cd ../../script
    make
    cp *.deb $bootcdroot/opt/drblcd/pkg
    make clean

    # Blake, 2004/03/15, drbl-patch
    cd ../patch
    dpkg-buildpackage
    cp ../drbl-patch_*_i386.deb $bootcdroot/opt/drblcd/pkg
    debian/rules clean
    rm -f ../drbl-patch_* 

    cd ../src
    dpkg-buildpackage
    cp ../drbl-installer_*_i386.deb $bootcdroot/opt/drblcd/pkg
    debian/rules clean
    rm -f ../drbl-installer_*

    cd drblcd

    # for next step
    cp -r drbl/* $bootcdroot/root

    # Blake, 2004/04/02, SCSI HD
    cp ../drblpush/mkinitrd-net/include-modules $bootcdroot/root

    #
    cdprefix="drblcd"
    ;;
esac

# chroot to install the one you like
mount -t proc proc $bootcdroot/proc
trap 'umount $bootcdroot/proc' HUP INT QUIT TERM
chroot $bootcdroot /root/bootcdimage $mirror_site
if [ "$non_interactive" = "true" ]; then
 chroot $bootcdroot /root/setdebconf-v0.9 /root/drblcd-debconf
fi
umount $bootcdroot/proc
if [ -f $bootcdroot/root/postbootcdimage ]; then
  $bootcdroot/root/postbootcdimage
fi
rm -f $bootcdroot/root/*

# Blake, 2004/05/05, readdebconf-v0.9 & setdebconf-v0.9
cp readdebconf-v0.9 $bootcdroot/usr/sbin
cp setdebconf-v0.9  $bootcdroot/usr/sbin

# drblcd-hdinstall
cp drblcd-hdinstall $bootcdroot/opt/drblcd/

# sources.list
use_mirror "http://opensource.nchc.org.tw"

# Blake, 2004/01/16, apt.conf
set_non_interactive "false"

# create cdimage.iso
if [ "$noiso" = "true" ]; then exit; fi
if [ "$non_interactive" = "false" ]; then
  echo -n "create cdimage.iso [Y|n]? "
  read ANS
  if [ "$ANS" = "n" -o "$ANS" = "N" ]; then exit; fi
fi

## remove old cdimage.iso
if [ -e /var/spool/bootcd/cdimage.iso ]; then
  rm -f /var/spool/bootcd/cdimage.iso
fi
## mountusr.sh, usr.cloop and /var/lib/bootcd/dev/cloop
#mknod /var/lib/bootcd/dev/cloop b 240 0
#mknod /var/lib/bootcd/dev/cloop-mod b 241 0
#cp mountusr.sh /var/lib/bootcd/etc/init.d
#ln -s ../init.d/mountusr.sh /var/lib/bootcd/etc/rcS.d/S14mountusr.sh
#CPWD=`pwd`
#cd /var/lib/bootcd/
#mkisofs -r usr | create_compressed_fs - 65536 > usr.cloop
#mv usr/bin/wc .
#rm -rf usr/*
#mkdir -p usr/bin
#mv wc usr/bin
#cd $CPWD
## logo.png
pngtopnm logo.png | ppmtolss16 \#b6b6b6=0 \#020202=7 > logo.lss
## cdimage.iso
apt-get -y install busybox-source-0.60.3
if [ -f /usr/src/busybox-0.60.3.tar.bz2 ]; then
  cp /usr/src/busybox-0.60.3.tar.bz2 .
else
  wget http://www.busybox.net/downloads/busybox-0.60.3.tar.bz2
fi
./bootcdwrite -c ./
rm -f logo.lss
mv /var/spool/bootcd/cdimage.iso $cdprefix-$drbl_version.iso
md5sum $cdprefix-$drbl_version.iso > $cdprefix-$drbl_version.md5sum
