I suspect this is a recent change that I missed in the renaming
[bootcd.git] / build.sh
index 1e6aa52..a85a41e 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -10,7 +10,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2004-2006 The Trustees of Princeton University
 #
-# $Id: build.sh,v 1.40 2006/07/25 23:51:39 mlhuang Exp $
+# $Id$
 #
 
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
@@ -18,6 +18,8 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
 CONFIGURATION=default
 NODE_CONFIGURATION_FILE=
 ALL=0
+# Leave 4 MB of free space
+FREE_SPACE=4096
 
 usage()
 {
@@ -57,10 +59,12 @@ pushd $srcdir
 # Root of the isofs
 isofs=$PWD/build/isofs
 
-# Build reference image if it does not exist. This should only need to
-# be executed once at build time, never at run time.
-if [ ! -f $isofs/bootcd.img ] ; then
-    ./prep.sh
+# The reference image is expected to have been built by prep.sh (see .spec)
+# we disable the initial logic that called prep.sh if that was not the case
+# this is because prep.sh needs to know pldistro 
+if [ ! -f $isofs/bootcd.img -o ! -f build/version.txt ] ; then
+    echo "you have to run prep.sh prior to calling $0 - exiting"
+    exit 1
 fi
 
 # build/version.txt written by prep.sh
@@ -260,8 +264,7 @@ mkisofs -o "$iso" \
 echo -n "* Creating USB image... "
 usb="$PLC_NAME-BootCD-$BOOTCD_VERSION.usb"
 
-# Leave 1 MB of free space on the VFAT filesystem
-mkfs.vfat -C "$usb" $(($(du -sk $isofs | awk '{ print $1; }') + 1024))
+mkfs.vfat -C "$usb" $(($(du -sk $isofs | awk '{ print $1; }') + $FREE_SPACE))
 
 # Mount it
 tmp=$(mktemp -d ${BUILDTMP}/bootcd.XXXXXX)
@@ -293,8 +296,7 @@ $srcdir/syslinux/unix/syslinux "$usb"
 echo -n "* Creating USB image... "
 usb="$PLC_NAME-BootCD-$BOOTCD_VERSION-serial.usb"
 
-# Leave 1 MB of free space on the VFAT filesystem
-mkfs.vfat -C "$usb" $(($(du -sk $isofs | awk '{ print $1; }') + 1024))
+mkfs.vfat -C "$usb" $(($(du -sk $isofs | awk '{ print $1; }') + $FREE_SPACE))
 
 # Mount it
 tmp=$(mktemp -d ${BUILDTMP}/bootcd.XXXXXX)
@@ -392,8 +394,8 @@ echo "ttyS0" >> etc/securetty
 
 #calculate the size of /tmp based on the size of /etc & /var + 8MB slack
 etcsize=$(du -s ./etc | awk '{ print $1 }')
-varsize=$(du -s ./etc | awk '{ print $1 }')
-let msize=($vsize+$esize+8192)/1024
+varsize=$(du -s ./var | awk '{ print $1 }')
+let msize=($varsize+$etcsize+8192)/1024
 
 
 # generate pl_rsysinit
@@ -429,12 +431,11 @@ chmod +x etc/rc.d/init.d/pl_rsysinit
 
 popd
 
-chown -R 0.0 $cramfs
+chown -R 0.0 $tmp
 
 #create the cramfs image
 echo "* Creating cramfs image"
 mkfs.cramfs $tmp/ $cramfs
-# Leave 1 MB of free space on the VFAT filesystem
 cramfs_size=$(($(du -sk $cramfs | awk '{ print $1; }')))
 mv $cramfs ${BUILDTMP}/cramfs.img
 rm -rf $tmp
@@ -445,7 +446,7 @@ echo "* Creating ISO CRAMFS-based image"
 iso="$PLC_NAME-BootCD-$BOOTCD_VERSION-cramfs.iso"
 
 tmp=$(mktemp -d ${BUILDTMP}/bootcd.XXXXXX)
-trap "$tmp; rm -rf $tmp" ERR INT
+trap "cd /; rm -rf $tmp" ERR INT
 (cd $isofs && find . | grep -v "\.img$" | cpio -p -d -u $tmp/)
 cat >$tmp/isolinux.cfg <<EOF
 DEFAULT kernel
@@ -489,8 +490,7 @@ trap - ERR INT
 echo "* Creating USB CRAMFS based image"
 usb="$PLC_NAME-BootCD-$BOOTCD_VERSION-cramfs.usb"
 
-# leave 1MB of space on the USB VFAT
-let vfat_size=${cramfs_size}+2048
+let vfat_size=${cramfs_size}+$FREE_SPACE
 
 # Make VFAT filesystem for USB
 mkfs.vfat -C "$usb" $vfat_size
@@ -525,8 +525,7 @@ $srcdir/syslinux/unix/syslinux "$usb"
 echo "* Creating USB CRAMFS based image w/ serial line support"
 usb="$PLC_NAME-BootCD-$BOOTCD_VERSION-cramfs-serial.usb"
 
-# leave 4MB of space on the USB VFAT
-let vfat_size=${cramfs_size}+2048
+let vfat_size=${cramfs_size}+$FREE_SPACE
 
 # Make VFAT filesystem for USB
 mkfs.vfat -C "$usb" $vfat_size