2 # febootstrap-to-supermin
3 # (C) Copyright 2009 Red Hat Inc.
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.
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.
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.
19 # Written by Richard W.M. Jones <rjones@redhat.com>
26 -n febootstrap-to-supermin -- "$@"`
28 echo "febootstrap-to-supermin: problem parsing the command line arguments"
35 echo "Usage: febootstrap-to-supermin DIR supermin.img hostfiles.txt"
36 echo "Please read febootstrap-to-supermin(8) man page for more information."
48 echo "Internal error!"
60 # Create a temporary directory, make sure it gets cleaned up at the end.
65 rm -rf "$tmpdir" && exit $status
67 trap remove_tmpdir EXIT
69 # Get the complete list of files and directories in the appliance.
70 (cd "$1" > /dev/null && find) > "$tmpdir/files"
72 exec 5>"$tmpdir/keep" # Files/dirs we will keep in supermin.img
73 exec 6>$3 # hostfiles.txt (output)
74 exec 7<"$tmpdir/files"
76 while read path <&7; do
77 dir=$(dirname "$path")
78 file=$(basename "$path")
80 # For quoting problems with the bash =~ operator, see bash FAQ
81 # question E14 here http://tiswww.case.edu/php/chet/bash/FAQ and
82 # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=487387#25
87 p_lib_modules='^\./lib/modules/'
88 p_builddir='^\./builddir'
89 p_ld_so='^ld-[.0-9]+\.so$'
90 p_libbfd='^libbfd-.*\.so$'
91 p_libgcc='^libgcc_s-.*\.so\.([0-9]+)$'
92 p_libntfs3g='^libntfs-3g\.so\..*$'
93 p_lib123so='^lib(.*)-[-.0-9]+\.so$'
94 p_lib123so123='^lib(.*)-[-.0-9]+\.so\.([0-9]+)\.'
95 p_libso123='^lib(.*)\.so\.([0-9]+)\.'
97 # Ignore fakeroot.log.
98 if [ "$path" = "./fakeroot.log" ]; then
101 # All we're going to keep are the special files /init,
102 # configuration files (/etc), devices and modifiable stuff (/var).
103 elif [ "$path" = "./init" ]; then
106 # Get timezone configuration from local system.
107 elif [ "$path" = "./etc/localtime" ]; then
110 elif [[ "$path" =~ $p_etc || "$path" =~ $p_dev || "$path" =~ $p_var ]]
114 # Kernel modules are always copied in from the host, including all
115 # the dependency information files.
116 elif [[ "$path" =~ $p_lib_modules ]]; then
119 # On mock/Koji, exclude bogus /builddir directory which for some
120 # reason contains some yum temporary files (RHBZ#566512).
121 elif [[ "$path" =~ $p_builddir ]]; then
124 # Always write directory names to both output files.
125 elif [ -d "$path" ]; then
129 # Some libraries need fixed version numbers replaced by wildcards.
131 elif [[ "$file" =~ $p_ld_so ]]; then
132 echo "$dir/ld-*.so" >&6
134 # Special case for libbfd
135 elif [[ "$file" =~ $p_libbfd ]]; then
136 echo "$dir/libbfd-*.so" >&6
138 # Special case for libgcc_s-<gccversion>-<date>.so.N
139 elif [[ "$file" =~ $p_libgcc ]]; then
140 echo "$dir/libgcc_s-*.so.${BASH_REMATCH[1]}" >&6
142 # Special case for libntfs-3g.so.*
143 elif [[ "$file" =~ $p_libntfs3g ]]; then
144 [ -n "$libntfs3g_once" ] || echo "$dir/libntfs-3g.so.*" >&6
148 elif [[ "$file" =~ $p_lib123so ]]; then
149 echo "$dir/lib${BASH_REMATCH[1]}-*.so" >&6
151 # libfoo-1.2.3.so.1.2.3 (but NOT '*.so.N')
152 elif [[ "$file" =~ $p_lib123so123 ]]; then
153 echo "$dir/lib${BASH_REMATCH[1]}-*.so.${BASH_REMATCH[2]}.*" >&6
155 # libfoo.so.1.2.3 (but NOT '*.so.N')
156 elif [[ "$file" =~ $p_libso123 ]]; then
157 echo "$dir/lib${BASH_REMATCH[1]}.so.${BASH_REMATCH[2]}.*" >&6
160 # Anything else comes from the host directly.
165 # Close output files.
169 # Now run febootstrap-to-initramfs to construct the supermin
171 if ! febootstrap-to-initramfs --nocompress --files="$tmpdir/keep" "$1" > "$2"