dracut-systemd/dracut-initqueue: only start service if really needed
[dracut.git] / dracut-catimages.sh
blob1f53a2d3877095eeafbc9ff3c28a79ab60b40037
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 cat << EOF
35 Usage: $0 [OPTION]... <initramfs> <base image> [<image>...]
36 Creates initial ramdisk image by concatenating several images from the command
37 line and /boot/dracut/
39 -f, --force Overwrite existing initramfs file.
40 -i, --imagedir Directory with additional images to add
41 (default: /boot/dracut/)
42 -o, --overlaydir Overlay directory, which contains files that
43 will be used to create an additional image
44 --nooverlay Do not use the overlay directory
45 --noimagedir Do not use the additional image directory
46 -h, --help This message
47 --debug Output debug information of the build process
48 -v, --verbose Verbose output during the build process
49 EOF
53 imagedir=/boot/dracut/
54 overlay=/var/lib/dracut/overlay
56 while (($# > 0)); do
57 case $1 in
58 -f|--force) force=yes;;
59 -i|--imagedir) imagedir=$2;shift;;
60 -o|--overlaydir) overlay=$2;shift;;
61 --nooverlay) no_overlay=yes;shift;;
62 --noimagedir) no_imagedir=yes;shift;;
63 -h|--help) usage; exit 1 ;;
64 --debug) debug="yes";;
65 -v|--verbose) beverbose="yes";;
66 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
67 *) break ;;
68 esac
69 shift
70 done
72 outfile=$1; shift
74 if [[ -z $outfile ]]; then
75 derror "No output file specified."
76 usage
77 exit 1
80 baseimage=$1; shift
82 if [[ -z $baseimage ]]; then
83 derror "No base image specified."
84 usage
85 exit 1
88 if [[ -f $outfile && ! $force ]]; then
89 derror "Will not override existing initramfs ($outfile) without --force"
90 exit 1
93 if [[ ! $no_imagedir && ! -d $imagedir ]]; then
94 derror "Image directory $overlay is not a directory"
95 exit 1
98 if [[ ! $no_overlay && ! -d $overlay ]]; then
99 derror "Overlay $overlay is not a directory"
100 exit 1
103 if [[ ! $no_overlay ]]; then
104 ofile="$imagedir/90-overlay.img"
105 dinfo "Creating image $ofile from directory $overlay"
106 type pigz &>/dev/null && gzip=pigz || gzip=gzip
107 ( cd "$overlay"; find . |cpio --quiet -H newc -o |$gzip -9 > "$ofile"; )
110 if [[ ! $no_imagedir ]]; then
111 for i in "$imagedir/"*.img; do
112 [[ -f $i ]] && images+=("$i")
113 done
116 images+=($@)
118 dinfo "Using base image $baseimage"
119 cat -- "$baseimage" > "$outfile"
121 for i in "${images[@]}"; do
122 dinfo "Appending $i"
123 cat -- "$i" >> "$outfile"
124 done
126 dinfo "Created $outfile"
128 exit 0