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: Sun Oct 28 14:43:27 CET 2007 [mika]
8 ################################################################################
10 # read configuration files, set some misc variables {{{
18 GRML_LIVE_VERSION='0.0.7'
20 # we need root permissions for the build-process:
21 if [ "$(id -u 2>/dev/null)" != 0 ] ; then
22 echo "Error: please run this script with uid 0 (root)." >&2
26 if [ -r /var/run/fai/FAI_INSTALLATION_IN_PROGRESS ] ; then
27 echo "/usr/sbin/fai already running or was aborted before.">&2
28 echo "You may remove /var/run/fai/FAI_INSTALLATION_IN_PROGRESS and try again.">&2
32 # make sure they are not set by default
36 if [ -r /etc/grml/lsb-functions ] ; then
37 . /etc/grml/lsb-functions
39 einfo() { echo " [*] $*" ;}
40 eerror() { echo " [!] $*">&2 ;}
41 ewarn() { echo " [x] $*" ;}
45 # source main configuration file:
46 LIVE_CONF=/etc/grml/grml-live.conf
54 [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
55 [ -n "$1" ] && EXIT="$1" || EXIT="1"
56 [ -n "$2" ] && eerror "$2">&2
62 # check for important variables {{{
63 [ -n "$GRML_FAI_CONFIG" ] || GRML_FAI_CONFIG=/etc/grml/fai
64 [ -n "$HOSTNAME" ] || HOSTNAME=grml
65 [ -n "$USERNAME" ] || USERNAME=grml
66 [ -n "$CLASSES" ] || CLASSES="GRML,I386"
67 [ -n "$BOOT_METHOD" ] || BOOT_METHOD='isolinux'
68 [ -n "$OUTPUT" ] || bailout 1 "${PN}: \$OUTPUT not specified. Please adjust $LIVE_CONF. Exiting."
70 [ -n "$VERSION" ] || VERSION="0.0.1"
71 [ -n "$RELEASENAME" ] || RELEASENAME="grml-live rocks"
72 [ -n "$GRML_NAME" ] || GRML_NAME='grml'
75 if [ -z "$LOGFILE" ] ; then
76 LOGFILE=/var/log/grml-live.log
79 chown root:adm $LOGFILE
82 if [ -n "$ZERO_LOGFILE" ] ; then
86 NFSROOT_CONF=/etc/grml/fai/make-fai-nfsroot.conf
90 # some important functions {{{
93 # usage: log "string to log"
94 log() { echo "$*" >> $LOGFILE ; }
96 # cut string at character number int = $1
97 # usage: cut_string 5 "1234567890" will output "12345"
99 [ -n "$2" ] || return 1
100 echo "$2" | head -c "$1"; echo -ne "\n"
103 # prepend int = $1 spaces before string = $2
104 # usage: extend_string_begin 5 "123" will output " 123"
105 extend_string_begin() {
106 [ -n "$2" ] || return 1
107 local COUNT="$(echo $2 | wc -c)"
108 local FILL="$(expr $COUNT - $1)"
109 while [ "$FILL" -gt 1 ] ; do
111 local FILL=$(expr $FILL - 1)
113 while [ "$FILL" -lt 1 ] ; do
115 local FILL=$(expr $FILL + 1)
117 echo "$2" | head -c "$1"; echo -ne "\n"
120 # append int = $1 spaces to string = $2
121 # usage: extend_string_begin 5 "123" will output "123 "
122 extend_string_end() {
123 [ -n "$2" ] || return 1
124 echo -n "$2" | head -c "$1"
125 local COUNT="$(echo $2 | wc -c)"
126 local FILL="$(expr $COUNT - $1)"
127 while [ "$FILL" -gt 1 ] ; do
129 local FILL=$(expr $FILL - 1)
131 while [ "$FILL" -lt 1 ] ; do
133 local FILL=$(expr $FILL + 1)
139 # usage information {{{
143 $PN - build process script for generating a (grml based) Linux Live-ISO
145 Usage: $PN [-a <architecture>] [-c <classe[s]>] [-g <grml_name>] \\
146 [-i <iso_name> ] [-o <output_directory>] [-s <suite>] \\
147 [-t <template_directory>] [-s <suite>] \\
148 [-v <version_number>] [-FVh]
153 $PN -c GRMLBASE,GRML_SMALL,I386 -o /grml/
154 $PN -c GRMLBASE,GRML_MEDIUM,I386 -o /dev/shm/grml
155 $PN -c GRMLBASE,GRML_SMALL,I386 -g grml-small -v 1.0
156 $PN -c GRMLBASE,GRML_FULL,I386 -i grml_0.0-1.iso -v 0.0-1
157 $PN -c GRMLBASE,GRML_FULL,I386 -s sid -V -r 'grml-live rocks'
159 More details: man grml-live
160 /usr/share/doc/grml-live/grml-live.html
162 Please send your bug reports, feedback,.. to the grml-team.
163 http://grml.org/bugs/
168 # command line parsing {{{
170 while getopts "a:c:g:i:o:r:s:t:v:FhV" opt; do
173 c) CLASSES="$OPTARG" ;;
174 g) GRML_NAME="$OPTARG" ;;
175 i) ISO_NAME="$OPTARG" ;;
177 CHROOT_OUTPUT="$OUTPUT/grml_chroot"
178 BUILD_OUTPUT="$OUTPUT/grml_cd"
179 ISO_OUTPUT="$OUTPUT/grml_isos"
181 r) RELEASENAME="$OPTARG" ;;
182 s) SUITE="$OPTARG" ;;
183 t) TEMPLATE_DIRECTORY="$OPTARG";;
184 v) VERSION="$OPTARG" ;;
186 h) usage ; bailout 0 ;;
188 ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;;
191 shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter
194 # some misc checks before executing FAI {{{
195 [ -n "$CLASSES" ] || bailout 1 "Error: \$CLASSES unset, please set it in $LIVE_CONF or
196 specify it on the command line using the -c option."
197 [ -n "$OUTPUT" ] || bailout 1 "Error: \$OUTPUT unset, please set it in $LIVE_CONF or
198 specify it on the command line using the -o option."
201 # ask user whether the setup is ok {{{
202 if [ -z "$FORCE" ] ; then
204 echo "${PN} [${GRML_LIVE_VERSION}]: check your configuration (or use -F to force execution):"
206 echo " FAI classes: $CLASSES"
207 echo " main directory: $OUTPUT"
208 [ -n "$CHROOT_OUTPUT" ] && echo " chroot target: $CHROOT_OUTPUT"
209 [ -n "$BUILD_OUTPUT" ] && echo " build target: $BUILD_OUTPUT"
210 [ -n "$ISO_OUTPUT" ] && echo " ISO target: $ISO_OUTPUT"
211 [ -n "$GRML_NAME" ] && echo " grml name: $GRML_NAME"
212 [ -n "$RELEASENAME" ] && echo " release name: $RELEASENAME"
213 [ -n "$VERSION" ] && echo " grml version: $VERSION"
214 [ -n "$SUITE" ] && echo " Debian suite: $SUITE"
215 [ -n "$ARCH" ] && echo " Architecture: $ARCH"
216 [ -n "$BOOT_METHOD" ] && echo " Boot method: $BOOT_METHOD"
217 [ -n "$TEMPLATE_DIRECTORY" ] && echo " Template files: $TEMPLATE_DIRECTORY"
218 [ -n "$FAI_ARGS" ] && echo " additional arguments for FAI: $FAI_ARGS"
219 [ -n "$LOGFILE" ] && echo " Logging to file: $LOGFILE"
220 [ -n "$VERBOSE" ] && echo " Using VERBOSE mode."
222 echo -n "Is this ok for you? [y/N] "
224 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
225 bailout 1 "Exiting as requested."
230 start_seconds=$(cut -d . -f 1 /proc/uptime)
231 log "------------------------------------------------------------------------------"
232 log "Starting grml-live [${GRML_LIVE_VERSION}] run [$(date)]"
233 log "Executed command line: $0 $@"
235 einfo "Logging actions to logfile $LOGFILE"
238 # on-the-fly configuration {{{
239 if [ -n "$MIRROR_DIRECTORY" ] ; then
240 if ! [ -d "$MIRROR_DIRECTORY/debian" ] ; then
241 log "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting. [$(date)]"
242 eerror "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting."
245 echo "$MIRROR_SOURCES" > /etc/grml/fai/apt/sources.list
246 if [ -n "$GRML_LIVE_SOURCES" ] ; then
247 echo "$GRML_LIVE_SOURCES" >> /etc/grml/fai/apt/sources.list
249 elif [ -n "$GRML_LIVE_SOURCES" ] ; then
250 echo "$GRML_LIVE_SOURCES" > /etc/grml/fai/apt/sources.list
253 if [ -n "$FAI_DEBOOTSTRAP" ] ; then
254 sed -i "s#^FAI_DEBOOTSTRAP=.*#FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"#" $NFSROOT_CONF
257 # does this suck? YES!
258 if [ -n "$SUITE" ] ; then
259 sed -i "s/SUITE=.*/SUITE=\"$SUITE\"/" $LIVE_CONF
261 DIST="\|\ etch\ \|\ stable\ \|\ lenny\ \|\ testing\ \|\ sid\ \|\ unstable\ "
262 sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" $LIVE_CONF
263 sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" /etc/grml/fai/apt/sources.list
264 # notice: activate grml-live pool only if we are building against unstable:
265 if grep -qe unstable -qe sid /etc/grml/fai/apt/sources.list ; then
266 grep -q 'grml-live.*main' /etc/grml/fai/apt/sources.list || \
267 grep grml-stable /etc/grml/fai/apt/sources.list | \
268 sed 's/grml-stable/grml-live/' >> /etc/grml/fai/apt/sources.list
270 grep -q 'grml-live.*main' /etc/grml/fai/apt/sources.list && \
271 sed -i 's/.*grml-live.*/# removed grml-live repository/' /etc/grml/fai/apt/sources.list
274 sed -i "s|FAI_DEBOOTSTRAP=\"[a-z]* |FAI_DEBOOTSTRAP=\"$SUITE |" $LIVE_CONF
275 sed -i "s|FAI_DEBOOTSTRAP=\"[a-z]* |FAI_DEBOOTSTRAP=\"$SUITE |" $NFSROOT_CONF
279 [ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)"
280 if grep -q -- 'FAI_DEBOOTSTRAP_OPTS.*--arch' $NFSROOT_CONF ; then
281 sed -i "s/--arch [a-z0-9]* /--arch $ARCH /" $NFSROOT_CONF
283 sed -i "s|FAI_DEBOOTSTRAP_OPTS=\"\(.*\)|FAI_DEBOOTSTRAP_OPTS=\"--arch $ARCH \1|" $NFSROOT_CONF
287 # CHROOT_OUTPUT - execute FAI {{{
288 [ -n "$CHROOT_OUTPUT" ] || CHROOT_OUTPUT="$OUTPUT/grml_chroot"
290 if [ -d "$CHROOT_OUTPUT/bin" ] ; then
291 log "$CHROOT_OUTPUT exists already, skipping stage 'fai dirinstall'"
292 ewarn "$CHROOT_OUTPUT exists already, skipping stage 'fai dirinstall'" ; eend 0
294 mkdir -p "$CHROOT_OUTPUT" || bailout 5 "Problem with creating $CHROOT_OUTPUT for FAI"
295 if [ -n "${MIRROR_DIRECTORY}" ] ; then
296 mkdir -p "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
297 mount --bind "${MIRROR_DIRECTORY}" "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
299 fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" -u "$HOSTNAME" dirinstall "$CHROOT_OUTPUT" $FAI_ARGS | tee -a $LOGFILE
300 umount $CHROOT_OUTPUT/proc 2>/dev/null || /bin/true
301 umount $CHROOT_OUTPUT/sys 2>/dev/null || /bin/true
302 [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
304 # notice: 'fai dirinstall' does not seem to exit appropriate, so:
306 if [ -r "/var/log/fai/dirinstall/$HOSTNAME/software.log" ] ; then
307 # 1 errors during executing of commands
308 # Unable to write mmap - msync (28 No space left on device)
309 grep 'dpkg: error processing' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=1
310 grep 'E: Method http has died unexpectedly!' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=2
311 grep 'ERROR: chroot' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=3
314 if [ -r "/var/log/fai/dirinstall/$HOSTNAME/shell.log" ] ; then
315 grep 'FAILED with exit code' /var/log/fai/dirinstall/$HOSTNAME/shell.log >> $LOGFILE && ERROR=2
318 if [ -n "$ERROR" ] ; then
319 log "There was an error [${ERROR}] during execution of stage 'fai dirinstall' [$(date)]"
320 eerror "There was an error during execution of stage 'fai dirinstall'"
321 echo " Check out /var/log/fai/dirinstall/$HOSTNAME/ for details. [exit ${ERROR}]"
325 log "Finished execution of stage 'fai dirinstall' [$(date)]"
326 einfo "Finished execution of stage 'fai dirinstall'"
331 # BUILD_OUTPUT - execute arch specific stuff and squashfs {{{
332 [ -n "$BUILD_OUTPUT" ] || BUILD_OUTPUT="$OUTPUT/grml_cd"
333 mkdir -p "$BUILD_OUTPUT" || bailout 6 "Problem with creating $BUILD_OUTPUT for stage ARCH"
336 if [ "$ARCH" = i386 ] || [ "$ARCH" = amd64 ] ; then
337 if [ -d "$BUILD_OUTPUT"/boot ] ; then
338 log "$BUILD_OUTPUT/boot exists already, skipping stage 'boot'"
339 ewarn "$BUILD_OUTPUT/boot exists already, skipping stage 'boot'" ; eend 0
342 mkdir -p "$BUILD_OUTPUT"/boot/isolinux
343 cp /boot/memtest86+.bin "$BUILD_OUTPUT"/boot/isolinux/memtest
345 # if we don't have an initrd we a) can't boot and b) there was an error
346 # during build, so check for the file:
347 if [ -f "$CHROOT_OUTPUT"/boot/initrd* ] ; then
348 cp "$CHROOT_OUTPUT"/boot/initrd* "$BUILD_OUTPUT"/boot/isolinux/initrd.gz
350 log "No initrd found inside $CHROOT_OUTPUT/boot/ - Exiting"
351 eerror "No initrd found inside $CHROOT_OUTPUT/boot/ - Exiting" ; eend 1
355 cp "$CHROOT_OUTPUT"/boot/vmlinuz* "$BUILD_OUTPUT"/boot/isolinux/linux26
356 cp /usr/lib/syslinux/chain.c32 "$BUILD_OUTPUT"/boot/isolinux/
357 cp /usr/lib/syslinux/isolinux.bin "$BUILD_OUTPUT"/boot/isolinux/
358 cp /usr/lib/syslinux/memdisk "$BUILD_OUTPUT"/boot/isolinux/
359 cp /usr/lib/syslinux/menu.c32 "$BUILD_OUTPUT"/boot/isolinux/
361 [ -n "$TEMPLATE_DIRECTORY" ] || TEMPLATE_DIRECTORY='/usr/share/grml-live/templates'
362 if ! [ -d "${TEMPLATE_DIRECTORY}"/boot ] ; then
363 log "${TEMPLATE_DIRECTORY}/boot does not exist. Exiting."
364 eerror "${TEMPLATE_DIRECTORY}/boot does not exist. Exiting." ; eend 1
367 cp ${TEMPLATE_DIRECTORY}/boot/isolinux/* "$BUILD_OUTPUT"/boot/isolinux/
368 cp ${TEMPLATE_DIRECTORY}/boot/isolinux/* "$BUILD_OUTPUT"/boot/isolinux/
369 cp -a ${TEMPLATE_DIRECTORY}/boot/grub "$BUILD_OUTPUT"/boot/
371 if ! [ -d "${TEMPLATE_DIRECTORY}"/GRML ] ; then
372 log "${TEMPLATE_DIRECTORY}/GRML does not exist. Exiting."
373 eerror "${TEMPLATE_DIRECTORY}/GRML does not exist. Exiting." ; eend 1
376 [ -d "$BUILD_OUTPUT"/GRML ] || mkdir "$BUILD_OUTPUT"/GRML
377 cp -a ${TEMPLATE_DIRECTORY}/GRML/* "$BUILD_OUTPUT"/GRML/
379 # adjust boot splash information:
380 ISO_DATE="$(date +%Y-%m-%d)"
381 RELEASE_INFO="$GRML_NAME $VERSION - Release Codename $RELEASENAME"
382 RELEASE_INFO="$(cut_string 68 "$RELEASE_INFO")"
383 RELEASE_INFO="$(extend_string_end 68 "$RELEASE_INFO")"
385 sed -i "s/%RELEASE_INFO%/$GRML_NAME $VERSION - $RELEASENAME/" "$BUILD_OUTPUT"/GRML/grml-version
386 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_OUTPUT"/GRML/grml-version
388 sed -i "s/%RELEASE_INFO%/$RELEASE_INFO/" "$BUILD_OUTPUT"/boot/isolinux/boot.msg
389 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_OUTPUT"/boot/isolinux/boot.msg
391 sed -i "s/%RELEASE_INFO%/$RELEASE_INFO/" "$BUILD_OUTPUT"/boot/isolinux/boot-beep.msg
392 sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_OUTPUT"/boot/isolinux/boot-beep.msg
394 sed -i "s/%VERSION%/$VERSION/" "$BUILD_OUTPUT"/boot/grub/menu.lst
395 sed -i "s/%GRML_NAME%/$GRML_NAME/" "$BUILD_OUTPUT"/boot/grub/menu.lst
397 # autostart for Windows:
398 if [ -d "${TEMPLATE_DIRECTORY}/windows/autostart/" ] ; then
399 cp ${TEMPLATE_DIRECTORY}/windows/autostart/* "$BUILD_OUTPUT"/
402 if [ -n "$WINDOWS_BINARIES" ] ; then
403 if [ -f "$BUILD_OUTPUT"/windows/putty.exe ] ; then
404 log "$BUILD_OUTPUT/windows exists already, skipping stage 'WINDOWS_BINARIES'"
405 ewarn "$BUILD_OUTPUT/windows exists already, skipping stage 'WINDOWS_BINARIES'" ; eend 0
407 mkdir "$BUILD_OUTPUT"/windows
408 ( cd "$BUILD_OUTPUT"/windows
409 for file in pageant plink pscp psftp putty puttygen ; do
410 wget -O ${file}.exe ${WINDOWS_BINARIES}/${file}.exe
413 log "Finished execution of stage 'WINDOWS_BINARIES' [$(date)]"
414 einfo "Finished execution of stage 'WINDOWS_BINARIES'" ; eend 0
416 einfo "Finished execution of stage 'boot'" ; eend 0
419 elif [ "$ARCH" = powerpc ] ; then
420 ewarn 'Warning: formorer, it is your turn. :)'>&2
423 eerror 'Error: Unsupported ARCH, sorry. Want to support it? Contribute!' ; eend 1
426 if [ -f "$BUILD_OUTPUT"/live/grml.squashfs ] ; then
427 log "$BUILD_OUTPUT/live exists already, skipping stage 'squashfs'"
428 ewarn "$BUILD_OUTPUT/live exists already, skipping stage 'squashfs'" ; eend 0
430 mkdir "$BUILD_OUTPUT"/live
431 mksquashfs $CHROOT_OUTPUT/* $BUILD_OUTPUT/live/grml.squashfs -noappend
432 log "Finished execution of stage 'squashfs' [$(date)]"
433 einfo "Finished execution of stage 'squashfs'" ; eend 0
436 # create md5sum file:
437 ( cd $BUILD_OUTPUT/GRML &&
438 find .. -type f -not -name md5sums -not -name isolinux.bin -exec md5sum {} \; > md5sums )
441 # ISO_OUTPUT - mkisofs {{{
442 [ -n "$ISO_OUTPUT" ] || ISO_OUTPUT="$OUTPUT/grml_isos"
443 [ -n "$ISO_NAME" ] || ISO_NAME="${GRML_NAME}_${VERSION}.iso"
445 if [ "$BOOT_METHOD" = "isolinux" ] ; then
446 BOOT_FILE="boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat"
447 elif [ "$BOOT_METHOD" = "grub" ] ; then
448 BOOT_FILE="boot/grub/stage2_eltorito"
451 if [ -f "${ISO_OUTPUT}/${ISO_NAME}" ] ; then
452 log "$ISO_OUTPUT exists already, skipping stage 'iso build'"
453 ewarn "$ISO_OUTPUT exists already, skipping stage 'iso build'" ; eend 0
455 mkdir -p "$ISO_OUTPUT" || bailout 6 "Problem with creating $ISO_OUTPUT for stage 'iso build'"
457 cd "$BUILD_OUTPUT" &&
458 mkisofs -V "grml $VERSION" -publisher 'grml-live | grml.org' \
459 -l -r -J -no-emul-boot -boot-load-size 4 -boot-info-table \
461 -o "${ISO_OUTPUT}/${ISO_NAME}" . ; RC=$?
463 if [ "$RC" = 0 ] ; then
464 log "Finished execution of stage 'iso build' [$(date)]"
465 einfo "Finished execution of stage 'iso build'" ; eend 0
467 log "There was an error ($RC) executing stage 'iso build' [$(date)]"
468 eerror "There was an error executing stage 'iso build'" ; eend 1
475 [ -n "$start_seconds" ] && SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]" || SECONDS="unknown"
476 einfo "Sucessfully finished execution of $PN [running ${SECONDS} seconds]" ; eend 0
477 log "Sucessfully finished execution of $PN [running ${SECONDS} seconds]"
478 log "------------------------------------------------------------------------------"
482 ## END OF FILE #################################################################
483 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3