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