--- /dev/null
+#!/bin/bash
+#
+# Script to repack the initrd to include the software repository,
+# to enable PXE-only network installation.
+#
+# Copyright (c) 2009 Citrix Systems
+#
+
+if [ "$#" != 2 ] ; then
+ echo "This script takes a path to the mounted CD as a parameter,">&2
+ echo "and the filename to write out the repacked initrd to.">&2
+ exit 1
+fi
+CDROM="$1"
+OUTPUT="$2"
+
+P_DOT_M="${CDROM}/packages.main"
+if [ ! -d "${P_DOT_M}" ] ; then
+ echo "Error: Could not find the repository at ${P_DOT_M}.">&2
+ exit 2
+fi
+
+INITRD="${CDROM}/isolinux/rootfs.gz"
+if [ ! -r "${INITRD}" ] ; then
+ echo "Error: Could not read the ramdisk filesystem from ${INITRD}.">&2
+ exit 3
+fi
+
+if [ -e "${OUTPUT}" ] ; then
+ echo "Error: output file ${OUTPUT} already exists.">&2
+ exit 4
+fi
+
+STAGING=$(mktemp)
+if [ $? != 0 ] ; then
+ echo "Error: could not create a temporary file.">&2
+ exit 5
+fi
+
+gunzip <"${INITRD}" >"${STAGING}"
+if [ $? != 0 ] ; then
+ echo "Error: could not unzip the initrd.">&2
+ rm "${STAGING}"
+ exit 6
+fi
+
+cd "${CDROM}"
+find packages.main -print | cpio -H newc -A -O "${STAGING}" -o
+if [ $? != 0 ] ; then
+ echo "Error: could not append to the new initrd.">&2
+ rm "${STAGING}"
+ exit 7
+fi
+
+cd -
+gzip <"${STAGING}" >"${OUTPUT}"
+if [ $? != 0 ] ; then
+ echo "Error: could not compress the new initrd.">&2
+ rm "${STAGING}"
+ rm "${OUTPUT}"
+ exit 8
+fi
+rm -f "${STAGING}"
+exit 0