]>
Commit | Line | Data |
---|---|---|
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 | ||
5494f08c | 19 | dwarning() { |
22fceeac | 20 | echo "Warning: $*" >&2 |
5494f08c HH |
21 | } |
22 | ||
23 | dinfo() { | |
24 | [[ $beverbose ]] && echo "$@" >&2 | |
25 | } | |
26 | ||
27 | derror() { | |
22fceeac | 28 | echo "Error: $*" >&2 |
5494f08c HH |
29 | } |
30 | ||
31 | usage() { | |
560402c3 | 32 | # 80x25 linebreak here ^ |
cc02093d HH |
33 | cat << EOF |
34 | Usage: $0 [OPTION]... <initramfs> <base image> [<image>...] | |
5494f08c HH |
35 | Creates initial ramdisk image by concatenating several images from the command |
36 | line and /boot/dracut/ | |
37 | ||
38 | -f, --force Overwrite existing initramfs file. | |
3b403b32 | 39 | -i, --imagedir Directory with additional images to add |
5494f08c HH |
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 | |
cc02093d | 48 | EOF |
5494f08c HH |
49 | } |
50 | ||
5494f08c HH |
51 | imagedir=/boot/dracut/ |
52 | overlay=/var/lib/dracut/overlay | |
53 | ||
54 | while (($# > 0)); do | |
55 | case $1 in | |
9a52c3fd HH |
56 | -f | --force) force=yes ;; |
57 | -i | --imagedir) | |
58 | imagedir=$2 | |
59 | shift | |
60 | ;; | |
61 | -o | --overlaydir) | |
62 | overlay=$2 | |
63 | shift | |
64 | ;; | |
65 | --nooverlay) | |
66 | no_overlay=yes | |
67 | shift | |
68 | ;; | |
69 | --noimagedir) | |
70 | no_imagedir=yes | |
71 | shift | |
72 | ;; | |
73 | -h | --help) | |
74 | usage | |
75 | exit 1 | |
76 | ;; | |
77 | --debug) export debug="yes" ;; | |
78 | -v | --verbose) beverbose="yes" ;; | |
79 | -*) | |
80 | printf "\nUnknown option: %s\n\n" "$1" >&2 | |
81 | usage | |
82 | exit 1 | |
83 | ;; | |
cc02093d | 84 | *) break ;; |
5494f08c HH |
85 | esac |
86 | shift | |
87 | done | |
88 | ||
9a52c3fd HH |
89 | outfile=$1 |
90 | shift | |
5494f08c | 91 | |
2790d5b2 | 92 | if [[ -z $outfile ]]; then |
5494f08c HH |
93 | derror "No output file specified." |
94 | usage | |
95 | exit 1 | |
96 | fi | |
97 | ||
9a52c3fd HH |
98 | baseimage=$1 |
99 | shift | |
5494f08c | 100 | |
2790d5b2 | 101 | if [[ -z $baseimage ]]; then |
5494f08c HH |
102 | derror "No base image specified." |
103 | usage | |
104 | exit 1 | |
105 | fi | |
106 | ||
2790d5b2 | 107 | if [[ -f $outfile && ! $force ]]; then |
5494f08c HH |
108 | derror "Will not override existing initramfs ($outfile) without --force" |
109 | exit 1 | |
110 | fi | |
111 | ||
2790d5b2 | 112 | if [[ ! $no_imagedir && ! -d $imagedir ]]; then |
5494f08c HH |
113 | derror "Image directory $overlay is not a directory" |
114 | exit 1 | |
115 | fi | |
116 | ||
2790d5b2 | 117 | if [[ ! $no_overlay && ! -d $overlay ]]; then |
5494f08c HH |
118 | derror "Overlay $overlay is not a directory" |
119 | exit 1 | |
120 | fi | |
121 | ||
2790d5b2 | 122 | if [[ ! $no_overlay ]]; then |
5494f08c HH |
123 | ofile="$imagedir/90-overlay.img" |
124 | dinfo "Creating image $ofile from directory $overlay" | |
9a52c3fd HH |
125 | type pigz &> /dev/null && gzip=pigz || gzip=gzip |
126 | ( | |
127 | cd "$overlay" || return 1 | |
128 | find . | cpio --quiet -H newc -o | $gzip -9 > "$ofile" | |
129 | ) | |
5494f08c HH |
130 | fi |
131 | ||
2790d5b2 VL |
132 | if [[ ! $no_imagedir ]]; then |
133 | for i in "$imagedir/"*.img; do | |
cc02093d | 134 | [[ -f $i ]] && images+=("$i") |
2790d5b2 | 135 | done |
5494f08c HH |
136 | fi |
137 | ||
9a52c3fd | 138 | images+=("$@") |
5494f08c HH |
139 | |
140 | dinfo "Using base image $baseimage" | |
b093aa2d | 141 | cat -- "$baseimage" > "$outfile" |
5494f08c | 142 | |
3b403b32 | 143 | for i in "${images[@]}"; do |
5494f08c | 144 | dinfo "Appending $i" |
b093aa2d | 145 | cat -- "$i" >> "$outfile" |
5494f08c HH |
146 | done |
147 | ||
148 | dinfo "Created $outfile" | |
149 | ||
150 | exit 0 |