Update of grml_cd stuff, several new files and features
[grml-live.git] / grml-live
1 #!/bin/sh
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: Sat Sep 15 21:36:04 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 VERBOSE=''
25 FORCE=''
26
27 # source main configuration file:
28 . /etc/grml/grml-live.conf
29
30 PN=$(basename $0)
31 TMPFILE=$(mktemp)
32 # }}}
33
34 # clean exit {{{
35 bailout() {
36   rm -f "$TMPFILE"
37   [ -n "$1" ] && EXIT="$1" || EXIT="1"
38   [ -n "$2" ] && echo "$2">&2
39   exit "$EXIT"
40 }
41 trap bailout 1 2 3 15
42 # }}}
43
44 # check for important variables {{{
45 [ -n "$GRML_FAI_CONFIG" ] || GRML_FAI_CONFIG=/etc/grml/fai
46 [ -n "$HOSTNAME" ] || HOSTNAME=grml
47 [ -n "$USERNAME" ] || USERNAME=grml
48 [ -n "$CLASSES" ] || CLASSES="GRML"
49 [ -n "$CHROOT_TARGET" ] || bailout 1 "${PN}: \$CHROOT_TARGET not specified. Please adjust /etc/grml/grml-live.conf. Exiting."
50 # }}}
51
52 # usage information {{{
53 usage()
54 {
55   echo "
56 $PN - build process script for generating a (grml based) Linux Live-ISO
57
58 Usage: $PN [-c <classe[s]>] [-t <target_directory>] [-F] [-h|--help] [additional_arguments_for_fai]
59
60 Usage examples:
61
62     $PN
63     $PN -c GRML -t /dev/shm/grml
64     $PN -c GRML,GRML_X -t /grml/chroot/grml_uncompressed
65     $PN -c GRML
66
67 More details: man grml-live
68               /usr/share/doc/grml-live/grml-live.html
69
70 Please send your bug reports, feedback,.. to the grml-team.
71 http://grml.org/bugs/
72 "
73 }
74 # }}}
75
76 # command line parsing {{{
77
78 while getopts ?c:f:t:Fhv: opt; do
79   case "$opt" in
80     c) CLASSES="$OPTARG" ;;
81     F) FORCE=1 ;;
82     h) usage ; bailout 0 ;;
83     t) CHROOT_TARGET="$OPTARG" ;;
84     v) VERBOSE="-v" ;;
85     ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;;
86   esac
87 done
88 shift $(($OPTIND - 1))  # set ARGV to the first not parsed commandline parameter
89 FAI_ARGS="$*"
90
91 # }}}
92
93 # some misc checks before executing FAI {{{
94 [ -n "$CLASSES" ] || bailout 1 "Error: \$CLASSES unset, please set it in /etc/grml/grml-live.conf or
95 specify it on the command line using the -c|--classes option."
96 [ -n "$CHROOT_TARGET" ] || bailout 1 "Error: \$CHROOT_TARGET unset, please set it in /etc/grml/grml-live.conf or
97 specify it on the command line using the -t|--target option."
98
99 if [ "$EXECUTE" != '1' ] ; then
100    echo "Error: please set EXECUTE=1 in /etc/grml/grml-live.conf to really execute grml-live.">&2
101    echo
102    echo "See 'man grml-live' for more details or execute '$PN --help'">&2
103    echo
104    bailout 1
105 fi
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 "  chroot target:  $CHROOT_TARGET"
115    echo "  build target:   $BUILD_TARGET"
116    echo "  ISO target:     $ISO_TARGET"
117
118    [ -n "$FAI_ARGS" ] && echo "  additional arguments for FAI: $FAI_ARGS"
119    echo
120    echo -n "Is this ok for you? [y/N] "
121    read a
122    if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
123       bailout 1 "Exiting as requested."
124    fi
125    echo
126 fi
127 # }}}
128
129 if [ -n "$GRML_LIVE_SOURCES" ] ; then
130    echo "$GRML_LIVE_SOURCES" > /etc/grml/fai/apt/sources.list
131 fi
132
133 if [ -n "$FAI_DEBOOTSTRAP" ] ; then
134    sed -i "s#^FAI_DEBOOTSTRAP#FAI_DEBOOTSTRAP=$FAI_DEBOOTSTRAP#" /etc/grml/fai/make-fai-nfsroot.conf
135 fi
136
137 # execute FAI {{{
138 if [ -d "$CHROOT_TARGET" ] ; then
139    echo "  [x] $CHROOT_TARGET exists already, skipping the stage 'fai dirnstall'"
140 else
141    mkdir "$CHROOT_TARGET" || bailout 5 "Problem with creating $CHROOT_TARGET for FAI"
142    fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" dirinstall "$CHROOT_TARGET" $FAI_ARGS
143 fi
144 # }}}
145
146 mkdir -p "$BUILD_TARGET" || bailout 6 "Problem with creating $BUILD_TARGET for stage ARCH"
147
148 # x86:
149 if [ "$ARCH" = x86 ] ; then
150    if [ -d "$BUILD_TARGET"/boot/isolinux ] ; then
151       echo "  [x] $BUILD_TARGET/boot/isolinux exists already - skipping stage 'boot/isolinux'"
152       continue
153    else
154       mkdir -p "$BUILD_TARGET"/boot/isolinux
155       mkdir "$BUILD_TARGET"/GRML
156       cp /boot/memtest86+.bin                                       "$BUILD_TARGET"/boot/isolinux/memtest
157       cp "$CHROOT_TARGET"/boot/initrd*                              "$BUILD_TARGET"/boot/isolinux/initrd.gz
158       cp "$CHROOT_TARGET"/boot/vmlinuz*                             "$BUILD_TARGET"/boot/isolinux/linux26
159       cp /usr/lib/syslinux/chain.c32                                "$BUILD_TARGET"/boot/isolinux/
160       cp /usr/lib/syslinux/isolinux.bin                             "$BUILD_TARGET"/boot/isolinux/
161       cp /usr/lib/syslinux/memdisk                                  "$BUILD_TARGET"/boot/isolinux/
162       cp /usr/lib/syslinux/menu.c32                                 "$BUILD_TARGET"/boot/isolinux/
163       cp /usr/share/grml-live/x86_files/boot/isolinux/allinone.img  "$BUILD_TARGET"/boot/isolinux/
164       cp /usr/share/grml-live/x86_files/boot/isolinux/balder10.imz  "$BUILD_TARGET"/boot/isolinux/
165       cp /usr/share/grml-live/x86_files/boot/isolinux/boot-beep.msg "$BUILD_TARGET"/boot/isolinux/
166       cp /usr/share/grml-live/x86_files/boot/isolinux/boot.msg      "$BUILD_TARGET"/boot/isolinux/
167       cp /usr/share/grml-live/x86_files/boot/isolinux/f*            "$BUILD_TARGET"/boot/isolinux/
168       cp /usr/share/grml-live/x86_files/boot/isolinux/isolinux.cfg  "$BUILD_TARGET"/boot/isolinux/
169       cp /usr/share/grml-live/x86_files/boot/isolinux/logo.16       "$BUILD_TARGET"/boot/isolinux/
170       cp /usr/share/grml-live/x86_files/boot/isolinux/syslinux.cfg  "$BUILD_TARGET"/boot/isolinux/
171       # minirt26.gz
172       # boot.cat
173       if [ -n "$WINDOWS_BINARIES" ] ; then
174          if [ -d "$BUILD_TARGET"/windows ] ; then
175             echo "  [x] $BUILD_TARGET/windows exists already - skipping stage WINDOWS_BINARIES"
176             return 0
177          else
178             mkdir "$BUILD_TARGET"/windows
179             ( cd "$BUILD_TARGET"/windows
180               for file in pageant plink pscp psftp putty puttygen ; do
181                   wget ${WINDOWS_BINARIES}/${file}.exe
182               done )
183          fi
184       fi
185    fi
186 # amd64:
187 elif [ "$ARCH" = amd64 ] ; then
188     echo 'Warning: gebi, it is your turn. :)'>2
189 # ppc:
190 elif [ "$ARCH" = ppc ] ; then
191     echo 'Warning: formorer, it is your turn. :)'>2
192 # unsuported:
193 else
194    echo 'Warning: Unsupported ARCH, sorry. Want to support it? Contribute!'>&2
195 fi
196
197 if [ -d "$BUILD_TARGET"/live ] ; then
198    echo "  [x] $BUILD_TARGET/live exists already, skipping stage 'squashfs'"
199 else
200    mkdir "$BUILD_TARGET"/live
201    mksquashfs $CHROOT_TARGET/* $BUILD_TARGET/live/grml.squashfs -noappend
202 fi
203
204 if [ -d "$ISO_TARGET" ] ; then
205    echo "  [x] $ISO_TARGET exists already, skipping the stage 'iso build'"
206 else
207    mkdir -p "$ISO_TARGET" || bailout 6 "Problem with creating $ISO_TARGET for stage 'iso build'"
208    ( cd "$BUILD_TARGET" &&
209      mkisofs -V "Debian/etch grml" -publisher 'Michael Prokop <mika@grml.org>' \
210              -l -r -J -no-emul-boot -boot-load-size 4 -boot-info-table    \
211              -c boot/isolinux/boot.cat -b boot/isolinux/isolinux.bin      \
212              -o "$ISO_TARGET"/grml_0.0-1.iso .
213    )
214
215 fi
216
217 echo "  [*] Sucessfully finished execution of $PN"
218 bailout 0
219
220 ## END OF FILE #################################################################
221 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=2