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