Makes $dist-updates-newkey only available on Fedora 9.
[ovirt-node-image.git] / edit-livecd
blob020003408734c9d157e769bc0783196b64293ea8
1 #!/bin/bash
3 # Edit a livecd to insert files
4 # Copyright 2008 Red Hat, Inc.
5 # Written by Perry Myers <pmyers@redhat.com>
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; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Library General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #!/bin/bash
21 PATH=$PATH:/sbin:/usr/sbin
23 ME=$(basename "$0")
24 warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
25 try_h() { printf "Try \`$ME -h' for more information.\n" >&2; }
26 die() { warn "$@"; try_h; exit 1; }
28 usage() {
29 case $# in 1) warn "$1"; try_h; exit 1;; esac
30 cat <<EOF
31 Usage: $ME livecd.iso program
32 livecd.iso - LiveCD ISO to edit
33 program - Arbitrary program/script that is run inside of the livecd root
34 filesystem. This script is not run in a chroot environment so
35 it can access the host filesystem. The program should be executable
36 If program is omitted the script will pause and allow the user in
37 another terminal to edit the filesystem manually. After enter is
38 pushed the script will re-package up the ISO.
40 Example Script:
41 #!/bin/sh
42 touch etc/sysconfig/foo
44 This will create a file /etc/sysconfig/foo in the livecd filesystem.
45 EOF
48 # exit after any error:
49 set -e
51 test $# -lt 1 && { usage; exit 1; }
53 # first, check to see we are root
54 if [ $( id -u ) -ne 0 ]; then
55 die "Must run as root"
58 CD=$1
59 PROG=$2
61 which mkisofs mksquashfs sed > /dev/null 2>&1
63 WDIR=`mktemp -d $PWD/livecd.XXXXXXXXXX`
64 ISO="${CD##*/}"
65 ISO="${ISO%.iso}-custom.iso"
67 function addExit() {
68 EXIT="$@ ; $EXIT"
69 trap "$EXIT" EXIT HUP TERM INT QUIT
72 function mnt() {
73 local margs="$1" ; shift
74 local mp="$WDIR/$1"
75 for D in "$@" ; do
76 mkdir -v -p "$WDIR/$D"
77 done
78 mount -v $margs "$mp"
79 addExit "df | grep $mp > /dev/null 2>&1 && umount -v $mp"
82 addExit "rm -Rf $WDIR"
84 LABEL=$(isoinfo -d -i $CD | awk -F ": " '/Volume id:/ {print $2}')
86 # mount the CD image
87 mnt "-t auto $CD -o loop,ro" cd
89 # mount compressed filesystem
90 mnt "-t squashfs $WDIR/cd/LiveOS/squashfs.img -o ro,loop" sq
92 # create writable copy of the new filesystem for the CD
93 cp -a $WDIR/cd $WDIR/cd-w
95 # create writable copy of the filesystem for the new compressed squashfs filesystem
96 cp -a $WDIR/sq $WDIR/sq-w
98 # mount ext3 filesystem
99 mnt "-t auto $WDIR/sq-w/LiveOS/ext3fs.img -o rw,loop" ex
101 echo ">>> Updating CD content"
102 if [ -n "$PROG" ]; then
103 cp -av $PROG $WDIR/ex
104 pushd $WDIR/ex
105 set +e
106 ./$(basename $PROG)
107 set -e
108 popd
109 rm -f $WDIR/ex/$PROG
110 else
111 echo "***"
112 echo "*** Pausing to allow manual changes. Press any key to continue."
113 echo "***"
114 read
116 echo ">>> Unmounting ext3fs"
117 umount $WDIR/ex
119 echo ">>> Compressing filesystem"
120 mksquashfs $WDIR/sq-w/ $WDIR/cd-w/LiveOS/squashfs.img -noappend
122 echo ">>> Recomputing MD5 sums"
123 ( cd $WDIR/cd-w && find . -type f -not -name md5sum.txt -not -path '*/isolinux/*' -print0 | xargs -0 -- md5sum > md5sum.txt )
125 echo ">>> Creating ISO image $ISO"
126 mkisofs \
127 -V "$LABEL" \
128 -r -cache-inodes -J -l \
129 -b isolinux/isolinux.bin \
130 -c isolinux/boot.cat \
131 -no-emul-boot -boot-load-size 4 -boot-info-table \
132 -o "$ISO" \
133 $WDIR/cd-w
135 # The trap ... callbacks will unmount everything.
136 set +e