dracut-lib: improve die() logging
[dracut.git] / dracut-catimages
blob88c404d944f05da37fe9e85239ffa6d208965d98
1 #!/bin/bash --norc
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # Copyright 2009 Red Hat, Inc. All rights reserved.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 dwarning() {
23 echo "Warning: $@" >&2
26 dinfo() {
27 [[ $beverbose ]] && echo "$@" >&2
30 derror() {
31 echo "Error: $@" >&2
34 usage() {
35 # 80x25 linebreak here ^
36 cat << EOF
37 Usage: $0 [OPTION]... <initramfs> <base image> [<image>...]
38 Creates initial ramdisk image by concatenating several images from the command
39 line and /boot/dracut/
41 -f, --force Overwrite existing initramfs file.
42 -i, --imagedir Directory with additional images to add
43 (default: /boot/dracut/)
44 -o, --overlaydir Overlay directory, which contains files that
45 will be used to create an additional image
46 --nooverlay Do not use the overlay directory
47 --noimagedir Do not use the additional image directory
48 -h, --help This message
49 --debug Output debug information of the build process
50 -v, --verbose Verbose output during the build process
51 EOF
55 imagedir=/boot/dracut/
56 overlay=/var/lib/dracut/overlay
58 while (($# > 0)); do
59 case $1 in
60 -f|--force) force=yes;;
61 -i|--imagedir) imagedir=$2;shift;;
62 -o|--overlaydir) overlay=$2;shift;;
63 --nooverlay) no_overlay=yes;shift;;
64 --noimagedir) no_imagedir=yes;shift;;
65 -h|--help) usage; exit 1 ;;
66 --debug) debug="yes";;
67 -v|--verbose) beverbose="yes";;
68 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
69 *) break ;;
70 esac
71 shift
72 done
74 outfile=$1; shift
76 if [[ -z $outfile ]]; then
77 derror "No output file specified."
78 usage
79 exit 1
82 baseimage=$1; shift
84 if [[ -z $baseimage ]]; then
85 derror "No base image specified."
86 usage
87 exit 1
90 if [[ -f $outfile && ! $force ]]; then
91 derror "Will not override existing initramfs ($outfile) without --force"
92 exit 1
95 if [[ ! $no_imagedir && ! -d $imagedir ]]; then
96 derror "Image directory $overlay is not a directory"
97 exit 1
100 if [[ ! $no_overlay && ! -d $overlay ]]; then
101 derror "Overlay $overlay is not a directory"
102 exit 1
105 if [[ ! $no_overlay ]]; then
106 ofile="$imagedir/90-overlay.img"
107 dinfo "Creating image $ofile from directory $overlay"
108 type pigz &>/dev/null && gzip=pigz || gzip=gzip
109 ( cd "$overlay"; find . |cpio --quiet -H newc -o |$gzip -9 > "$ofile"; )
112 if [[ ! $no_imagedir ]]; then
113 for i in "$imagedir/"*.img; do
114 [[ -f $i ]] && images+=("$i")
115 done
118 images+=($@)
120 dinfo "Using base image $baseimage"
121 cat "$baseimage" > "$outfile"
123 for i in "${images[@]}"; do
124 dinfo "Appending $i"
125 cat "$i" >> "$outfile"
126 done
128 dinfo "Created $outfile"
130 exit 0