--- livecd-ng.old	2004-12-23 01:49:52.000000000 +0100
+++ livecd-ng	2004-12-23 01:46:09.000000000 +0100
@@ -142,16 +142,25 @@
 then
 	KERNCONFIG="kernel-config"
 fi
+if [ "$KERNVERSION" = "" ]
+then
+	KERNVERSION="2.4"
+fi
+if [ "$BB_CONFIG" = "" ]
+then
+	BB_CONFIG="busybox-config"
+fi
 CD_BUILDTEMP=${CD_BUILDROOT}/tmp
 CD_BUILDCHROOT=${CD_BUILDROOT}/cdroot
 export CCACHEDIR=${CCACHEDIR:-/root/.ccache}
 CD_STAGEFILE="${CD_STAGELOC}/${CD_STAGETARBALL##*/}"
+CD_PORTAGEFILE="${CD_STAGELOC}/${CD_PORTAGESNAPSHOT##*/}"
 LOOP_ROOT=${CD_BUILDROOT}/looproot
 ISO_ROOT=${CD_BUILDROOT}/isoroot
-CLOOP_TARBALL=gcloop_0.66-1.tar.gz
-CLOOP_DIR=cloop-0.66
-BUSYBOX_TARBALL=busybox-0.60.5.tar.bz2
-BUSYBOX_DIR=busybox-0.60.5
+CLOOP_TARBALL=cloop_2.01-5.tar.gz
+CLOOP_DIR=cloop-2.01
+BUSYBOX_TARBALL=busybox-1.00.tar.bz2
+BUSYBOX_DIR=busybox-1.00
 LOOP_FILE=${CD_BUILDROOT}/livecd.loop
 CLOOP_FILE=${CD_BUILDROOT}/livecd.cloop
 LOOP_MODE=cloop
@@ -174,6 +183,10 @@
 	mount -o bind $CD_PORTDIR $CD_BUILDCHROOT/usr/portage || chroot_die
 	[ ! -e $CD_BUILDCHROOT/tmp/livecd ] && install -d $CD_BUILDCHROOT/tmp/livecd
 	mount -o bind $CD_BUILDTEMP $CD_BUILDCHROOT/tmp/livecd || chroot_die
+	if [ ! -e ${CDBUILDCHROOT}/${CCACHEDIR} ]
+	then
+		mkdir ${CDBUILDCHROOT}/${CCACHEDIR}
+	fi
 	mount -o bind ${CCACHEDIR} ${CD_BUILDCHROOT}/${CCACHEDIR} || chroot_die
 	mount -o bind $CD_DISTDIR $CD_BUILDCHROOT/home/distfiles || chroot_die
 }
@@ -198,7 +211,11 @@
 	then
 		( cd $CD_STAGELOC; wget $CD_STAGETARBALL )
 	fi
-}
+	if [ ! -e "$CD_PORTAGEFILE" ]
+	then	
+		( cd $CD_STAGELOC; wget $CD_PORTAGESNAPSHOT )
+	fi	
+	}
 
 build_setup() {
 	cat > $CD_BUILDTEMP/build-setup << EOF
@@ -316,6 +333,12 @@
 }
 
 kernel_build() {
+	if [ ! -e ${CD_BUILDCHROOT}/usr/src/linux ] && [ -h ${CD_BUILDCHROOT}/usr/src/linux ]
+	then
+		KERNELLINK=`readlink ${CD_BUILDCHROOT}/usr/src/linux`
+		rm -f ${CD_BUILDCHROOT}/usr/src/linux
+		ln -s `basename ${KERNELLINK}` ${CD_BUILDCHROOT}/usr/src/linux
+	fi
 	cp "${LIVECD_ROOT}/profiles/${CD_PROFILE}/${KERNCONFIG}" "${CD_BUILDCHROOT}/usr/src/linux/.config" || chroot_die
 	cat > $CD_BUILDTEMP/kernel-build << EOF
 source /tmp/livecd/build-setup
@@ -338,6 +361,7 @@
 
 initrd_build() {
 	cp ${LIVECD_ROOT}/archives/${CLOOP_TARBALL} ${LIVECD_ROOT}/archives/${BUSYBOX_TARBALL} $CD_BUILDTEMP || die
+	cp ${LIVECD_ROOT}/profiles/${CD_PROFILE}/${BB_CONFIG} $CD_BUILDTEMP || die
 	cat > $CD_BUILDTEMP/initrd-build << EOF
 source /tmp/livecd/build-setup
 cd /tmp/livecd
@@ -346,20 +370,30 @@
 	rm -rf ${CLOOP_DIR}
 	cwrapper tar xzf ${CLOOP_TARBALL}
 	cd ${CLOOP_DIR} 
+	echo ">>> Compiling cloop"
+	# conf.vars exists only on Debian systems
+	sed -i "s/include.*conf.vars/#&/" Makefile
+	if [ "$KERNVERSION" = "2.4" ]
+	then
+	  sed -i "s:#include <netinet/in.h>::" advancecomp-1.9_create_compressed_fs/advfs.cc
+	fi
 	make
 	cd ..
 fi
 rm -rf ${BUSYBOX_DIR}
 cwrapper tar xjf ${BUSYBOX_TARBALL}
+echo "cp ${LIVECD_ROOT}/profiles/${CD_PROFILE}/${BB_CONFIG} /tmp/livecd/${BUSYBOX_DIR}/.config"
+mv "${BB_CONFIG}" "${BUSYBOX_DIR}/.config"
 cd ${BUSYBOX_DIR}
-cp Config.h Config.h.orig
-sed -e "s://#define BB_INSMOD:#define BB_INSMOD:" \
--e "s://#define BB_PIVOT_ROOT:#define BB_PIVOT_ROOT:" \
--e "s://#define BB_LOADKMAP:#define BB_LOADKMAP:" \
--e "s://#define BB_LOSETUP:#define BB_LOSETUP:" \
--e "s://#define BB_RMMOD:#define BB_RMMOD:" Config.h.orig > Config.h
-cwrapper make clean
-cwrapper make DOSTATIC=true
+#cp Config.h Config.h.orig
+#sed -e "s://#define BB_INSMOD:#define BB_INSMOD:" \
+#-e "s://#define BB_PIVOT_ROOT:#define BB_PIVOT_ROOT:" \
+#-e "s://#define BB_LOADKMAP:#define BB_LOADKMAP:" \
+#-e "s://#define BB_LOSETUP:#define BB_LOSETUP:" \
+#-e "s://#define BB_RMMOD:#define BB_RMMOD:" Config.h.orig > Config.h
+#cwrapper make clean
+#cwrapper make DOSTATIC=true
+make
 EOF
 	chmod +x $CD_BUILDTEMP/initrd-build
 	chroot $CD_BUILDCHROOT /tmp/livecd/initrd-build
@@ -368,8 +402,8 @@
 
 initrd_create() {
 	install -d ${CD_BUILDCHROOT}-initrd
-	dd if=/dev/zero of=${CD_BUILDROOT}/initrd bs=1k count=3000
-	mke2fs -F -q -N3000 ${CD_BUILDROOT}/initrd
+	dd if=/dev/zero of=${CD_BUILDROOT}/initrd bs=1k count=10000
+	mke2fs -F -q -N10000 ${CD_BUILDROOT}/initrd
 	mount -t ext2 -o loop ${CD_BUILDROOT}/initrd ${CD_BUILDCHROOT}-initrd
 	#makeinitrd
 	if [ ! -e ${CD_BUILDCHROOT}-initrd/bin ]
@@ -403,7 +437,7 @@
 	install -d ${CD_BUILDCHROOT}-initrd/modules/storage
 	if [ "$LOOP_MODE" = "cloop" ]
 	then
-		cp ${CD_BUILDTEMP}/${CLOOP_DIR}/cloop_ucl.o ${CD_BUILDCHROOT}-initrd/modules/cloop.o || chroot_die "can't find ucl cloop module"
+		cp ${CD_BUILDTEMP}/${CLOOP_DIR}/cloop.o ${CD_BUILDCHROOT}-initrd/modules/cloop.o || chroot_die "can't find cloop module"
 	fi
 	local mymod
 	for i in $STORAGE_MODULES
@@ -433,7 +467,7 @@
 	umount ${LOOP_ROOT} || chroot_die
 	if [ "$LOOP_MODE" = "cloop" ]
 	then
-		cat ${LOOP_FILE} | ${CD_BUILDTEMP}/${CLOOP_DIR}/create_compressed_ucl_fs - 131072 > ${CLOOP_FILE} || chroot_die
+		cat ${LOOP_FILE} | ${CD_BUILDTEMP}/${CLOOP_DIR}/create_compressed_fs - 131072 > ${CLOOP_FILE} || chroot_die
 	fi
 }
 
@@ -460,11 +494,14 @@
 chroot_generate() {
 	umount_all
 	[ ! -e "$CD_STAGEFILE" ] && chroot_die "$CD_STAGEFILE not found; please run \"fetch\" first."
+	[ ! -e "$CD_PORTAGEFILE" ] && chroot_die "$CD_PORTAGEFILE not found; please run \"fetch\" first."
 	[ -e "$CD_BUILDCHROOT" ] && chroot_die "$CD_BUILDCHROOT already exists; please run $0 $CD_PROFILE delete before running $0 $CD_PROFILE build"
 	#create build chroot directory and extract stage tarball
 	install -d "$CD_BUILDCHROOT"
 	echo ">>> Extracting stage tarball..."
 	tar xjpf $CD_STAGEFILE -C $CD_BUILDCHROOT || die "stage tarball extraction error"
+	echo ">>> Extracting portage snapshot..."
+	tar xjpf $CD_PORTAGEFILE -C $CD_BUILDCHROOT/usr/ || die "stage tarball extraction error"
 	#set up our private temp directory and the mount-point inside the chroot.
 	install -d "$CD_BUILDTEMP" "${CD_BUILDCHROOT}/tmp/livecd" || die "couldn't create chroot temp. directories"
 	#set up ccache so we can get funky.
@@ -559,7 +596,7 @@
     	pre_fetch;;
     build)  
     	chroot_generate;;
-	cloop)
+    cloop)
 		cloop_create;;
     initrd) 
 		mount_all
