Add a build_usb_partition function to create a partitioned usb image that will
[bootcd.git] / build.sh
index c986d81..1ee3864 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -30,6 +30,7 @@ usage()
     echo "    -c name          (Deprecated) Static configuration to use (default: $CONFIGURATION)"
     echo "    -f planet.cnf    Node to customize CD for (default: none)"
     echo "    -t 'types'       Build the specified images (default: $TYPES)"
+    echo "    -a               Build all supported images"
     echo "    -C custom-dir    Custom directory"
     echo "    -O output-base   The basename of the generated files (default: PLC_NAME-BootCD-VERSION)"
     echo "    -h               This message"
@@ -37,7 +38,7 @@ usage()
 }
 
 # Get options
-while getopts "O:c:f:t:C:h" opt ; do
+while getopts "O:c:f:t:C:ah" opt ; do
     case $opt in
     c)
         CONFIGURATION=$OPTARG
@@ -54,6 +55,9 @@ while getopts "O:c:f:t:C:h" opt ; do
     O)
         OUTPUT_BASE="$OPTARG"
         ;;
+    a)
+        TYPES="usb iso usb_serial iso_serial usb_cramfs iso_cramfs usb_cramfs_serial iso_cramfs_serial"
+        ;;
     h|*)
         usage
         ;;
@@ -151,9 +155,10 @@ trap "do_cleanup" ERR INT EXIT
 BUILDTMP=$(mktemp -d ${BUILDTMP}/bootcd.XXXXXX)
 push_cleanup rm -fr "${BUILDTMP}"
 mkdir "${BUILDTMP}/isofs"
-for i in "$isofs"/{bootcd.img,kernel,isolinux.bin}; do
+for i in "$isofs"/{bootcd.img,kernel}; do
     ln -s "$i" "${BUILDTMP}/isofs"
 done
+cp "/usr/lib/syslinux/isolinux.bin" "${BUILDTMP}/isofs"
 isofs="${BUILDTMP}/isofs"
 
 # Root of the ISO and USB images
@@ -289,6 +294,59 @@ EOF
         $MKISOFS_OPTS \
         $isofs
 }
+function build_usb_partition()
+{
+       echo -n "* Creating USB image with partitions..."
+       local usb="$1"
+    local serial=$2
+    local custom=$3
+
+       local size=$(($(du -Lsk $isofs | awk '{ print $1; }') + $FREE_SPACE))
+       size=$(( $size / 1024 ))
+
+       local heads=64
+       local sectors=32
+       local cylinders=$(( ($size*1024*2)/($heads*$sectors) ))
+       local offset=$(( $sectors*512 ))
+
+       /usr/lib/syslinux/mkdiskimage -M -4 "$usb" $size $heads $sectors
+
+       cat >${BUILDTMP}/mtools.conf<<EOF
+drive z:
+file="${usb}"
+cylinders=$cylinders
+heads=$heads
+sectors=$sectors
+offset=$offset
+mformat_only
+EOF
+       # environment variable for mtools
+       export MTOOLSRC="${BUILDTMP}/mtools.conf"
+
+       ### COPIED FROM build_usb() below!!!!
+    echo -n " populating USB image... "
+    mcopy -bsQ -i "$usb" "$isofs"/* z:/
+       
+    # Use syslinux instead of isolinux to make the image bootable
+    tmp="${BUILDTMP}/syslinux.cfg"
+    cat >$tmp <<EOF
+${serial:+SERIAL 0 115200}
+DEFAULT kernel
+APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img${custom:+,custom.img} root=/dev/ram0 rw ${serial:+console=ttyS0,115200n8}
+DISPLAY pl_version
+PROMPT 0
+TIMEOUT 40
+EOF
+    mdel -i "$usb" z:/isolinux.cfg 2>/dev/null || :
+    mcopy -i "$usb" "$tmp" z:/syslinux.cfg
+    rm -f "$tmp"
+    rm -f "${BUILDTMP}/mtools.conf"
+       unset MTOOLSRC
+
+    echo "making USB image bootable."
+    syslinux -o $offset "$usb"
+
+}
 
 # Create USB image
 function build_usb()
@@ -319,7 +377,7 @@ EOF
     rm -f "$tmp"
 
     echo "making USB image bootable."
-    $srcdir/syslinux/unix/syslinux "$usb"
+    syslinux "$usb"
 }
 
 
@@ -438,8 +496,6 @@ EOF
 
     popd
 
-    chown -R 0.0 $tmp
-
     # create the cramfs image
     echo "* Creating cramfs image"
     mkfs.cramfs $tmp/ ${BUILDTMP}/cramfs.img
@@ -506,17 +562,18 @@ DISPLAY pl_version
 PROMPT 0
 TIMEOUT 40
 EOF
-  mcopy -bsQ -i "$usb" "$tmp" ::/syslinux.cfg
-  rm -f "$tmp"
+    mcopy -bsQ -i "$usb" "$tmp" ::/syslinux.cfg
+    rm -f "$tmp"
 
-  echo "* Making USB CRAMFS based image bootable"
-  $srcdir/syslinux/unix/syslinux "$usb"
+    echo "* Making USB CRAMFS based image bootable"
+    syslinux "$usb"
 }
 
 function type_to_name()
 {
     echo $1 | sed '
         s/usb$/.usb/;
+        s/usb_partition$/-partition.usb/;
         s/usb_serial$/-serial.usb/;
         s/iso$/.iso/;
         s/iso_serial$/-serial.iso/;