Drop Latest change lines, add initial support for Debian/squeeze
[grml-live.git] / remaster / grml-live-remaster
1 #!/bin/sh
2 # Filename:      grml-live-remaster
3 # Purpose:       remaster a grml from the live cd
4 # Authors:       grml-team (grml.org), (c) Michael Schierl <schierlm@gmx.de>, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8 # DISCLAIMER:
9 # this script currently lacks LOTS of error checking code... any help welcome...
10 ################################################################################
11
12 set -e # exit on any error
13
14 VERSION='0.0.2'
15
16 # source core functions {{{
17 . /etc/grml/lsb-functions
18 . /etc/grml/script-functions
19 # }}}
20
21 # make sure we have what we need {{{
22 check4progs mkisofs mksquashfs || exit 1
23 check4root || exit 1
24 # }}}
25
26 if [ x"$1" == x ]; then
27    echo "$0 - version $VERSION"
28    echo ""
29    echo "Usage: $0 destination.iso"
30    echo "  destination.iso should point to a path that is on a hard disk,"
31    echo "  you might want to mount some swap partitions or swap files"
32    echo "  first, because grml-live-remaster will need a lot ot RAM."
33    echo ""
34    echo "Please report bugs and feature requests: http://grml.org/bugs/"
35    exit -1
36 fi
37
38 if [ ! -d /remaster ]; then
39    mkdir -p /remaster/chroot /remaster/tmp /remaster/cdrom
40    mount -t tmpfs tmpfs /remaster/tmp
41    echo "#:# edit the following two lines to change the boot message" \
42            >/remaster/msg
43    echo "#:#" >>/remaster/msg
44    if [ -r /live/image/boot/isolinux/boot.msg ] ; then
45       sed 1,2d /live/image/boot/isolinux/boot.msg >>/remaster/msg
46    else
47       sed 1,2d /live/image/boot.msg >>/remaster/msg
48    fi
49 fi
50
51 SQUASHFS_FILE="$(find /live/image/live -name \*.squashfs | head -1)"
52 if ! grep -q "/remaster/cdrom squashfs" /proc/mounts ;  then
53    mount -t squashfs "$SQUASHFS_FILE" /remaster/cdrom -o ro,loop
54 fi
55
56 if ! grep -q "aufs /remaster/chroot" /proc/mounts ; then
57    mount -t aufs aufs /remaster/chroot -o br:/remaster/tmp=rw:/remaster/cdrom=rr
58 fi
59
60 for i in dev proc root sys tmp; do
61     mount --bind /$i /remaster/chroot/$i
62 done
63
64 echo "Now edit the contents of the live CD in this chrooted shell:"
65 chroot /remaster/chroot
66
67 for i in dev proc root sys tmp; do
68         umount /remaster/chroot/$i
69 done
70
71 $EDITOR /remaster/msg
72
73 [ -d /remaster/iso ] || mkdir /remaster/iso
74
75 for i in /live/image/*; do
76     if [ ! $i == /live/image/live ]; then
77        cp -R $i /remaster/iso
78     fi
79 done
80
81 if [ -r /remaster/iso/boot/isolinux/boot.msg ] ; then
82    rm /remaster/iso/boot/isolinux/boot.msg
83 fi
84
85 # make sure we support usb sticks as well:
86 if [ -d /live/image/boot/isolinux ] ; then
87    BOOTSTUFF=/live/image/boot/isolinux
88 else
89    BOOTSTUFF=/live/image
90 fi
91
92 [ -d /remaster/iso/boot/isolinux ] || mkdir -p /remaster/iso/boot/isolinux
93
94 sed 3,4d "${BOOTSTUFF}"/boot.msg \
95         >/remaster/iso/boot/isolinux/boot.msg
96 sed 1,2d /remaster/msg >>/remaster/iso/boot/isolinux/boot.msg
97
98 mkdir /remaster/iso/live
99 mksquashfs /remaster/chroot /remaster/iso/live/"$(basename $SQUASHFS_FILE)"
100 umount /remaster/chroot /remaster/cdrom
101
102 if [ -f /remaster/iso/boot/isolinux/isolinux.bin ] ; then
103    ISOLINUX=boot/isolinux/isolinux.bin
104    ISOLINUX_BOOTCAT=boot/isolinux/boot.cat
105 else
106    ISOLINUX=isolinux.bin
107    ISOLINUX_BOOTCAT=boot.cat
108 fi
109
110 mkisofs -b $ISOLINUX -no-emul-boot -c $ISOLINUX_BOOTCAT \
111         -boot-info-table -l -r -J -o "$1" /remaster/iso
112 rm -R /remaster/iso
113
114 echo ""
115 echo "ISO generation complete:"
116 ls --color -l "$1"
117 echo "If you want to customize your ISO, just call grml-live-remaster again."
118
119 ## END OF FILE #################################################################
120 # vim: ai filetype=sh expandtab