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