90mdraid dracut-functions: fix md raid hostonly detection
[dracut.git] / dracut-catimages
blobd49d0e2a4b3c66a7577545487df9928a7947237d
1 #!/bin/bash --norc
3 # Copyright 2009 Red Hat, Inc. All rights reserved.
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, see <http://www.gnu.org/licenses/>.
20 dwarning() {
21 echo "Warning: $@" >&2
24 dinfo() {
25 [[ $beverbose ]] && echo "$@" >&2
28 derror() {
29 echo "Error: $@" >&2
32 usage() {
33 # 80x25 linebreak here ^
34 echo "Usage: $0 [OPTION]... <initramfs> <base image> [<image>...]
35 Creates initial ramdisk image by concatenating several images from the command
36 line and /boot/dracut/
38 -f, --force Overwrite existing initramfs file.
39 -i, --imagedir Directory with additional images to add
40 (default: /boot/dracut/)
41 -o, --overlaydir Overlay directory, which contains files that
42 will be used to create an additional image
43 --nooverlay Do not use the overlay directory
44 --noimagedir Do not use the additional image directory
45 -h, --help This message
46 --debug Output debug information of the build process
47 -v, --verbose Verbose output during the build process
52 imagedir=/boot/dracut/
53 overlay=/var/lib/dracut/overlay
55 while (($# > 0)); do
56 case $1 in
57 -f|--force) force=yes;;
58 -i|--imagedir) imagedir=$2;shift;;
59 -o|--overlaydir) overlay=$2;shift;;
60 --nooverlay) no_overlay=yes;shift;;
61 --noimagedir) no_imagedir=yes;shift;;
62 -h|--help) usage; exit 1 ;;
63 --debug) debug="yes";;
64 -v|--verbose) beverbose="yes";;
65 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
66 *) break ;;
67 esac
68 shift
69 done
71 outfile=$1; shift
73 if [[ -z $outfile ]]; then
74 derror "No output file specified."
75 usage
76 exit 1
79 baseimage=$1; shift
81 if [[ -z $baseimage ]]; then
82 derror "No base image specified."
83 usage
84 exit 1
87 if [[ -f $outfile && ! $force ]]; then
88 derror "Will not override existing initramfs ($outfile) without --force"
89 exit 1
92 if [[ ! $no_imagedir && ! -d $imagedir ]]; then
93 derror "Image directory $overlay is not a directory"
94 exit 1
97 if [[ ! $no_overlay && ! -d $overlay ]]; then
98 derror "Overlay $overlay is not a directory"
99 exit 1
102 if [[ ! $no_overlay ]]; then
103 ofile="$imagedir/90-overlay.img"
104 dinfo "Creating image $ofile from directory $overlay"
105 type pigz &>/dev/null && gzip=pigz || gzip=gzip
106 ( cd "$overlay"; find . |cpio --quiet -H newc -o |$gzip -9 > "$ofile"; )
109 if [[ ! $no_imagedir ]]; then
110 for i in "$imagedir/"*.img; do
111 [[ -f $i ]] && images+=("$i")
112 done
115 images+=($@)
117 dinfo "Using base image $baseimage"
118 cat "$baseimage" > "$outfile"
120 for i in "${images[@]}"; do
121 dinfo "Appending $i"
122 cat "$i" >> "$outfile"
123 done
125 dinfo "Created $outfile"
127 exit 0