#!/bin/bash # Filename: grml-live # Purpose: build process script for generating a (grml based) Linux Live-ISO # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2 or any later version. # Latest change: Tue Sep 18 22:46:28 CEST 2007 [mika] ################################################################################ # read configuration files, set some misc variables {{{ export LANG=C export LC_ALL=C # exit on any error: set -e # we need root permissions for the build-process: if [ "$(id -u 2>/dev/null)" != 0 ] ; then echo "Error: please run this script with uid 0 (root)." >&2 exit 1 fi # make sure they are not set by default VERBOSE='' FORCE='' # source main configuration file: LIVE_CONF=/etc/grml/grml-live.conf . $LIVE_CONF PN=$(basename $0) # TMPFILE=$(mktemp) # }}} # clean exit {{{ bailout() { # rm -f "$TMPFILE" [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_TARGET}/${MIRROR_DIRECTORY}" [ -n "$1" ] && EXIT="$1" || EXIT="1" [ -n "$2" ] && echo "$2">&2 exit "$EXIT" } trap bailout 1 2 3 15 # }}} # check for important variables {{{ [ -n "$GRML_FAI_CONFIG" ] || GRML_FAI_CONFIG=/etc/grml/fai [ -n "$HOSTNAME" ] || HOSTNAME=grml [ -n "$USERNAME" ] || USERNAME=grml [ -n "$CLASSES" ] || CLASSES="GRML,I386" [ -n "$TARGET" ] || bailout 1 "${PN}: \$TARGET not specified. Please adjust $LIVE_CONF. Exiting." # }}} # usage information {{{ usage() { echo " $PN - build process script for generating a (grml based) Linux Live-ISO Usage: $PN [-c ] [-t ] [-s [-Fvh] Usage examples: $PN $PN -c GRMLBASE,GRML_X,I386 -t /grml/ $PN -c GRMLBASE,I386 -t /dev/shm/grml $PN -c GRMLBASE,GRML_SMALL,I386 $PN -s sid -c GRMLBASE,I386 More details: man grml-live /usr/share/doc/grml-live/grml-live.html Please send your bug reports, feedback,.. to the grml-team. http://grml.org/bugs/ " } # }}} # command line parsing {{{ while getopts "c:s:t:Fhv" opt; do case "$opt" in c) CLASSES="$OPTARG" ;; F) FORCE=1 ;; h) usage ; bailout 0 ;; s) SUITE="$OPTARG" ;; t) TARGET="$OPTARG" CHROOT_TARGET="$TARGET/grml_chroot" BUILD_TARGET="$TARGET/grml_cd" ISO_TARGET="$TARGET/grml_isos" ;; v) VERBOSE="-v" ;; ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;; esac done shift $(($OPTIND - 1)) # set ARGV to the first not parsed commandline parameter # }}} # some misc checks before executing FAI {{{ [ -n "$CLASSES" ] || bailout 1 "Error: \$CLASSES unset, please set it in $LIVE_CONF or specify it on the command line using the -c|--classes option." [ -n "$TARGET" ] || bailout 1 "Error: \$TARGET unset, please set it in $LIVE_CONF or specify it on the command line using the -t|--target option." # }}} # ask user whether the setup is ok {{{ if [ -z "$FORCE" ] ; then echo echo "$PN - check your configuration (or invoke using -F to force execution without prompting):" echo echo " FAI classes: $CLASSES" echo " main directory: $TARGET" [ -n "$CHROOT_TARGET" ] && echo " chroot target: $CHROOT_TARGET" [ -n "$BUILD_TARGET" ] && echo " build target: $BUILD_TARGET" [ -n "$ISO_TARGET" ] && echo " ISO target: $ISO_TARGET" [ -n "$SUITE" ] && echo " Debian suite: $SUITE" [ -n "$FAI_ARGS" ] && echo " additional arguments for FAI: $FAI_ARGS" [ -n "$VERBOSE" ] && echo " Using VERBOSE mode." echo echo -n "Is this ok for you? [y/N] " read a if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then bailout 1 "Exiting as requested." fi echo fi # }}} # on-the-fly configuration {{{ if [ -n "$MIRROR_DIRECTORY" ] ; then if ! [ -d "$MIRROR_DIRECTORY/debian" ] ; then echo "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting.">&2 bailout 1 fi echo "$MIRROR_SOURCES" > /etc/grml/fai/apt/sources.list if [ -n "$GRML_LIVE_SOURCES" ] ; then echo "$GRML_LIVE_SOURCES" >> /etc/grml/fai/apt/sources.list fi elif [ -n "$GRML_LIVE_SOURCES" ] ; then echo "$GRML_LIVE_SOURCES" > /etc/grml/fai/apt/sources.list fi if [ -n "$FAI_DEBOOTSTRAP" ] ; then sed -i "s#^FAI_DEBOOTSTRAP=.*#FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"#" /etc/grml/fai/make-fai-nfsroot.conf fi # does this suck? YES! if [ -n "$SUITE" ] ; then sed -i "s/SUITE=.*/SUITE=\"$SUITE\"/" $LIVE_CONF DIST="\|\ etch\ \|\ stable\ \|\ lenny\ \|\ testing\ \|\ sid\ \|\ unstable\ " sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" $LIVE_CONF sed -i "s/\(deb .\+\)\([ \t]+\)$DIST\([ \t]+\)\(main \)/\1\2 $SUITE \3\4/" /etc/grml/fai/apt/sources.list DIST='\"etch\|=\"stable=\"lenny=\"testing=\"sid=\"unstable' sed -i "s#FAI_DEBOOTSTRAP=$DIST#FAI_DEBOOTSTRAP=\"$SUITE#" $LIVE_CONF sed -i "s#FAI_DEBOOTSTRAP=$DIST#FAI_DEBOOTSTRAP=\"$SUITE#" /etc/grml/fai/make-fai-nfsroot.conf fi # }}} # CHROOT_TARGET - execute FAI {{{ [ -n "$CHROOT_TARGET" ] || CHROOT_TARGET="$TARGET/grml_chroot" if [ -d "$CHROOT_TARGET" ] ; then echo " [x] $CHROOT_TARGET exists already, skipping the stage 'fai dirnstall'" else mkdir -p "$CHROOT_TARGET" || bailout 5 "Problem with creating $CHROOT_TARGET for FAI" if [ -n "${MIRROR_DIRECTORY}" ] ; then mkdir -p "${CHROOT_TARGET}/${MIRROR_DIRECTORY}" mount --bind "${MIRROR_DIRECTORY}" "${CHROOT_TARGET}/${MIRROR_DIRECTORY}" fi fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" dirinstall "$CHROOT_TARGET" $FAI_ARGS umount $CHROOT_TARGET/proc 2>/dev/null || /bin/true umount $CHROOT_TARGET/sys 2>/dev/null || /bin/true [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_TARGET}/${MIRROR_DIRECTORY}" # notice: 'fai dirinstall' does not seem to exit appropriate -> if grep -q 'dpkg: error processing' /var/log/fai/dirinstall/$HOSTNAME/software.log || \ grep -q 'FAILED with exit code' /var/log/fai/dirinstall/$HOSTNAME/shell.log ; then echo " [!] There was an error during execution of stage 'fai dirinstall'" echo " Check out /var/log/fai/dirinstall/$HOSTNAME/... for details" exit 1 else echo " [*] Finished execution of stage 'fai dirinstall'" fi fi # }}} # BUILD_TARGET - execute arch specific stuff and squashfs {{{ [ -n "$BUILD_TARGET" ] || BUILD_TARGET="$TARGET/grml_cd" mkdir -p "$BUILD_TARGET" || bailout 6 "Problem with creating $BUILD_TARGET for stage ARCH" # i386: [ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)" if [ "$ARCH" = i386 ] ; then if [ -d "$BUILD_TARGET"/boot/isolinux ] ; then echo " [x] $BUILD_TARGET/boot/isolinux exists already - skipping stage 'boot/isolinux'" continue else # booting stuff: mkdir -p "$BUILD_TARGET"/boot/isolinux mkdir "$BUILD_TARGET"/GRML cp /boot/memtest86+.bin "$BUILD_TARGET"/boot/isolinux/memtest cp "$CHROOT_TARGET"/boot/initrd* "$BUILD_TARGET"/boot/isolinux/initrd.gz cp "$CHROOT_TARGET"/boot/vmlinuz* "$BUILD_TARGET"/boot/isolinux/linux26 cp /usr/lib/syslinux/chain.c32 "$BUILD_TARGET"/boot/isolinux/ cp /usr/lib/syslinux/isolinux.bin "$BUILD_TARGET"/boot/isolinux/ cp /usr/lib/syslinux/memdisk "$BUILD_TARGET"/boot/isolinux/ cp /usr/lib/syslinux/menu.c32 "$BUILD_TARGET"/boot/isolinux/ cp /usr/share/grml-live/i386_files/boot/isolinux/allinone.img "$BUILD_TARGET"/boot/isolinux/ cp /usr/share/grml-live/i386_files/boot/isolinux/balder10.imz "$BUILD_TARGET"/boot/isolinux/ cp /usr/share/grml-live/i386_files/boot/isolinux/boot-beep.msg "$BUILD_TARGET"/boot/isolinux/ cp /usr/share/grml-live/i386_files/boot/isolinux/boot.msg "$BUILD_TARGET"/boot/isolinux/ cp /usr/share/grml-live/i386_files/boot/isolinux/f* "$BUILD_TARGET"/boot/isolinux/ cp /usr/share/grml-live/i386_files/boot/isolinux/isolinux.cfg "$BUILD_TARGET"/boot/isolinux/ cp /usr/share/grml-live/i386_files/boot/isolinux/logo.16 "$BUILD_TARGET"/boot/isolinux/ cp /usr/share/grml-live/i386_files/boot/isolinux/syslinux.cfg "$BUILD_TARGET"/boot/isolinux/ # autostart for Windows: cp /usr/share/grml-live/windows/autostart/autorun.bat "$BUILD_TARGET"/ cp /usr/share/grml-live/windows/autostart/autorun.inf "$BUILD_TARGET"/ cp /usr/share/grml-live/windows/autostart/autorun.pif "$BUILD_TARGET"/ cp /usr/share/grml-live/windows/autostart/cdrom.ico "$BUILD_TARGET"/ # windows-binaries: if [ -n "$WINDOWS_BINARIES" ] ; then if [ -d "$BUILD_TARGET"/windows ] ; then echo " [x] $BUILD_TARGET/windows exists already - skipping stage 'WINDOWS_BINARIES'" return 0 else mkdir "$BUILD_TARGET"/windows ( cd "$BUILD_TARGET"/windows for file in pageant plink pscp psftp putty puttygen ; do wget ${WINDOWS_BINARIES}/${file}.exe done ) fi echo " [*] Finished execution of stage 'WINDOWS_BINARIES'" fi echo " [*] Finished execution of stage 'boot/isolinux'" fi # amd64: elif [ "$ARCH" = amd64 ] ; then echo 'Warning: gebi, it is your turn. :)'>&2 # ppc: elif [ "$ARCH" = powerpc ] ; then echo 'Warning: formorer, it is your turn. :)'>&2 # unsuported: else echo 'Warning: Unsupported ARCH, sorry. Want to support it? Contribute!'>&2 fi if [ -d "$BUILD_TARGET"/live ] ; then echo " [x] $BUILD_TARGET/live exists already, skipping stage 'squashfs'" else mkdir "$BUILD_TARGET"/live mksquashfs $CHROOT_TARGET/* $BUILD_TARGET/live/grml.squashfs -noappend fi echo " [*] Finished execution of stage 'squashfs'" # }}} # ISO_TARGET - mkisofs {{{ [ -n "$ISO_TARGET" ] || ISO_TARGET="$TARGET/grml_isos" if [ -d "$ISO_TARGET" ] ; then echo " [x] $ISO_TARGET exists already, skipping the stage 'iso build'" else mkdir -p "$ISO_TARGET" || bailout 6 "Problem with creating $ISO_TARGET for stage 'iso build'" ( cd "$BUILD_TARGET" && mkisofs -V "Debian/etch grml" -publisher 'Michael Prokop ' \ -l -r -J -no-emul-boot -boot-load-size 4 -boot-info-table \ -c boot/isolinux/boot.cat -b boot/isolinux/isolinux.bin \ -o "$ISO_TARGET"/grml_0.0-1.iso . ) echo " [*] Finished execution of stage 'iso build'" fi # }}} # finalize {{{ echo " [*] Sucessfully finished execution of $PN" bailout 0 # }}} ## END OF FILE ################################################################# # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3