[Ovirt-devel] [PATCH node-image] edit-livecd: optionally append kernel boot params
Jim Meyering
jim at meyering.net
Tue Dec 2 11:13:16 UTC 2008
Alan Pevec <apevec at redhat.com> wrote:
> ---
> edit-livecd | 37 +++++++++++++++++++++++++++++--------
> 1 files changed, 29 insertions(+), 8 deletions(-)
Good timing, since I was just considering changing usage to require
something like an --output=FILE option to specify the output
file name, rather than using $(basename $ISO .iso)-custom.iso,
which puts the result in the current directory.
> diff --git a/edit-livecd b/edit-livecd
> index 0200034..8025fb6 100755
> --- a/edit-livecd
> +++ b/edit-livecd
> @@ -25,12 +25,17 @@ warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
> try_h() { printf "Try \`$ME -h' for more information.\n" >&2; }
> die() { warn "$@"; try_h; exit 1; }
>
> +NODEIMG_DEFAULT=/usr/share/ovirt-node-image/ovirt-node-image.iso
> +CD=$NODEIMG_DEFAULT
> +
> usage() {
> case $# in 1) warn "$1"; try_h; exit 1;; esac
> cat <<EOF
> -Usage: $ME livecd.iso program
> - livecd.iso - LiveCD ISO to edit
> - program - Arbitrary program/script that is run inside of the livecd root
> +Usage: $ME -i LiveCD.iso [-b bootparams] [-p program]
> + -h: display this help and exit
> + -i: livecd.iso - LiveCD ISO to edit (default: $NODEIMG_DEFAULT)
> + -b: bootparams - optional parameters appended to the kernel command line
> + -p: program - Arbitrary program/script that is run inside of the livecd root
Please remove the ":" after each option, and leave at least two spaces
between option-arg and description (in case we ever use help2man):
-h display this help and exit
-i livecd.iso LiveCD ISO to edit (default: $NODEIMG_DEFAULT)
-b bootparams optional parameters appended to the kernel command line
-p program Arbitrary program/script that is run inside of the livecd
...
> @@ -48,16 +53,26 @@ EOF
> # exit after any error:
> set -e
>
> -test $# -lt 1 && { usage; exit 1; }
> +err=0 help=0
> +while getopts :b:i:p:h c; do
> + case $c in
> + i) CD=$OPTARG;;
> + b) PARAMS=$OPTARG;;
> + p) PROG=$OPTARG;;
> + h) help=1;;
> + '?') err=1; warn "invalid option: \`-$OPTARG'";;
> + :) err=1; warn "missing argument to \`-$OPTARG' option";;
> + *) err=1; warn "internal error: \`-$OPTARG' not handled";;
> + esac
> +done
> +test $err = 1 && { try_h; exit 1; }
> +test $help = 1 && { usage; exit 0; }
>
> # first, check to see we are root
> if [ $( id -u ) -ne 0 ]; then
> die "Must run as root"
> fi
>
> -CD=$1
> -PROG=$2
> -
> which mkisofs mksquashfs sed > /dev/null 2>&1
>
> WDIR=`mktemp -d $PWD/livecd.XXXXXXXXXX`
> @@ -81,7 +96,8 @@ function mnt() {
>
> addExit "rm -Rf $WDIR"
>
> -LABEL=$(isoinfo -d -i $CD | awk -F ": " '/Volume id:/ {print $2}')
> +eval $(/lib/udev/vol_id $CD)
You'll want extra quotes, to be safe:
eval "$(/lib/udev/vol_id $CD)"
> +LABEL=$ID_FS_LABEL
>
> # mount the CD image
> mnt "-t auto $CD -o loop,ro" cd
> @@ -122,6 +138,11 @@ mksquashfs $WDIR/sq-w/ $WDIR/cd-w/LiveOS/squashfs.img -noappend
> echo ">>> Recomputing MD5 sums"
> ( cd $WDIR/cd-w && find . -type f -not -name md5sum.txt -not -path '*/isolinux/*' -print0 | xargs -0 -- md5sum > md5sum.txt )
>
> +if [ -n "$PARAMS" ]; then
> + echo ">>> Appending boot parameters"
> + sed -i 's/^ append .*$/& '$PARAMS/ "$WDIR/cd-w/isolinux/isolinux.cfg"
and you need quotes around $PARAMS:
sed -i 's/^ append .*$/& '"$PARAMS"/ "$WDIR/cd-w/isolinux/isolinux.cfg"
And you'll also want to make the script fail -- or maybe
try to find a usable sed delimiter if $PARAMS contains a slash.
> +fi
> +
> echo ">>> Creating ISO image $ISO"
> mkisofs \
> -V "$LABEL" \
More information about the ovirt-devel
mailing list