SW: remove darcs from GRML_FULL (too large).
[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),
5 #                (c) Michael Schierl <schierlm@gmx.de>,
6 #                (c) Michael Prokop <mika@grml.org>,
7 #                (c) Thorsten Glaser <tg@mirbsd.org>
8 # Bug-Reports:   see http://grml.org/bugs/
9 # License:       This file is licensed under the GPL v2 or any later version.
10 ################################################################################
11 # DISCLAIMER:
12 # this script currently lacks LOTS of error checking code... any help welcome...
13 ################################################################################
14
15 # define function getfilesize before "set -e"
16 if stat --help >/dev/null 2>&1; then
17   getfilesize='stat -c %s'      # GNU stat
18 else
19   getfilesize='stat -f %z'      # BSD stat
20 fi
21
22 set -e # exit on any error
23
24 VERSION='0.0.2'
25 GRML_LIVE_EDITOR=${VISUAL:-${EDITOR:-vi}}
26
27 # source core functions {{{
28 . /etc/grml/lsb-functions
29 . /etc/grml/script-functions
30 # }}}
31
32 # make sure we have what we need {{{
33 check4progs mkisofs stat || exit 1
34
35 # allow overriding via environment:
36 if [ -z "$MKSQUASHFS" ] ; then
37   if which mksquashfs-lzma >/dev/null 2>&1 ; then
38     MKSQUASHFS=mksquashfs-lzma
39   elif which mksquashfs >/dev/null 2>&1 ; then
40     MKSQUASHFS=mksquashfs
41   else
42     echo "Error: neither mksquashfs-lzma nor mksquashfs present. Exiting."
43     exit 1
44   fi
45 fi
46 check4root || exit 1
47 # }}}
48
49 if [ x"$1" == x ]; then
50    echo "$0 - version $VERSION"
51    echo ""
52    echo "Usage: $0 destination.iso"
53    echo "  destination.iso should point to a path that is on a hard disk,"
54    echo "  you might want to mount some swap partitions or swap files"
55    echo "  first, because grml-live-remaster will need a lot ot RAM."
56    echo ""
57    echo "Please report bugs and feature requests: http://grml.org/bugs/"
58    exit 1
59 fi
60
61 if [ ! -d /remaster ]; then
62    mkdir -p /remaster/chroot /remaster/tmp /remaster/cdrom
63    mount -t tmpfs tmpfs /remaster/tmp
64    echo "#:# edit the following two lines to change the boot message" \
65            >/remaster/msg
66    echo "#:#" >>/remaster/msg
67    if [ -r /live/image/boot/isolinux/boot.msg ] ; then
68       sed 1,2d /live/image/boot/isolinux/boot.msg >>/remaster/msg
69    else
70       sed 1,2d /live/image/boot.msg >>/remaster/msg
71    fi
72 fi
73
74 SQUASHFS_FILE="$(find /live/image/live -name \*.squashfs | head -1)"
75 if ! grep -q "/remaster/cdrom squashfs" /proc/mounts ;  then
76    mount -t squashfs "$SQUASHFS_FILE" /remaster/cdrom -o ro,loop
77 fi
78
79 if ! grep -q "aufs /remaster/chroot" /proc/mounts ; then
80    mount -t aufs aufs /remaster/chroot -o br:/remaster/tmp=rw:/remaster/cdrom=rr
81 fi
82
83 for i in dev proc root sys tmp; do
84     mount --bind /$i /remaster/chroot/$i
85 done
86
87 echo "Now edit the contents of the live CD in this chrooted shell:"
88 chroot /remaster/chroot
89
90 for i in dev proc root sys tmp; do
91         umount /remaster/chroot/$i
92 done
93
94 ${GRML_LIVE_EDITOR} /remaster/msg
95
96 [ -d /remaster/iso ] || mkdir /remaster/iso
97
98 for i in /live/image/*; do
99     if [ ! $i == /live/image/live ]; then
100        cp -R $i /remaster/iso
101     fi
102 done
103
104 if [ -r /remaster/iso/boot/isolinux/boot.msg ] ; then
105    rm /remaster/iso/boot/isolinux/boot.msg
106 fi
107
108 # make sure we support usb sticks as well:
109 if [ -d /live/image/boot/isolinux ] ; then
110    BOOTSTUFF=/live/image/boot/isolinux
111 else
112    BOOTSTUFF=/live/image
113 fi
114
115 [ -d /remaster/iso/boot/isolinux ] || mkdir -p /remaster/iso/boot/isolinux
116
117 sed 3,4d "${BOOTSTUFF}"/boot.msg \
118         >/remaster/iso/boot/isolinux/boot.msg
119 sed 1,2d /remaster/msg >>/remaster/iso/boot/isolinux/boot.msg
120
121 mkdir /remaster/iso/live
122 $MKSQUASHFS /remaster/chroot /remaster/iso/live/"$(basename $SQUASHFS_FILE)"
123 umount /remaster/chroot /remaster/cdrom
124
125 if [ -f /remaster/iso/boot/isolinux/isolinux.bin ] ; then
126    ISOLINUX=boot/isolinux/isolinux.bin
127    ISOLINUX_BOOTCAT=boot/isolinux/boot.cat
128 else
129    ISOLINUX=isolinux.bin
130    ISOLINUX_BOOTCAT=boot.cat
131 fi
132
133 mkisofs -b $ISOLINUX -no-emul-boot -c $ISOLINUX_BOOTCAT \
134         -boot-info-table -boot-load-size 4 -no-pad \
135         -l -r -J -o "$1" /remaster/iso
136 # pad for partition table
137 siz=$($getfilesize "$1")
138 cyls=$((siz / 512 / 32 / 16 + 1))       # C=$cyls H=16 S=32 (= 256 KiB units)
139 siz=$((cyls * 16 * 32 * 512))           # size after padding
140 dd if=/dev/zero bs=1 count=1 seek=$((siz - 1)) of="$1" 2>/dev/null
141 rm -R /remaster/iso
142
143 # here is the place where we could apply bootgrub.mksh
144
145 echo ""
146 echo "ISO generation complete:"
147 ls --color -l "$1"
148 echo "If you want to customize your ISO, just call grml-live-remaster again."
149
150 ## END OF FILE #################################################################
151 # vim: ai filetype=sh expandtab