]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | dwarning() { | |
23 | echo "Warning: $@" >&2 | |
24 | } | |
25 | ||
26 | dinfo() { | |
27 | [[ $beverbose ]] && echo "$@" >&2 | |
28 | } | |
29 | ||
30 | derror() { | |
31 | echo "Error: $@" >&2 | |
32 | } | |
33 | ||
34 | usage() { | |
35 | # 80x25 linebreak here ^ | |
cc02093d HH |
36 | cat << EOF |
37 | Usage: $0 [OPTION]... <initramfs> <base image> [<image>...] | |
5494f08c HH |
38 | Creates initial ramdisk image by concatenating several images from the command |
39 | line 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 | 51 | EOF |
5494f08c HH |
52 | } |
53 | ||
54 | ||
55 | imagedir=/boot/dracut/ | |
56 | overlay=/var/lib/dracut/overlay | |
57 | ||
58 | while (($# > 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 | |
72 | done | |
73 | ||
74 | outfile=$1; shift | |
75 | ||
2790d5b2 | 76 | if [[ -z $outfile ]]; then |
5494f08c HH |
77 | derror "No output file specified." |
78 | usage | |
79 | exit 1 | |
80 | fi | |
81 | ||
82 | baseimage=$1; shift | |
83 | ||
2790d5b2 | 84 | if [[ -z $baseimage ]]; then |
5494f08c HH |
85 | derror "No base image specified." |
86 | usage | |
87 | exit 1 | |
88 | fi | |
89 | ||
2790d5b2 | 90 | if [[ -f $outfile && ! $force ]]; then |
5494f08c HH |
91 | derror "Will not override existing initramfs ($outfile) without --force" |
92 | exit 1 | |
93 | fi | |
94 | ||
2790d5b2 | 95 | if [[ ! $no_imagedir && ! -d $imagedir ]]; then |
5494f08c HH |
96 | derror "Image directory $overlay is not a directory" |
97 | exit 1 | |
98 | fi | |
99 | ||
2790d5b2 | 100 | if [[ ! $no_overlay && ! -d $overlay ]]; then |
5494f08c HH |
101 | derror "Overlay $overlay is not a directory" |
102 | exit 1 | |
103 | fi | |
104 | ||
2790d5b2 | 105 | if [[ ! $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 |
110 | fi |
111 | ||
2790d5b2 VL |
112 | if [[ ! $no_imagedir ]]; then |
113 | for i in "$imagedir/"*.img; do | |
cc02093d | 114 | [[ -f $i ]] && images+=("$i") |
2790d5b2 | 115 | done |
5494f08c HH |
116 | fi |
117 | ||
2790d5b2 | 118 | images+=($@) |
5494f08c HH |
119 | |
120 | dinfo "Using base image $baseimage" | |
2790d5b2 | 121 | cat "$baseimage" > "$outfile" |
5494f08c | 122 | |
3b403b32 | 123 | for i in "${images[@]}"; do |
5494f08c | 124 | dinfo "Appending $i" |
2790d5b2 | 125 | cat "$i" >> "$outfile" |
5494f08c HH |
126 | done |
127 | ||
128 | dinfo "Created $outfile" | |
129 | ||
130 | exit 0 |