summaryrefslogtreecommitdiffstats
path: root/0012-dracut-functions.sh-removed-non-dracut-install-shell.patch
blob: 72d04207c3cc13545df9a0a78f61350d2bf53123 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
From 55a0b3abc7b8da4f3714cfcb5d34f7aa4e78e5bc Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Mon, 5 Aug 2013 11:47:54 +0200
Subject: [PATCH] dracut-functions.sh: removed non dracut-install shell
 functions

---
 dracut-functions.sh | 315 ++++++++++------------------------------------------
 1 file changed, 56 insertions(+), 259 deletions(-)

diff --git a/dracut-functions.sh b/dracut-functions.sh
index dee53bb..c0a12cd 100755
--- a/dracut-functions.sh
+++ b/dracut-functions.sh
@@ -55,14 +55,6 @@ if ! [[ $dracutbasedir ]]; then
     dracutbasedir="$(readlink -f $dracutbasedir)"
 fi
 
-if ! [[ $DRACUT_INSTALL ]]; then
-    DRACUT_INSTALL=$(find_binary dracut-install)
-fi
-
-if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then
-    DRACUT_INSTALL=$dracutbasedir/dracut-install
-fi
-
 # Detect lib paths
 if ! [[ $libdirs ]] ; then
     if [[ "$(ldd /bin/sh)" == */lib64/* ]] &>/dev/null \
@@ -588,268 +580,73 @@ fs_get_option() {
     done
 }
 
-if [[ $DRACUT_INSTALL ]]; then
-    [[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
-    inst_dir() {
-        [[ -e ${initdir}/"$1" ]] && return 0  # already there
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" || :
-    }
-
-    inst() {
-        [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-        #dinfo "$DRACUT_INSTALL -l $@"
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
-
-    inst_simple() {
-        [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-        [[ -e $1 ]] || return 1  # no source
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" || :
-    }
-
-    inst_symlink() {
-        [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-        [[ -L $1 ]] || return 1
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
-
-    dracut_install() {
-        local ret
-        #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        ret=$?
-        (($ret != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-        return $ret
-    }
-
-    inst_library() {
-        [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-        [[ -e $1 ]] || return 1  # no source
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
-
-    inst_binary() {
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
-
-    inst_script() {
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
-
-else
-
-    # Install a directory, keeping symlinks as on the original system.
-    # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
-    # will create ${initdir}/lib64, ${initdir}/lib64/file,
-    # and a symlink ${initdir}/lib -> lib64.
-    inst_dir() {
-        [[ -e ${initdir}/"$1" ]] && return 0  # already there
-
-        local _dir="$1" _part="${1%/*}" _file
-        while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
-            _dir="$_part $_dir"
-            _part=${_part%/*}
-        done
-
-        # iterate over parent directories
-        for _file in $_dir; do
-            [[ -e "${initdir}/$_file" ]] && continue
-            if [[ -L $_file ]]; then
-                inst_symlink "$_file"
-            else
-            # create directory
-                mkdir -m 0755 -p "${initdir}/$_file" || return 1
-                [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
-                chmod u+w "${initdir}/$_file"
-            fi
-        done
-    }
 
-    # $1 = file to copy to ramdisk
-    # $2 (optional) Name for the file on the ramdisk
-    # Location of the image dir is assumed to be $initdir
-    # We never overwrite the target if it exists.
-    inst_simple() {
-        [[ -f "$1" ]] || return 1
-        [[ "$1" == */* ]] || return 1
-        local _src=$1 _target="${2:-$1}"
-
-        [[ -L $_src ]] && { inst_symlink $_src $_target; return $?; }
-
-        if ! [[ -d ${initdir}/$_target ]]; then
-            [[ -e ${initdir}/$_target ]] && return 0
-            [[ -L ${initdir}/$_target ]] && return 0
-            [[ -d "${initdir}/${_target%/*}" ]] || inst_dir "${_target%/*}"
-        fi
-        if [[ $DRACUT_FIPS_MODE ]]; then
-            # install checksum files also
-            if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
-                inst "${_src%/*}/.${_src##*/}.hmac" "${_target%/*}/.${_target##*/}.hmac"
-            fi
-            if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
-                inst "/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_target##*/}.hmac"
-            fi
-            if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
-                inst "/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_target##*/}.hmac"
-            fi
-        fi
-        ddebug "Installing $_src"
-        cp --reflink=auto --sparse=auto -pfL "$_src" "${initdir}/$_target"
-    }
+if ! [[ $DRACUT_INSTALL ]]; then
+    DRACUT_INSTALL=$(find_binary dracut-install)
+fi
 
-    # same as above, but specialized for symlinks
-    inst_symlink() {
-        local _src=$1 _target=${2:-$1} _realsrc
-        [[ "$1" == */* ]] || return 1
-        [[ -L $1 ]] || return 1
-        [[ -L $initdir/$_target ]] && return 0
-        _realsrc=$(readlink -f "$_src")
-        if ! [[ -e $initdir/$_realsrc ]]; then
-            if [[ -d $_realsrc ]]; then
-                inst_dir "$_realsrc"
-            else
-                inst "$_realsrc"
-            fi
-        fi
-        [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
+if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then
+    DRACUT_INSTALL=$dracutbasedir/dracut-install
+fi
 
-        ln_r "${_realsrc}" "${_target}"
-    }
+if ! [[ -x $DRACUT_INSTALL ]]; then
+    dfatal "dracut-install not found!"
+    exit 10
+fi
 
-    # Same as above, but specialized to handle dynamic libraries.
-    # It handles making symlinks according to how the original library
-    # is referenced.
-    inst_library() {
-        local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
-        [[ "$1" == */* ]] || return 1
-        [[ -e $initdir/$_dest ]] && return 0
-        if [[ -L $_src ]]; then
-            if [[ $DRACUT_FIPS_MODE ]]; then
-                # install checksum files also
-                if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
-                    inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
-                fi
-                if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
-                    inst "/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_dest##*/}.hmac"
-                fi
-                if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
-                    inst "/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_dest##*/}.hmac"
-                fi
-            fi
-            _reallib=$(readlink -f "$_src")
-            inst_simple "$_reallib" "$_reallib"
-            inst_dir "${_dest%/*}"
-            ln_r "${_reallib}" "${_dest}"
-        else
-            inst_simple "$_src" "$_dest"
-        fi
+[[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
+inst_dir() {
+    [[ -e ${initdir}/"$1" ]] && return 0  # already there
+    $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" || :
+}
 
-        # Create additional symlinks.  See rev_symlinks description.
-        for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
-            [[ ! -e $initdir/$_symlink ]] && {
-                ddebug "Creating extra symlink: $_symlink"
-                inst_symlink $_symlink
-            }
-        done
-    }
+inst() {
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+        #dinfo "$DRACUT_INSTALL -l $@"
+    $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" || :
+}
 
-    # Same as above, but specialized to install binary executables.
-    # Install binary executable, and all shared library dependencies, if any.
-    inst_binary() {
-        local _bin _target
-        _bin=$(find_binary "$1") || return 1
-        _target=${2:-$_bin}
-        [[ -e $initdir/$_target ]] && return 0
-        local _file _line
-        local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
-        # I love bash!
-        LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
-            [[ $_line = 'not a dynamic executable' ]] && break
-
-            if [[ $_line =~ $_so_regex ]]; then
-                _file=${BASH_REMATCH[1]}
-                [[ -e ${initdir}/$_file ]] && continue
-                inst_library "$_file"
-                continue
-            fi
+inst_simple() {
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -e $1 ]] || return 1  # no source
+    $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" || :
+}
 
-            if [[ $_line == *not\ found* ]]; then
-                dfatal "Missing a shared library required by $_bin."
-                dfatal "Run \"ldd $_bin\" to find out what it is."
-                dfatal "$_line"
-                dfatal "dracut cannot create an initrd."
-                exit 1
-            fi
-        done
-        inst_simple "$_bin" "$_target"
-    }
+inst_symlink() {
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -L $1 ]] || return 1
+    $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
+}
 
-    # same as above, except for shell scripts.
-    # If your shell script does not start with shebang, it is not a shell script.
-    inst_script() {
-        local _bin
-        _bin=$(find_binary "$1") || return 1
-        shift
-        local _line _shebang_regex
-        read -r -n 80 _line <"$_bin"
-        # If debug is set, clean unprintable chars to prevent messing up the term
-        [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
-        _shebang_regex='(#! *)(/[^ ]+).*'
-        [[ $_line =~ $_shebang_regex ]] || return 1
-        inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
-    }
+dracut_install() {
+    local ret
+        #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
+    $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
+    ret=$?
+    (($ret != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
+    return $ret
+}
 
-    # general purpose installation function
-    # Same args as above.
-    inst() {
-        local _x
-
-        case $# in
-            1) ;;
-            2) [[ ! $initdir && -d $2 ]] && export initdir=$2
-                [[ $initdir = $2 ]] && set $1;;
-            3) [[ -z $initdir ]] && export initdir=$2
-                set $1 $3;;
-            *) dfatal "inst only takes 1 or 2 or 3 arguments"
-                exit 1;;
-        esac
-        for _x in inst_symlink inst_script inst_binary inst_simple; do
-            $_x "$@" && return 0
-        done
-        return 1
-    }
+inst_library() {
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -e $1 ]] || return 1  # no source
+    $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
+}
 
-    # dracut_install [-o ] <file> [<file> ... ]
-    # Install <file> to the initramfs image
-    # -o optionally install the <file> and don't fail, if it is not there
-    dracut_install() {
-        local _optional=no
-        if [[ $1 = '-o' ]]; then
-            _optional=yes
-            shift
-        fi
-        while (($# > 0)); do
-            if ! inst "$1" ; then
-                if [[ $_optional = yes ]]; then
-                    dinfo "Skipping program $1 as it cannot be found and is" \
-                        "flagged to be optional"
-                else
-                    dfatal "Failed to install $1"
-                    exit 1
-                fi
-            fi
-            shift
-        done
-    }
+inst_binary() {
+    $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
+}
 
-fi
+inst_script() {
+    $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
+}
 
 # find symlinks linked to given library file
 # $1 = library file