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: Thu Oct 18 00:42:13 CEST 2007 [mika]
8 ################################################################################
10 # read configuration files, set some misc variables {{{
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
24 if [ -r /var/run/fai/FAI_INSTALLATION_IN_PROGRESS ] ; then
25 echo "/usr/sbin/fai already running or was aborted before.">&2
26 echo "You may remove /var/run/fai/FAI_INSTALLATION_IN_PROGRESS and try again.">&2
30 # make sure they are not set by default
34 if [ -r /etc/grml/lsb-functions ] ; then
35 . /etc/grml/lsb-functions
37 einfo() { echo " [*] $*" ;}
38 eerror() { echo " [!] $*">&2 ;}
39 ewarn() { echo " [x] $*" ;}
43 # source main configuration file:
44 LIVE_CONF=/etc/grml/grml-live.conf
52 [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
53 [ -n "$1" ] && EXIT="$1" || EXIT="1"
54 [ -n "$2" ] && eerror "$2">&2
60 # check for important variables {{{
61 [ -n "$GRML_FAI_CONFIG" ] || GRML_FAI_CONFIG=/etc/grml/fai
62 [ -n "$HOSTNAME" ] || HOSTNAME=grml
63 [ -n "$USERNAME" ] || USERNAME=grml
64 [ -n "$CLASSES" ] || CLASSES="GRML,I386"
65 [ -n "$BOOT_METHOD" ] || BOOT_METHOD='isolinux'
66 [ -n "$OUTPUT" ] || bailout 1 "${PN}: \$OUTPUT not specified. Please adjust $LIVE_CONF. Exiting."
68 [ -n "$VERSION" ] || VERSION="0.0.1"
69 [ -n "$RELEASENAME" ] || RELEASENAME="grml-live rocks"
70 [ -n "$GRML_NAME" ] || GRML_NAME='grml'
72 if mkdir -p /var/log/fai/dirinstall/${HOSTNAME} ; then
73 LOGFILE=/var/log/fai/dirinstall/${HOSTNAME}/grml-live.log
75 LOGFILE="$LOGDIR/grml-live.log"
78 NFSROOT_CONF=/etc/grml/fai/make-fai-nfsroot.conf
82 # some important functions {{{
85 # usage: log "string to log"
86 log() { echo "$*" >> $LOGFILE ; }
88 # cut string at character number int = $1
89 # usage: cut_string 5 "1234567890" will output "12345"
91 [ -n "$2" ] || return 1
92 echo "$2" | head -c "$1"; echo -ne "\n"
95 # prepend int = $1 spaces before string = $2
96 # usage: extend_string_begin 5 "123" will output " 123"
97 extend_string_begin() {
98 [ -n "$2" ] || return 1
99 local COUNT="$(echo $2 | wc -c)"
100 local FILL="$(expr $COUNT - $1)"
101 while [ "$FILL" -gt 1 ] ; do
103 local FILL=$(expr $FILL - 1)
105 while [ "$FILL" -lt 1 ] ; do
107 local FILL=$(expr $FILL + 1)
109 echo "$2" | head -c "$1"; echo -ne "\n"
112 # append int = $1 spaces to string = $2
113 # usage: extend_string_begin 5 "123" will output "123 "
114 extend_string_end() {
115 [ -n "$2" ] || return 1
116 echo -n "$2" | head -c "$1"
117 local COUNT="$(echo $2 | wc -c)"
118 local FILL="$(expr $COUNT - $1)"
119 while [ "$FILL" -gt 1 ] ; do
121 local FILL=$(expr $FILL - 1)
123 while [ "$FILL" -lt 1 ] ; do
125 local FILL=$(expr $FILL + 1)
131 # usage information {{{
135 $PN - build process script for generating a (grml based) Linux Live-ISO
137 Usage: $PN [-a <architecture>] [-c <classe[s]>] [-g <grml_name>] \\
138 [-i <iso_name> ] [-o <output_directory>] [-s <suite>] \\
139 [-t <template_directory>] [-s <suite>] \\
140 [-v <version_number>] [-FVh]
145 $PN -c GRMLBASE,GRML_SMALL,I386 -o /grml/
146 $PN -c GRMLBASE,GRML_MEDIUM,I386 -o /dev/shm/grml
147 $PN -c GRMLBASE,GRML_SMALL,I386 -g grml-small -v 1.0
148 $PN -c GRMLBASE,GRML_FULL,I386 -i grml_0.0-1.iso -v 0.0-1
149 $PN -c GRMLBASE,GRML_FULL,I386 -s sid -V -r 'grml-live rocks'
151 More details: man grml-live
152 /usr/share/doc/grml-live/grml-live.html
154 Please send your bug reports, feedback,.. to the grml-team.
155 http://grml.org/bugs/
160 # command line parsing {{{
162 while getopts "a:c:g:i:o:r:s:t:v:FhV" opt; do
165 c) CLASSES="$OPTARG" ;;
166 g) GRML_NAME="$OPTARG" ;;
167 i) ISO_NAME="$OPTARG" ;;
169 CHROOT_OUTPUT="$OUTPUT/grml_chroot"
170 BUILD_OUTPUT="$OUTPUT/grml_cd"
171 ISO_OUTPUT="$OUTPUT/grml_isos"
173 r) RELEASENAME="$OPTARG" ;;
174 s) SUITE="$OPTARG" ;;
175 t) TEMPLATE_DIRECTORY="$OPTARG";;
176 v) VERSION="$OPTARG" ;;
178 h) usage ; bailout 0 ;;
180 ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;;
183 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
185 echo "Executing: $(basename $0) $*" >> $LOGFILE
188 # some misc checks before executing FAI {{{
189 [ -n "$CLASSES" ] || bailout 1 "Error: \$CLASSES unset, please set it in $LIVE_CONF or
190 specify it on the command line using the -c option."
191 [ -n "$OUTPUT" ] || bailout 1 "Error: \$OUTPUT unset, please set it in $LIVE_CONF or
192 specify it on the command line using the -o option."
195 # ask user whether the setup is ok {{{
196 if [ -z "$FORCE" ] ; then
198 echo "${PN}: check your configuration (or use -F to force execution without prompting):"
200 echo " FAI classes: $CLASSES"
201 echo " main directory: $OUTPUT"
202 [ -n "$CHROOT_OUTPUT" ] && echo " chroot target: $CHROOT_OUTPUT"
203 [ -n "$BUILD_OUTPUT" ] && echo " build target: $BUILD_OUTPUT"
204 [ -n "$ISO_OUTPUT" ] && echo " ISO target: $ISO_OUTPUT"
205 [ -n "$GRML_NAME" ] && echo " grml name: $GRML_NAME"
206 [ -n "$RELEASENAME" ] && echo " release name: $RELEASENAME"
207 [ -n "$VERSION" ] && echo " grml version: $VERSION"
208 [ -n "$SUITE" ] && echo " Debian suite: $SUITE"
209 [ -n "$ARCH" ] && echo " Architecture: $ARCH"
210 [ -n "$BOOT_METHOD" ] && echo " Boot method: $BOOT_METHOD"
211 [ -n "$TEMPLATE_DIRECTORY" ] && echo " Template files: $TEMPLATE_DIRECTORY"
212 [ -n "$FAI_ARGS" ] && echo " additional arguments for FAI: $FAI_ARGS"
213 [ -n "$VERBOSE" ] && echo " Using VERBOSE mode."
215 echo -n "Is this ok for you? [y/N] "
217 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
218 bailout 1 "Exiting as requested."
222 start_seconds=$(cut -d . -f 1 /proc/uptime)
223 log "------------------------------------------------------------------------------"
224 log "Starting grml-live run [$(date)]"
228 # on-the-fly configuration {{{
229 if [ -n "$MIRROR_DIRECTORY" ] ; then
230 if ! [ -d "$MIRROR_DIRECTORY/debian" ] ; then
231 log "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting. [$(date)]"
232 eerror "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting."
235 echo "$MIRROR_SOURCES" > /etc/grml/fai/apt/sources.list
236 if [ -n "$GRML_LIVE_SOURCES" ] ; then
237 echo "$GRML_LIVE_SOURCES" >> /etc/grml/fai/apt/sources.list
239 elif [ -n "$GRML_LIVE_SOURCES" ] ; then
240 echo "$GRML_LIVE_SOURCES" > /etc/grml/fai/apt/sources.list
243 if [ -n "$FAI_DEBOOTSTRAP" ] ; then
244 sed -i "s#^FAI_DEBOOTSTRAP=.*#FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"#" $NFSROOT_CONF
247 # does this suck? YES!
248 if [ -n "$SUITE" ] ; then
249 sed -i "s/SUITE=.*/SUITE=\"$SUITE\"/" $LIVE_CONF
251 DIST="\|\ etch\ \|\ stable\ \|\ lenny\ \|\ testing\ \|\ sid\ \|\ unstable\ "
252 sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" $LIVE_CONF
253 sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" /etc/grml/fai/apt/sources.list
255 sed -i "s|FAI_DEBOOTSTRAP=\"[a-z]* |FAI_DEBOOTSTRAP=\"$SUITE |" $LIVE_CONF
256 sed -i "s|FAI_DEBOOTSTRAP=\"[a-z]* |FAI_DEBOOTSTRAP=\"$SUITE |" $NFSROOT_CONF
260 [ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)"
261 if grep -q -- 'FAI_DEBOOTSTRAP_OPTS.*--arch' $NFSROOT_CONF ; then
262 sed -i "s/--arch [a-z0-9]* /--arch $ARCH /" $NFSROOT_CONF
264 sed -i "s|FAI_DEBOOTSTRAP_OPTS=\"\(.*\)|FAI_DEBOOTSTRAP_OPTS=\"--arch $ARCH \1|" $NFSROOT_CONF
268 # CHROOT_OUTPUT - execute FAI {{{
269 [ -n "$CHROOT_OUTPUT" ] || CHROOT_OUTPUT="$OUTPUT/grml_chroot"
271 if [ -d "$CHROOT_OUTPUT/bin" ] ; then
272 log "$CHROOT_OUTPUT exists already, skipping stage 'fai dirinstall'"
273 ewarn "$CHROOT_OUTPUT exists already, skipping stage 'fai dirinstall'" ; eend 0
275 mkdir -p "$CHROOT_OUTPUT" || bailout 5 "Problem with creating $CHROOT_OUTPUT for FAI"
276 if [ -n "${MIRROR_DIRECTORY}" ] ; then
277 mkdir -p "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
278 mount --bind "${MIRROR_DIRECTORY}" "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
280 fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" -u "$HOSTNAME" dirinstall "$CHROOT_OUTPUT" $FAI_ARGS | tee -a $LOGFILE
281 umount $CHROOT_OUTPUT/proc 2>/dev/null || /bin/true
282 umount $CHROOT_OUTPUT/sys 2>/dev/null || /bin/true
283 [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
285 # notice: 'fai dirinstall' does not seem to exit appropriate, so:
287 if [ -r "/var/log/fai/dirinstall/$HOSTNAME/software.log" ] ; then
288 # 1 errors during executing of commands
289 grep 'dpkg: error processing' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=1
290 grep 'E: Method http has died unexpectedly!' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=2
291 grep 'ERROR: chroot' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=3
294 if [ -r "/var/log/fai/dirinstall/$HOSTNAME/shell.log" ] ; then
295 grep 'FAILED with exit code' /var/log/fai/dirinstall/$HOSTNAME/shell.log >> $LOGFILE && ERROR=2
298 if [ -n "$ERROR" ] ; then
299 log "There was an error [${ERROR}] during execution of stage 'fai dirinstall' [$(date)]"
300 eerror "There was an error during execution of stage 'fai dirinstall'"
301 echo " Check out /var/log/fai/dirinstall/$HOSTNAME/ for details. [exit ${ERROR}]"
305 log "Finished execution of stage 'fai dirinstall' [$(date)]"
306 einfo "Finished execution of stage 'fai dirinstall'"
311 # BUILD_OUTPUT - execute arch specific stuff and squashfs {{{
312 [ -n "$BUILD_OUTPUT" ] || BUILD_OUTPUT="$OUTPUT/grml_cd"
313 mkdir -p "$BUILD_OUTPUT" || bailout 6 "Problem with creating $BUILD_OUTPUT for stage ARCH"
316 if [ "$ARCH" = i386 ] || [ "$ARCH" = amd64 ] ; then
317 if [ -d "$BUILD_OUTPUT"/boot ] ; then
318 log "$BUILD_OUTPUT/boot exists already, skipping stage 'boot'"
319 ewarn "$BUILD_OUTPUT/boot exists already, skipping stage 'boot'" ; eend 0
322 mkdir -p "$BUILD_OUTPUT"/boot/isolinux
323 cp /boot/memtest86+.bin "$BUILD_OUTPUT"/boot/isolinux/memtest
325 # if we don't have an initrd we a) can't boot and b) there was an error
326 # during build, so check for the file:
327 if [ -f "$CHROOT_OUTPUT"/boot/initrd* ] ; then
328 cp "$CHROOT_OUTPUT"/boot/initrd* "$BUILD_OUTPUT"/boot/isolinux/initrd.gz
330 log "No initrd found inside $CHROOT_OUTPUT/boot/ - Exiting"
331 eerror "No initrd found inside $CHROOT_OUTPUT/boot/ - Exiting" ; eend 1
335 cp "$CHROOT_OUTPUT"/boot/vmlinuz* "$BUILD_OUTPUT"/boot/isolinux/linux26
336 cp /usr/lib/syslinux/chain.c32 "$BUILD_OUTPUT"/boot/isolinux/
337 cp /usr/lib/syslinux/isolinux.bin "$BUILD_OUTPUT"/boot/isolinux/
338 cp /usr/lib/syslinux/memdisk "$BUILD_OUTPUT"/boot/isolinux/
339 cp /usr/lib/syslinux/menu.c32 "$BUILD_OUTPUT"/boot/isolinux/
341 [ -n "$TEMPLATE_DIRECTORY" ] || TEMPLATE_DIRECTORY='/usr/share/grml-live/templates'
342 if ! [ -d "${TEMPLATE_DIRECTORY}"/boot ] ; then
343 log "${TEMPLATE_DIRECTORY}/boot does not exist. Exiting."
344 eerror "${TEMPLATE_DIRECTORY}/boot does not exist. Exiting." ; eend 1
347 cp ${TEMPLATE_DIRECTORY}/boot/isolinux/* "$BUILD_OUTPUT"/boot/isolinux/
348 cp ${TEMPLATE_DIRECTORY}/boot/isolinux/* "$BUILD_OUTPUT"/boot/isolinux/
349 cp -a ${TEMPLATE_DIRECTORY}/boot/grub "$BUILD_OUTPUT"/boot/
351 if ! [ -d "${TEMPLATE_DIRECTORY}"/GRML ] ; then
352 log "${TEMPLATE_DIRECTORY}/GRML does not exist. Exiting."
353 eerror "${TEMPLATE_DIRECTORY}/GRML does not exist. Exiting." ; eend 1
356 [ -d "$BUILD_OUTPUT"/GRML ] || mkdir "$BUILD_OUTPUT"/GRML
357 cp -a ${TEMPLATE_DIRECTORY}/GRML/* "$BUILD_OUTPUT"/GRML/
359 # adjust boot splash information:
360 ISO_DATE="$(date +%Y-%m-%d)"
361 RELEASE_INFO="$GRML_NAME $VERSION - Release Codename $RELEASENAME"
362 RELEASE_INFO="$(cut_string 68 "$RELEASE_INFO")"
363 RELEASE_INFO="$(extend_string_end 68 "$RELEASE_INFO")"
365 sed -i "s/%RELEASE_INFO%/$GRML_NAME $VERSION - $RELEASENAME/" "$BUILD_OUTPUT"/GRML/grml-version
366 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_OUTPUT"/GRML/grml-version
368 sed -i "s/%RELEASE_INFO%/$RELEASE_INFO/" "$BUILD_OUTPUT"/boot/isolinux/boot.msg
369 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_OUTPUT"/boot/isolinux/boot.msg
371 sed -i "s/%RELEASE_INFO%/$RELEASE_INFO/" "$BUILD_OUTPUT"/boot/isolinux/boot-beep.msg
372 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_OUTPUT"/boot/isolinux/boot-beep.msg
374 sed -i "s/%VERSION%/$VERSION/" "$BUILD_OUTPUT"/boot/grub/menu.lst
375 sed -i "s/%GRML_NAME%/$GRML_NAME/" "$BUILD_OUTPUT"/boot/grub/menu.lst
377 # autostart for Windows:
378 if [ -d "${TEMPLATE_DIRECTORY}/windows/autostart/" ] ; then
379 cp ${TEMPLATE_DIRECTORY}/windows/autostart/* "$BUILD_OUTPUT"/
382 if [ -n "$WINDOWS_BINARIES" ] ; then
383 if [ -f "$BUILD_OUTPUT"/windows/putty.exe ] ; then
384 log "$BUILD_OUTPUT/windows exists already, skipping stage 'WINDOWS_BINARIES'"
385 ewarn "$BUILD_OUTPUT/windows exists already, skipping stage 'WINDOWS_BINARIES'" ; eend 0
387 mkdir "$BUILD_OUTPUT"/windows
388 ( cd "$BUILD_OUTPUT"/windows
389 for file in pageant plink pscp psftp putty puttygen ; do
390 wget -O ${file}.exe ${WINDOWS_BINARIES}/${file}.exe
393 log "Finished execution of stage 'WINDOWS_BINARIES' [$(date)]"
394 einfo "Finished execution of stage 'WINDOWS_BINARIES'" ; eend 0
396 einfo "Finished execution of stage 'boot'" ; eend 0
399 elif [ "$ARCH" = powerpc ] ; then
400 ewarn 'Warning: formorer, it is your turn. :)'>&2
403 eerror 'Error: Unsupported ARCH, sorry. Want to support it? Contribute!' ; eend 1
406 if [ -f "$BUILD_OUTPUT"/live/grml.squashfs ] ; then
407 log "$BUILD_OUTPUT/live exists already, skipping stage 'squashfs'"
408 ewarn "$BUILD_OUTPUT/live exists already, skipping stage 'squashfs'" ; eend 0
410 mkdir "$BUILD_OUTPUT"/live
411 mksquashfs $CHROOT_OUTPUT/* $BUILD_OUTPUT/live/grml.squashfs -noappend
412 log "Finished execution of stage 'squashfs' [$(date)]"
413 einfo "Finished execution of stage 'squashfs'" ; eend 0
416 # create md5sum file:
417 ( cd $BUILD_OUTPUT/GRML &&
418 find .. -type f -not -name md5sums -not -name isolinux.bin -exec md5sum {} \; > md5sums )
421 # ISO_OUTPUT - mkisofs {{{
422 [ -n "$ISO_OUTPUT" ] || ISO_OUTPUT="$OUTPUT/grml_isos"
423 [ -n "$ISO_NAME" ] || ISO_NAME="${GRML_NAME}_${VERSION}.iso"
425 if [ "$BOOT_METHOD" = "isolinux" ] ; then
426 BOOT_FILE="boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat"
427 elif [ "$BOOT_METHOD" = "grub" ] ; then
428 BOOT_FILE="boot/grub/stage2_eltorito"
431 if [ -f "${ISO_OUTPUT}/${ISO_NAME}" ] ; then
432 log "$ISO_OUTPUT exists already, skipping stage 'iso build'"
433 ewarn "$ISO_OUTPUT exists already, skipping stage 'iso build'" ; eend 0
435 mkdir -p "$ISO_OUTPUT" || bailout 6 "Problem with creating $ISO_OUTPUT for stage 'iso build'"
437 cd "$BUILD_OUTPUT" &&
438 mkisofs -V "grml $VERSION" -publisher 'grml-live | grml.org' \
439 -l -r -J -no-emul-boot -boot-load-size 4 -boot-info-table \
441 -o "${ISO_OUTPUT}/${ISO_NAME}" . ; RC=$?
443 if [ "$RC" = 0 ] ; then
444 log "Finished execution of stage 'iso build' [$(date)]"
445 einfo "Finished execution of stage 'iso build'" ; eend 0
447 log "There was an error ($RC) executing stage 'iso build' [$(date)]"
448 eerror "There was an error executing stage 'iso build'" ; eend 1
455 [ -n "$start_seconds" ] && SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]"
456 einfo "Sucessfully finished execution of $PN [running ${SECONDS} seconds]" ; eend 0
457 log "Sucessfully finished execution of $PN [running ${SECONDS} seconds]"
458 log "------------------------------------------------------------------------------"
462 ## END OF FILE #################################################################
463 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3