Rewrite libguestfs-supermin-helper in C.
[libguestfs.git] / appliance / make.sh.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 # This is called from the Makefile to build the initramfs.
20
21 unset CDPATH
22
23 set -e
24 set -x
25
26 if [ "@DIST@" = "REDHAT" ]; then
27   cd @top_builddir@
28   # Decide on names for the final output.  These have to match Makefile.am.
29   output=appliance/initramfs.@REPO@.@host_cpu@.img
30   koutput=appliance/vmlinuz.@REPO@.@host_cpu@
31   rm -f $output
32   rm -f $koutput
33
34   # Create the basic initramfs.
35   exec 5<appliance/packagelist
36   packages=
37   while read pkg 0<&5; do
38       packages="$packages -i $pkg"
39   done
40   exec 5<&-
41
42   @FEBOOTSTRAP@ $packages -u @UPDATES@ @REPO@ initramfs @MIRROR@
43
44   # /sysroot is where the guest root filesystem will be mounted.
45   @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /sysroot
46
47   # Create /tmp if it is missing.
48   @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /tmp
49
50   # Create /selinux if it is missing.
51   @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0755 /selinux
52
53   # Nuke some stuff.  The kernel pulls mkinitrd and plymouth which pulls in
54   # all of Python.  Sheez.
55   (cd initramfs && find -name '*python*' -print0) |
56     xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
57   (cd initramfs && find -name '*plymouth*' -print0) |
58     xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
59   (cd initramfs && find -name 'libply-*' -print0) |
60     xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
61
62   # In Fedora >= 11, it pulls in all of Perl from somewhere.  Nuke from orbit.
63   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/perl5 /usr/lib64/perl5
64
65   # Anaconda?  JPEG images?
66   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/anaconda-runtime
67
68   # Don't need any firmware.
69   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/firmware
70
71   # Don't need any keyboard maps.
72   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/kbd
73
74   # Remove anything in home directory.  Because of the potential for disaster
75   # we don't put a slash before 'home'.
76   (cd initramfs && echo home/*) |
77     xargs @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
78
79   # Remove /var/lib/yum stuff.
80   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /var/lib/yum
81
82   # Remove some unreadable binaries which are incompatible with
83   # the supermin appliance.  Since these binaries can't be read
84   # from the host filesystem, they generate warnings like:
85   #   cpio: ./usr/bin/chfn: Cannot open: Permission denied
86   # These binaries are not needed for operation of the appliance.
87   @FEBOOTSTRAP_RUN@ initramfs -- rm -f \
88     /usr/bin/chfn \
89     /usr/bin/chsh \
90     /usr/libexec/pt_chown \
91     /usr/sbin/groupdel \
92     /usr/sbin/groupadd \
93     /usr/sbin/useradd \
94     /usr/sbin/tzdata-update \
95     /usr/sbin/userdel \
96     /usr/sbin/usermod \
97     /usr/sbin/groupmod \
98     /usr/sbin/groupmems \
99     /sbin/unix_update \
100     /usr/sbin/tcpd \
101     /lib/dbus-1/dbus-daemon-launch-helper \
102     /lib64/dbus-1/dbus-daemon-launch-helper \
103     /etc/passwd- \
104     /etc/group- \
105     /etc/gshadow \
106     /etc/gshadow- \
107     /etc/shadow \
108     /etc/shadow- \
109     /etc/securetty \
110     /etc/sysconfig/iptables-config \
111     /etc/default/useradd \
112     /etc/security/opasswd \
113     /etc/libaudit.conf \
114     /var/log/tallylog \
115     /var/log/maillog \
116     /var/log/secure \
117     /var/log/spooler \
118     /var/log/messages \
119     /var/log/btmp \
120     /var/log/yum.log \
121     $(cd initramfs && echo usr/sbin/glibc_post_upgrade.*)
122
123   # Kernel modules take up nearly half of the image.  Only include ones
124   # which are on the whitelist.
125   exec 5<appliance/kmod.whitelist
126   whitelist=
127   while read kmod 0<&5; do
128       whitelist="$whitelist -a -not -name $kmod"
129   done
130   exec 5<&-
131
132   (cd initramfs && \
133     find lib/modules/*/kernel -name '*.ko' $whitelist -a -print0 ) |
134     xargs -0 febootstrap-run initramfs -- rm
135
136   # Pull the kernel out into the current directory.  We don't want it in
137   # the initramfs image.
138   cp initramfs/boot/vmlinuz* $koutput
139   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf boot
140
141   # Minimize the image.
142   @FEBOOTSTRAP_MINIMIZE@ initramfs
143
144   # Add some missing configuration files.
145   if [ ! -f initramfs/etc/hosts ]; then
146       cat > hosts.new <<'__EOF__'
147   127.0.0.1 guestfs localhost.localdomain localhost
148   ::1       localhost6.localdomain6 localhost6
149 __EOF__
150       @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root
151       rm hosts.new
152   fi
153
154   if [ ! -f initramfs/etc/fstab ]; then
155       @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab
156   fi
157
158   echo nameserver 10.0.2.3 > resolv.conf.new
159   @FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root
160   rm resolv.conf.new
161
162   ls -lh $koutput
163
164   # Now directly run the update script to copy/update the daemon in the
165   # initramfs.
166   cd appliance && bash update.sh
167
168 elif [ "@DIST@" = "DEBIAN" ]; then
169   cd @top_builddir@/appliance
170   debirf make -n debian
171   mkdir -p @top_builddir@/initramfs
172   touch @top_builddir@/initramfs/fakeroot.log
173 fi