supermin: Prevent multilib corruption (RHBZ#558593).
[libguestfs.git] / appliance / libguestfs-supermin-helper
similarity index 65%
rename from appliance/libguestfs-supermin-helper.in
rename to appliance/libguestfs-supermin-helper
index ab3aad5..0970776 100755 (executable)
@@ -1,6 +1,5 @@
 #!/bin/bash -
-# @configure_input@
-# Copyright (C) 2009 Red Hat Inc.
+# Copyright (C) 2009-2010 Red Hat Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -22,12 +21,41 @@ unset CDPATH
 
 set -e
 
+if [ $# -ne 5 ]; then
+    p=`basename $0`
+    echo
+    echo "$p: Create supermin appliance."
+    echo
+    echo "Usage:"
+    echo "$p sourcedir host_cpu repo kernel initrd"
+    echo
+    echo "This script is used by libguestfs to build the supermin appliance"
+    echo "(kernel and initrd output files).  You should NOT need to run this"
+    echo "program directly except if you are debugging tricky supermin"
+    echo "appliance problems."
+    echo
+    echo "NB: The kernel and initrd parameters are OUTPUT parameters.  If"
+    echo "those files exist, they are overwritten by the output."
+    echo
+    echo "Typical usage when debugging supermin appliance problems:"
+    echo "  $p /usr/lib64/guestfs x86_64 fedora-12 /tmp/kernel /tmp/initrd"
+    echo "Note: This will OVERWRITE any existing files called /tmp/kernel"
+    echo "and /tmp/initrd."
+    echo
+    exit 1
+fi
+
 # Source directory containing the supermin input files.
 sourcedir=$(cd "$1" > /dev/null; pwd)
 
+# Host CPU and repo constants passed from the library (see:
+# https://bugzilla.redhat.com/show_bug.cgi?id=558593).
+host_cpu=$2
+repo=$3
+
 # Output files.
-kernel="$2"
-initrd="$3"
+kernel="$4"
+initrd="$5"
 
 # Kernel:
 # Look for the most recent kernel named vmlinuz-*.<arch>* which has a
@@ -37,7 +65,7 @@ initrd="$3"
 # RHEL 5 didn't append the arch to the kernel name, so look for kernels
 # without arch second.
 
-arch=$(echo "@host_cpu@" | sed 's/^i.86$/i?86/')
+arch=$(echo $host_cpu | sed 's/^i.86$/i?86/')
 kernels=$(
     ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen ||: ;
     ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen
@@ -66,14 +94,14 @@ fi
 
 # The initrd consists of these components:
 # (1) The base skeleton appliance that we constructed at build time.
-#     name = initramfs.@REPO@.@host_cpu@.supermin.img
+#     name = initramfs.$repo.$host_cpu.supermin.img
 #     format = compressed cpio
 # (2) The modules from modpath which are on the module whitelist.
 #     format = plain cpio
 # (3) The host files which match wildcards in *.supermin.hostfiles.
 #     format = plain cpio
 
-cp "$sourcedir"/initramfs.@REPO@.@host_cpu@.supermin.img "$initrd"
+cp "$sourcedir"/initramfs.$repo.$host_cpu.supermin.img "$initrd"
 
 # Kernel modules (2).
 exec 5<"$sourcedir"/kmod.whitelist
@@ -90,6 +118,6 @@ find "$modpath" \( -not -name '*.ko' $whitelist \) -a -print0 |
 
 (cd / && \
   ls -1df $(
-      cat "$sourcedir"/initramfs.@REPO@.@host_cpu@.supermin.hostfiles
+      cat "$sourcedir"/initramfs.$repo.$host_cpu.supermin.hostfiles
     ) 2>/dev/null |
   cpio -C 65536 --quiet -o -H newc ) >> "$initrd"