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 # Ignore fakeroot.log.
81 if [ "$path" = "./fakeroot.log" ]; then
84 # Kernel modules are always copied in from the host, including all
85 # the dependency information files.
86 elif [[ "$path" =~ '^\./lib/modules/' ]]; then
89 # All we're going to keep are the special files /init, the daemon,
90 # configuration files (/etc), devices and modifiable stuff (/var).
91 elif [ "$path" = "./init" ]; then
94 elif [[ "$path" =~ '^\./etc' || "$path" =~ '^./dev' || "$path" =~ '^\./var' ]]; then
97 # Always write directory names to both output files.
98 elif [ -d "$path" ]; then
102 # Some libraries need fixed version numbers replaced by wildcards.
103 elif [[ "$file" =~ '^ld-[.0-9]+\.so$' ]]; then
104 echo "$dir/ld-*.so" >&6
107 elif [[ "$file" =~ '^lib(.*)-[-.0-9]+\.so$' ]]; then
108 echo "$dir/lib${BASH_REMATCH[1]}-*.so" >&6
110 # libfoo-1.2.3.so.1.2.3 (but NOT '*.so.N')
111 elif [[ "$file" =~ '^lib(.*)-[-.0-9]+\.so\.([0-9]+)\.' ]]; then
112 echo "$dir/lib${BASH_REMATCH[1]}-*.so.${BASH_REMATCH[2]}.*" >&6
114 # libfoo.so.1.2.3 (but NOT '*.so.N')
115 elif [[ "$file" =~ '^lib(.*)\.so\.([0-9]+)\.' ]]; then
116 echo "$dir/lib${BASH_REMATCH[1]}.so.${BASH_REMATCH[2]}.*" >&6
119 # Anything else comes from the host directly.
124 # Close output files.
128 # Now run febootstrap-to-initramfs to construct the supermin
130 if ! febootstrap-to-initramfs --nocompress --files="$tmpdir/keep" "$1" > "$2"