]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut-catimages.sh
iscsi: always popd, even if there is no iscsi device
[thirdparty/dracut.git] / dracut-catimages.sh
CommitLineData
5494f08c 1#!/bin/bash --norc
cc02093d 2#
5494f08c
HH
3# Copyright 2009 Red Hat, Inc. All rights reserved.
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, see <http://www.gnu.org/licenses/>.
17#
18
19
20dwarning() {
21 echo "Warning: $@" >&2
22}
23
24dinfo() {
25 [[ $beverbose ]] && echo "$@" >&2
26}
27
28derror() {
29 echo "Error: $@" >&2
30}
31
32usage() {
33# 80x25 linebreak here ^
cc02093d
HH
34 cat << EOF
35Usage: $0 [OPTION]... <initramfs> <base image> [<image>...]
5494f08c
HH
36Creates initial ramdisk image by concatenating several images from the command
37line and /boot/dracut/
38
39 -f, --force Overwrite existing initramfs file.
3b403b32 40 -i, --imagedir Directory with additional images to add
5494f08c
HH
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
cc02093d 49EOF
5494f08c
HH
50}
51
52
53imagedir=/boot/dracut/
54overlay=/var/lib/dracut/overlay
55
56while (($# > 0)); do
57 case $1 in
cc02093d
HH
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 ;;
5494f08c
HH
68 esac
69 shift
70done
71
72outfile=$1; shift
73
2790d5b2 74if [[ -z $outfile ]]; then
5494f08c
HH
75 derror "No output file specified."
76 usage
77 exit 1
78fi
79
80baseimage=$1; shift
81
2790d5b2 82if [[ -z $baseimage ]]; then
5494f08c
HH
83 derror "No base image specified."
84 usage
85 exit 1
86fi
87
2790d5b2 88if [[ -f $outfile && ! $force ]]; then
5494f08c
HH
89 derror "Will not override existing initramfs ($outfile) without --force"
90 exit 1
91fi
92
2790d5b2 93if [[ ! $no_imagedir && ! -d $imagedir ]]; then
5494f08c
HH
94 derror "Image directory $overlay is not a directory"
95 exit 1
96fi
97
2790d5b2 98if [[ ! $no_overlay && ! -d $overlay ]]; then
5494f08c
HH
99 derror "Overlay $overlay is not a directory"
100 exit 1
101fi
102
2790d5b2 103if [[ ! $no_overlay ]]; then
5494f08c
HH
104 ofile="$imagedir/90-overlay.img"
105 dinfo "Creating image $ofile from directory $overlay"
c9157078
VS
106 type pigz &>/dev/null && gzip=pigz || gzip=gzip
107 ( cd "$overlay"; find . |cpio --quiet -H newc -o |$gzip -9 > "$ofile"; )
5494f08c
HH
108fi
109
2790d5b2
VL
110if [[ ! $no_imagedir ]]; then
111 for i in "$imagedir/"*.img; do
cc02093d 112 [[ -f $i ]] && images+=("$i")
2790d5b2 113 done
5494f08c
HH
114fi
115
2790d5b2 116images+=($@)
5494f08c
HH
117
118dinfo "Using base image $baseimage"
b093aa2d 119cat -- "$baseimage" > "$outfile"
5494f08c 120
3b403b32 121for i in "${images[@]}"; do
5494f08c 122 dinfo "Appending $i"
b093aa2d 123 cat -- "$i" >> "$outfile"
5494f08c
HH
124done
125
126dinfo "Created $outfile"
127
128exit 0