#!/bin/sh

lineno=`wc -l bootcd/bootcd | sed -e 's/bootcd\/bootcd//g'`
lineno=`expr $lineno + 1`
eval "sed -e 's/\${LINENO}/$lineno/' bootcd/bootcd > drbl-bootcd"

# busybox
if [ ! -f ../../cache/busybox-0.60.3.tar.bz2 ]; then
  mkdir -p ../cache/
  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 .
    cp /usr/src/busybox-0.60.3.tar.bz2 bootcd/
  else
    wget http://www.busybox.net/downloads/busybox-0.60.3.tar.bz2
    cp busybox-0.60.3.tar.bz2 ../cache/
    mv busybox-0.60.3.tar.bz2 bootcd/
  fi
else
  cp ../../cache/busybox-0.60.3.tar.bz2 bootcd/
fi
# bootcd
#cp ../deb/bootcd_2.32_all.deb bootcd/
#apt-get update
#apt-get install bootcd -d
#deb=`ls /var/cache/apt/archives/bootcd*.deb`
#cp $deb bootcd/
#cp ../src/drblcd/bootcdwrite bootcd/
# drblcd-hdinstall
cp ../../src/drblcd/drblcd-hdinstall bootcd/drblcd-hdinstall.real

zip -r bootcd.zip bootcd/
cat bootcd.zip >> drbl-bootcd
rm -f bootcd.zip

rm -f bootcd/busybox-0.60.3.tar.bz2
#rm -f bootcd/bootcd_2.32_all.deb
#rm -f bootcd/bootcd*.deb
#rm -f bootcd/bootcdwrite
rm -f bootcd/drblcd-hdinstall.real

chmod 755 drbl-bootcd
