You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.4 KiB
131 lines
3.4 KiB
![]()
16 years ago
|
#!/bin/bash --norc
|
||
![]()
15 years ago
|
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||
|
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||
|
#
|
||
![]()
16 years ago
|
# Copyright 2009 Red Hat, Inc. All rights reserved.
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation; either version 2 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
#
|
||
|
|
||
|
|
||
|
dwarning() {
|
||
|
echo "Warning: $@" >&2
|
||
|
}
|
||
|
|
||
|
dinfo() {
|
||
|
[[ $beverbose ]] && echo "$@" >&2
|
||
|
}
|
||
|
|
||
|
derror() {
|
||
|
echo "Error: $@" >&2
|
||
|
}
|
||
|
|
||
|
usage() {
|
||
|
# 80x25 linebreak here ^
|
||
![]()
15 years ago
|
cat << EOF
|
||
|
Usage: $0 [OPTION]... <initramfs> <base image> [<image>...]
|
||
![]()
16 years ago
|
Creates initial ramdisk image by concatenating several images from the command
|
||
|
line and /boot/dracut/
|
||
|
|
||
|
-f, --force Overwrite existing initramfs file.
|
||
![]()
14 years ago
|
-i, --imagedir Directory with additional images to add
|
||
![]()
16 years ago
|
(default: /boot/dracut/)
|
||
|
-o, --overlaydir Overlay directory, which contains files that
|
||
|
will be used to create an additional image
|
||
|
--nooverlay Do not use the overlay directory
|
||
|
--noimagedir Do not use the additional image directory
|
||
|
-h, --help This message
|
||
|
--debug Output debug information of the build process
|
||
|
-v, --verbose Verbose output during the build process
|
||
![]()
15 years ago
|
EOF
|
||
![]()
16 years ago
|
}
|
||
|
|
||
|
|
||
|
imagedir=/boot/dracut/
|
||
|
overlay=/var/lib/dracut/overlay
|
||
|
|
||
|
while (($# > 0)); do
|
||
|
case $1 in
|
||
![]()
15 years ago
|
-f|--force) force=yes;;
|
||
|
-i|--imagedir) imagedir=$2;shift;;
|
||
|
-o|--overlaydir) overlay=$2;shift;;
|
||
|
--nooverlay) no_overlay=yes;shift;;
|
||
|
--noimagedir) no_imagedir=yes;shift;;
|
||
|
-h|--help) usage; exit 1 ;;
|
||
|
--debug) debug="yes";;
|
||
|
-v|--verbose) beverbose="yes";;
|
||
|
-*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
|
||
|
*) break ;;
|
||
![]()
16 years ago
|
esac
|
||
|
shift
|
||
|
done
|
||
|
|
||
|
outfile=$1; shift
|
||
|
|
||
![]()
16 years ago
|
if [[ -z $outfile ]]; then
|
||
![]()
16 years ago
|
derror "No output file specified."
|
||
|
usage
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
baseimage=$1; shift
|
||
|
|
||
![]()
16 years ago
|
if [[ -z $baseimage ]]; then
|
||
![]()
16 years ago
|
derror "No base image specified."
|
||
|
usage
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
![]()
16 years ago
|
if [[ -f $outfile && ! $force ]]; then
|
||
![]()
16 years ago
|
derror "Will not override existing initramfs ($outfile) without --force"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
![]()
16 years ago
|
if [[ ! $no_imagedir && ! -d $imagedir ]]; then
|
||
![]()
16 years ago
|
derror "Image directory $overlay is not a directory"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
![]()
16 years ago
|
if [[ ! $no_overlay && ! -d $overlay ]]; then
|
||
![]()
16 years ago
|
derror "Overlay $overlay is not a directory"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
![]()
16 years ago
|
if [[ ! $no_overlay ]]; then
|
||
![]()
16 years ago
|
ofile="$imagedir/90-overlay.img"
|
||
|
dinfo "Creating image $ofile from directory $overlay"
|
||
![]()
15 years ago
|
type pigz &>/dev/null && gzip=pigz || gzip=gzip
|
||
|
( cd "$overlay"; find . |cpio --quiet -H newc -o |$gzip -9 > "$ofile"; )
|
||
![]()
16 years ago
|
fi
|
||
|
|
||
![]()
16 years ago
|
if [[ ! $no_imagedir ]]; then
|
||
|
for i in "$imagedir/"*.img; do
|
||
![]()
15 years ago
|
[[ -f $i ]] && images+=("$i")
|
||
![]()
16 years ago
|
done
|
||
![]()
16 years ago
|
fi
|
||
|
|
||
![]()
16 years ago
|
images+=($@)
|
||
![]()
16 years ago
|
|
||
|
dinfo "Using base image $baseimage"
|
||
![]()
16 years ago
|
cat "$baseimage" > "$outfile"
|
||
![]()
16 years ago
|
|
||
![]()
14 years ago
|
for i in "${images[@]}"; do
|
||
![]()
16 years ago
|
dinfo "Appending $i"
|
||
![]()
16 years ago
|
cat "$i" >> "$outfile"
|
||
![]()
16 years ago
|
done
|
||
|
|
||
|
dinfo "Created $outfile"
|
||
|
|
||
|
exit 0
|