cd29b8aa42506b6db041fa32df7b24effb4e09b2
[libguestfs.git] / appliance / supermin-split.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 # Decide which files will stay in the supermin appliance and which
20 # files will be pulled out of the host at runtime.
21 #
22 # Read the README file!
23 #
24 # The basic idea is that we create two output files, one containing
25 # the files that will stay, and the other listing the files that
26 # will be pulled from the host (ie. not go into the appliance now).
27 #
28 # The list of files that stay ('supermin.incfiles') is just a straight
29 # list of files and directories.
30 #
31 # The list of files that come from the host ('*.supermin.hostfiles')
32 # can include wildcards, to allow libraries to be upgraded on the
33 # host.
34
35 unset CDPATH
36
37 set -e
38
39 cd @top_builddir@/initramfs
40
41 incfiles=../appliance/supermin.incfiles
42 hostfiles=../appliance/initramfs.@REPO@.@host_cpu@.supermin.hostfiles
43
44 exec 5>$incfiles
45 exec 6>$hostfiles
46
47 # Note currently the initramfs contains ~2500 files, and none have
48 # "funny characters" in the names.  So this is reasonable just to
49 # simplify the script.
50 for path in $(find -not -name fakeroot.log); do
51     dir=$(dirname "$path")
52     file=$(basename "$path")
53
54     # For quoting problems with the bash =~ operator, see bash FAQ
55     # question E14 here http://tiswww.case.edu/php/chet/bash/FAQ and
56     # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=487387#25
57     # (RHBZ#566511).
58     p_etc='^\./etc'
59     p_dev='^\./dev'
60     p_var='^\./var'
61     p_lib_modules='^\./lib/modules/'
62     p_builddir='^\./builddir'
63     p_ld_so='^ld-[.0-9]+\.so$'
64     p_libbfd='^libbfd-.*\.so$'
65     p_libgcc='^libgcc_s-.*\.so\.([0-9]+)$'
66     p_lib123so='^lib(.*)-[-.0-9]+\.so$'
67     p_lib123so123='^lib(.*)-[-.0-9]+\.so\.([0-9]+)\.'
68     p_libso123='^lib(.*)\.so\.([0-9]+)\.'
69
70     # All we're going to keep are the special files /init, the daemon,
71     # configuration files (/etc), devices and modifiable stuff (/var).
72     if [ "$path" = "./init" -o "$file" = "guestfsd" ]; then
73         echo "$path" >&5
74
75     elif [[ "$path" =~ $p_etc || "$path" =~ $p_dev || "$path" =~ $p_var ]]
76     then
77         echo "$path" >&5
78
79     # Kernel modules are always copied in from the host, including all
80     # the dependency files.
81     elif [[ "$path" =~ $p_lib_modules ]]; then
82         :
83
84     # On mock/Koji, exclude bogus /builddir directory which for some
85     # reason contains some yum temporary files (RHBZ#566512).
86     elif [[ "$path" =~ $p_builddir ]]; then
87         :
88
89     elif [ -d "$path" ]; then
90         # Always write directory names to both output files.
91         echo "$path" >&5
92         echo "$path" >&6
93
94     # Some libraries need fixed version numbers replaced by wildcards.
95
96     elif [[ "$file" =~ $p_ld_so ]]; then
97         echo "$dir/ld-*.so" >&6
98
99     # Special case for libbfd
100     elif [[ "$file" =~ $p_libbfd ]]; then
101         echo "$dir/libbfd-*.so" >&6
102
103     # Special case for libgcc_s-<gccversion>-<date>.so.N
104     elif [[ "$file" =~ $p_libgcc ]]; then
105         echo "$dir/libgcc_s-*.so.${BASH_REMATCH[1]}" >&6
106
107     # libfoo-1.2.3.so
108     elif [[ "$file" =~ $p_lib123so ]]; then
109         echo "$dir/lib${BASH_REMATCH[1]}-*.so" >&6
110
111     # libfoo-1.2.3.so.1.2.3 (but NOT '*.so.N')
112     elif [[ "$file" =~ $p_lib123so123 ]]; then
113         echo "$dir/lib${BASH_REMATCH[1]}-*.so.${BASH_REMATCH[2]}.*" >&6
114
115     # libfoo.so.1.2.3 (but NOT '*.so.N')
116     elif [[ "$file" =~ $p_libso123 ]]; then
117         echo "$dir/lib${BASH_REMATCH[1]}.so.${BASH_REMATCH[2]}.*" >&6
118
119     else
120         # Anything else comes from the host directly.
121         echo "$path" >&6
122     fi
123 done