Version 1.0.48.
[libguestfs.git] / appliance / libguestfs-supermin-helper.in
1 #!/bin/bash -
2 # @configure_input@
3 # Copyright (C) 2009 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # Helper script which constructs the supermin appliance at runtime.
20
21 unset CDPATH
22
23 set -e
24
25 # Source directory containing the supermin input files.
26 sourcedir=$(cd "$1" > /dev/null; pwd)
27
28 # Output files.
29 kernel="$2"
30 initrd="$3"
31
32 # Look for the kernel first.  This is very unsophisticated: We
33 # just look for any kernel named vmlinuz-*.$host_cpu which has a
34 # corresponding /lib/modules/*.$host_cpu directory.
35
36 for f in /boot/vmlinuz-*.@host_cpu@; do
37     b=$(basename "$f")
38     b=$(echo "$b" | sed 's,vmlinuz-,,')
39     modpath="/lib/modules/$b"
40     if [ -d "$modpath" ]; then
41         ln -sf "$f" "$kernel"
42         break
43     fi
44     modpath=
45 done
46
47 if [ -z "$modpath" ]; then
48     echo "$0: failed to find a suitable kernel" >&2
49     exit 1
50 fi
51
52 # The initrd consists of these components:
53 # (1) The base skeleton appliance that we constructed at build time.
54 #     name = initramfs.@REPO@.@host_cpu@.supermin.img
55 #     format = compressed cpio
56 # (2) The modules from modpath which are on the module whitelist.
57 #     format = plain cpio
58 # (3) The host files which match wildcards in *.supermin.hostfiles.
59 #     format = plain cpio
60
61 cp "$sourcedir"/initramfs.@REPO@.@host_cpu@.supermin.img "$initrd"
62
63 # Kernel modules (2).
64 exec 5<"$sourcedir"/kmod.whitelist
65 whitelist=
66 while read kmod 0<&5; do
67     whitelist="$whitelist -o -name $kmod"
68 done
69 exec 5<&-
70
71 find "$modpath" \( -not -name '*.ko' $whitelist \) -a -print0 |
72   cpio --quiet -o -0 -H newc >> "$initrd"
73
74 # Host files (3).
75
76 (cd / && \
77   ls -1df $(
78       cat "$sourcedir"/initramfs.@REPO@.@host_cpu@.supermin.hostfiles
79     ) 2>/dev/null |
80   cpio --quiet -o -H newc ) >> "$initrd"