[Ovirt-devel] [PATCH node-image] edit-livecd: optionally append kernel boot params

Jim Meyering jim at meyering.net
Tue Dec 2 15:53:41 UTC 2008


Jim Meyering <jim at meyering.net> wrote:

> 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

Hi Alan,

Here's an incremental diff on top of yours.
It reflects the comments I sent already in this thread,
fixes a couple more things, and adds a few FIXME comments.
If this looks ok to you, let me know and I'll amend and push the result.

  cat <<EOF > TeST
  #!/bin/sh
  test -f etc/TeST && ls -l etc/TeST
  touch etc/TeST
  EOF
  chmod a+x TeST
  ./edit-livecd -p TeST -i ovirt-node-image.iso
  ./edit-livecd -p TeST -i ovirt-node-image-custom.iso

and noted that the latter run did output this:

  -rw-r--r--. 1 root root 0 2008-12-02 16:50 etc/TeST

Note the -p PROGRAM-related FIXME.
When I make that change I'll also realign the --help output.

Jim
------------------------

diff --git a/edit-livecd b/edit-livecd
index 8025fb6..c122eee 100755
--- a/edit-livecd
+++ b/edit-livecd
@@ -32,15 +32,15 @@ usage() {
     case $# in 1) warn "$1"; try_h; exit 1;; esac
     cat <<EOF
 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
+  -b BOOTPARAMS  optional parameters appended to the kernel command line
+  -i LIVECD.iso  LiveCD ISO to edit (default: $NODEIMG_DEFAULT)
+  -p PROGRAM     Arbitrary program/script that is run inside of the livecd root
             filesystem.  This script is not run in a chroot environment so
             it can access the host filesystem.  The program should be executable
             If program is omitted the script will pause and allow the user in
             another terminal to edit the filesystem manually.  After enter is
             pushed the script will re-package up the ISO.
+  -h             display this help and exit

   Example Script:
     #!/bin/sh
@@ -50,6 +50,13 @@ Usage: $ME -i LiveCD.iso [-b bootparams] [-p program]
 EOF
 }

+# FIXME: instead of requiring a PROGRAM, allow arbitrary shell code,
+# so we can invoke $0 -p 'touch etc/sysconfig/foo' ...
+# This means that if you *do* have a program in the current directory
+# running "$0 -p ./my-script" won't work, since it'll be run with
+# a different working dir.  However, *this* will:
+# $0 -p "$PWD/my-script"
+
 # exit after any error:
 set -e

@@ -73,9 +80,14 @@ if [ $( id -u ) -ne 0 ]; then
     die "Must run as root"
 fi

+# FIXME: don't use which: with bash, it's a separate program
+# FIXME: When failing due to a missing required program, tell the user why.
 which mkisofs mksquashfs sed > /dev/null 2>&1

 WDIR=`mktemp -d $PWD/livecd.XXXXXXXXXX`
+# FIXME: fail if $WDIR contains white space or shell meta-characters
+# FIXME: do the same for $CD.
+
 ISO="${CD##*/}"
 ISO="${ISO%.iso}-custom.iso"

@@ -94,9 +106,9 @@ function mnt() {
     addExit "df | grep $mp > /dev/null 2>&1 && umount -v $mp"
 }

-addExit "rm -Rf $WDIR"
+addExit "rm -rf $WDIR"

-eval $(/lib/udev/vol_id $CD)
+eval "$(/lib/udev/vol_id $CD)"
 LABEL=$ID_FS_LABEL

 # mount the CD image
@@ -139,8 +151,10 @@ 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
+    # FIXME: make the script fail -- or maybe try to
+    # find a usable sed delimiter if $PARAMS contains a slash
     echo ">>> Appending boot parameters"
-    sed -i 's/^  append .*$/& '$PARAMS/ "$WDIR/cd-w/isolinux/isolinux.cfg"
+    sed -i 's/^  append .*$/& '"$PARAMS/" "$WDIR/cd-w/isolinux/isolinux.cfg"
 fi

 echo ">>> Creating ISO image $ISO"
@@ -155,4 +169,3 @@ mkisofs \

 # The trap ... callbacks will unmount everything.
 set +e
-




More information about the ovirt-devel mailing list