Depend on fai >=3.2, implement the suite handling for conffiles, update docs, improve...
[grml-live.git] / grml-live
1 #!/bin/bash
2 # Filename:      grml-live
3 # Purpose:       build process script for generating a (grml based) Linux Live-ISO
4 # Authors:       grml-team (grml.org), (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 # Latest change: Tue Sep 18 19:29:33 CEST 2007 [mika]
8 ################################################################################
9
10 # read configuration files, set some misc variables {{{
11
12 export LANG=C
13 export LC_ALL=C
14
15 # exit on any error:
16 set -e
17
18 # we need root permissions for the build-process:
19 if [ "$(id -u 2>/dev/null)" != 0 ] ; then
20    echo "Error: please run this script with uid 0 (root)." >&2
21    exit 1
22 fi
23
24 # make sure they are not set by default
25 VERBOSE=''
26 FORCE=''
27
28 # source main configuration file:
29 LIVE_CONF=/etc/grml/grml-live.conf
30 . $LIVE_CONF
31
32 PN=$(basename $0)
33 # TMPFILE=$(mktemp)
34 # }}}
35
36 # clean exit {{{
37 bailout() {
38   # rm -f "$TMPFILE"
39   [ -n "$1" ] && EXIT="$1" || EXIT="1"
40   [ -n "$2" ] && echo "$2">&2
41   exit "$EXIT"
42 }
43 trap bailout 1 2 3 15
44 # }}}
45
46 # check for important variables {{{
47 [ -n "$GRML_FAI_CONFIG" ] || GRML_FAI_CONFIG=/etc/grml/fai
48 [ -n "$HOSTNAME" ] || HOSTNAME=grml
49 [ -n "$USERNAME" ] || USERNAME=grml
50 [ -n "$CLASSES" ]  || CLASSES="GRML,I386"
51 [ -n "$TARGET" ] || bailout 1 "${PN}: \$TARGET not specified. Please adjust $LIVE_CONF. Exiting."
52 # }}}
53
54 # usage information {{{
55 usage()
56 {
57   echo "
58 $PN - build process script for generating a (grml based) Linux Live-ISO
59
60 Usage: $PN [-c <classe[s]>] [-t <target_directory>] [-s <suite> [-Fvh]
61
62 Usage examples:
63
64     $PN
65     $PN -c GRMLBASE,GRML_X,I386 -t /grml/
66     $PN -c GRMLBASE,I386 -t /dev/shm/grml
67     $PN -c GRMLBASE,GRML_SMALL,I386
68     $PN -s sid -c GRMLBASE,I386
69
70 More details: man grml-live
71               /usr/share/doc/grml-live/grml-live.html
72
73 Please send your bug reports, feedback,.. to the grml-team.
74 http://grml.org/bugs/
75 "
76 }
77 # }}}
78
79 # command line parsing {{{
80
81 while getopts "c:s:t:Fhv" opt; do
82   case "$opt" in
83     c) CLASSES="$OPTARG" ;;
84     # f) FLAVOUR="$OPTARG" ;; # TODO
85     F) FORCE=1 ;;
86     h) usage ; bailout 0 ;;
87     s) SUITE="$OPTARG" ;;
88     t) TARGET="$OPTARG"
89        CHROOT_TARGET="$TARGET/grml_chroot"
90        BUILD_TARGET="$TARGET/grml_cd"
91        ISO_TARGET="$TARGET/grml_isos"
92        ;;
93     v) VERBOSE="-v" ;;
94     ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;;
95   esac
96 done
97 shift $(($OPTIND - 1))  # set ARGV to the first not parsed commandline parameter
98
99 # }}}
100
101 # some misc checks before executing FAI {{{
102 [ -n "$CLASSES" ] || bailout 1 "Error: \$CLASSES unset, please set it in $LIVE_CONF or
103 specify it on the command line using the -c|--classes option."
104 [ -n "$TARGET" ] || bailout 1 "Error: \$TARGET unset, please set it in $LIVE_CONF or
105 specify it on the command line using the -t|--target option."
106 # }}}
107
108 # ask user whether the setup is ok {{{
109 if [ -z "$FORCE" ] ; then
110    echo
111    echo "$PN - check your configuration (or invoke using -F to force execution without prompting):"
112    echo
113    echo "  FAI classes:       $CLASSES"
114    echo "  main directory:    $TARGET"
115    [ -n "$CHROOT_TARGET" ] && echo "  chroot target:     $CHROOT_TARGET"
116    [ -n "$BUILD_TARGET" ]  && echo "  build target:      $BUILD_TARGET"
117    [ -n "$ISO_TARGET" ]    && echo "  ISO target:        $ISO_TARGET"
118    [ -n "$SUITE" ]         && echo "  Debian suite:      $SUITE"
119    [ -n "$FAI_ARGS" ]      && echo "  additional arguments for FAI: $FAI_ARGS"
120    [ -n "$VERBOSE" ]       && echo "  Using VERBOSE mode."
121    echo
122    echo -n "Is this ok for you? [y/N] "
123    read a
124    if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
125       bailout 1 "Exiting as requested."
126    fi
127    echo
128 fi
129 # }}}
130
131 # on-the-fly configuration {{{
132 if [ -n "$GRML_LIVE_SOURCES" ] ; then
133    echo "$GRML_LIVE_SOURCES" > /etc/grml/fai/apt/sources.list
134 fi
135
136 if [ -n "$FAI_DEBOOTSTRAP" ] ; then
137    sed -i "s#^FAI_DEBOOTSTRAP=.*#FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"#" /etc/grml/fai/make-fai-nfsroot.conf
138 fi
139
140 # does this suck? YES!
141 if [ -n "$SUITE" ] ; then
142    sed -ie "s/SUITE=.*/SUITE=\"$SUITE\"/" $LIVE_CONF
143
144    DIST="\|\ etch\ \|\ stable\ \|\ lenny\ \|\ testing\ \|\ sid\ \|\ unstable\ "
145    sed -ie "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" $LIVE_CONF
146    sed -ie "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" /etc/grml/fai/apt/sources.list
147
148    DIST='\"etch\|=\"stable=\"lenny=\"testing=\"sid=\"unstable'
149    sed -ie "s#FAI_DEBOOTSTRAP=$DIST#FAI_DEBOOTSTRAP=\"$SUITE#" $LIVE_CONF
150    sed -ie "s#FAI_DEBOOTSTRAP=$DIST#FAI_DEBOOTSTRAP=\"$SUITE#" /etc/grml/fai/make-fai-nfsroot.conf
151 fi
152 # }}}
153
154 # CHROOT_TARGET - execute FAI {{{
155 [ -n "$CHROOT_TARGET" ] || CHROOT_TARGET="$TARGET/grml_chroot"
156
157 if [ -d "$CHROOT_TARGET" ] ; then
158    echo "  [x] $CHROOT_TARGET exists already, skipping the stage 'fai dirnstall'"
159 else
160    mkdir -p "$CHROOT_TARGET" || bailout 5 "Problem with creating $CHROOT_TARGET for FAI"
161    fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" dirinstall "$CHROOT_TARGET" $FAI_ARGS
162    umount $CHROOT_TARGET/proc 2>/dev/null || /bin/true
163    umount $CHROOT_TARGET/sys  2>/dev/null || /bin/true
164    # notice: 'fai dirinstall' does not seem to exit appropriate ->
165    # we need better error handling
166    if [ -r "$CHROOT_TARGET"/etc/grml_cd ] ; then
167       echo "  [*] Finished execution of stage 'fai dirinstall'"
168    else
169       echo "  [!] There was an error during execution of stage 'fai dirinstall'"
170       exit 1
171    fi
172 fi
173 # }}}
174
175 # BUILD_TARGET - execute arch specific stuff and squashfs {{{
176 [ -n "$BUILD_TARGET" ] || BUILD_TARGET="$TARGET/grml_cd"
177 mkdir -p "$BUILD_TARGET" || bailout 6 "Problem with creating $BUILD_TARGET for stage ARCH"
178
179 # i386:
180 [ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)"
181 if [ "$ARCH" = i386 ] ; then
182    if [ -d "$BUILD_TARGET"/boot/isolinux ] ; then
183       echo "  [x] $BUILD_TARGET/boot/isolinux exists already - skipping stage 'boot/isolinux'"
184       continue
185    else
186       # booting stuff:
187       mkdir -p "$BUILD_TARGET"/boot/isolinux
188       mkdir "$BUILD_TARGET"/GRML
189       cp /boot/memtest86+.bin                                        "$BUILD_TARGET"/boot/isolinux/memtest
190       cp "$CHROOT_TARGET"/boot/initrd*                               "$BUILD_TARGET"/boot/isolinux/initrd.gz
191       cp "$CHROOT_TARGET"/boot/vmlinuz*                              "$BUILD_TARGET"/boot/isolinux/linux26
192       cp /usr/lib/syslinux/chain.c32                                 "$BUILD_TARGET"/boot/isolinux/
193       cp /usr/lib/syslinux/isolinux.bin                              "$BUILD_TARGET"/boot/isolinux/
194       cp /usr/lib/syslinux/memdisk                                   "$BUILD_TARGET"/boot/isolinux/
195       cp /usr/lib/syslinux/menu.c32                                  "$BUILD_TARGET"/boot/isolinux/
196       cp /usr/share/grml-live/i386_files/boot/isolinux/allinone.img  "$BUILD_TARGET"/boot/isolinux/
197       cp /usr/share/grml-live/i386_files/boot/isolinux/balder10.imz  "$BUILD_TARGET"/boot/isolinux/
198       cp /usr/share/grml-live/i386_files/boot/isolinux/boot-beep.msg "$BUILD_TARGET"/boot/isolinux/
199       cp /usr/share/grml-live/i386_files/boot/isolinux/boot.msg      "$BUILD_TARGET"/boot/isolinux/
200       cp /usr/share/grml-live/i386_files/boot/isolinux/f*            "$BUILD_TARGET"/boot/isolinux/
201       cp /usr/share/grml-live/i386_files/boot/isolinux/isolinux.cfg  "$BUILD_TARGET"/boot/isolinux/
202       cp /usr/share/grml-live/i386_files/boot/isolinux/logo.16       "$BUILD_TARGET"/boot/isolinux/
203       cp /usr/share/grml-live/i386_files/boot/isolinux/syslinux.cfg  "$BUILD_TARGET"/boot/isolinux/
204       # autostart for Windows:
205       cp /usr/share/grml-live/windows/autostart/autorun.bat          "$BUILD_TARGET"/
206       cp /usr/share/grml-live/windows/autostart/autorun.inf          "$BUILD_TARGET"/
207       cp /usr/share/grml-live/windows/autostart/autorun.pif          "$BUILD_TARGET"/
208       cp /usr/share/grml-live/windows/autostart/cdrom.ico            "$BUILD_TARGET"/
209       # windows-binaries:
210       if [ -n "$WINDOWS_BINARIES" ] ; then
211          if [ -d "$BUILD_TARGET"/windows ] ; then
212             echo "  [x] $BUILD_TARGET/windows exists already - skipping stage 'WINDOWS_BINARIES'"
213             return 0
214          else
215             mkdir "$BUILD_TARGET"/windows
216             ( cd "$BUILD_TARGET"/windows
217               for file in pageant plink pscp psftp putty puttygen ; do
218                   wget ${WINDOWS_BINARIES}/${file}.exe
219               done )
220          fi
221       echo "  [*] Finished execution of stage 'WINDOWS_BINARIES'"
222       fi
223    echo "  [*] Finished execution of stage 'boot/isolinux'"
224    fi
225 # amd64:
226 elif [ "$ARCH" = amd64 ] ; then
227     echo 'Warning: gebi, it is your turn. :)'>&2
228 # ppc:
229 elif [ "$ARCH" = powerpc ] ; then
230     echo 'Warning: formorer, it is your turn. :)'>&2
231 # unsuported:
232 else
233    echo 'Warning: Unsupported ARCH, sorry. Want to support it? Contribute!'>&2
234 fi
235
236 if [ -d "$BUILD_TARGET"/live ] ; then
237    echo "  [x] $BUILD_TARGET/live exists already, skipping stage 'squashfs'"
238 else
239    mkdir "$BUILD_TARGET"/live
240    mksquashfs $CHROOT_TARGET/* $BUILD_TARGET/live/grml.squashfs -noappend
241 fi
242 echo "  [*] Finished execution of stage 'squashfs'"
243 # }}}
244
245 # ISO_TARGET - mkisofs {{{
246 [ -n "$ISO_TARGET" ] || ISO_TARGET="$TARGET/grml_isos"
247 if [ -d "$ISO_TARGET" ] ; then
248    echo "  [x] $ISO_TARGET exists already, skipping the stage 'iso build'"
249 else
250    mkdir -p "$ISO_TARGET" || bailout 6 "Problem with creating $ISO_TARGET for stage 'iso build'"
251    ( cd "$BUILD_TARGET" &&
252      mkisofs -V "Debian/etch grml" -publisher 'Michael Prokop <mika@grml.org>' \
253              -l -r -J -no-emul-boot -boot-load-size 4 -boot-info-table    \
254              -c boot/isolinux/boot.cat -b boot/isolinux/isolinux.bin      \
255              -o "$ISO_TARGET"/grml_0.0-1.iso .
256    )
257    echo "  [*] Finished execution of stage 'iso build'"
258 fi
259 # }}}
260
261 # finalize {{{
262 echo "  [*] Sucessfully finished execution of $PN"
263 bailout 0
264 # }}}
265
266 ## END OF FILE #################################################################
267 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3