# 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
CONFIGURATION=default
NODE_CONFIGURATION_FILE=
ALL=0
+# Leave 4 MB of free space
+FREE_SPACE=4096
usage()
{
# 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
echo "* Building images for $FULL_VERSION_STRING"
-# From within a myplc chroot /tmp is too small to build
-# all possible images, whereas /data is part of the host
+# From within a myplc chroot /usr/tmp is too small
+# to build all possible images, whereas /data is part of the host
# filesystem and usually has sufficient space. What we
# should do is check whether the expected amount of space
# is available.
-[ -d /data ] && BUILDTMP=/data || BUILDTMP=/tmp
+BUILDTMP=/usr/tmp
+if [ -d /data ] ; then
+ isreadonly=$(mktemp /data/isreadonly.XXXXXX || /bin/true)
+ if [ -n "$isreadonly" ] ; then
+ rm -f "$isreadonly"
+ BUILDTMP=/data
+ fi
+fi
# Root of the ISO and USB images
echo "* Populating root filesystem..."
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)
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)
#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
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
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
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
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