X-Git-Url: https://git.grml.org/?p=grml-live.git;a=blobdiff_plain;f=grml-live;h=ae0e99e551c7404f6f77206c537f332870a58f9c;hp=2734ae2e7ba0a9b8689d1ec9940ce3a1b1342a6b;hb=201df31e812c709b38316fb106cad8da54d0ff73;hpb=e3354f3c1dada77470efbd3bf5172d79b3257b0e diff --git a/grml-live b/grml-live index 2734ae2..ae0e99e 100755 --- a/grml-live +++ b/grml-live @@ -4,7 +4,7 @@ # 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 09:11:50 CEST 2007 [mika] +# Latest change: Wed Sep 19 23:59:48 CEST 2007 [mika] ################################################################################ # read configuration files, set some misc variables {{{ @@ -25,18 +25,27 @@ fi VERBOSE='' FORCE='' +if [ -r /etc/grml/lsb-functions ] ; then + . /etc/grml/lsb-functions +else + einfo() { echo " [*] $*" ;} + eerror() { echo " [!] $*">&2 ;} + ewarn() { echo " [x] $*" ;} + eend() { return 0 ;} +fi + # source main configuration file: -. /etc/grml/grml-live.conf +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 + [ -n "$2" ] && eerror "$2">&2 exit "$EXIT" } trap bailout 1 2 3 15 @@ -47,7 +56,63 @@ trap bailout 1 2 3 15 [ -n "$HOSTNAME" ] || HOSTNAME=grml [ -n "$USERNAME" ] || USERNAME=grml [ -n "$CLASSES" ] || CLASSES="GRML,I386" -[ -n "$TARGET" ] || bailout 1 "${PN}: \$TARGET not specified. Please adjust /etc/grml/grml-live.conf. Exiting." +[ -n "$TARGET" ] || bailout 1 "${PN}: \$TARGET not specified. Please adjust $LIVE_CONF. Exiting." + +[ -n "$VERSION" ] || VERSION="0.0.1" +[ -n "$RELEASENAME" ] || RELEASENAME="grml-live rocks" + +[ -n "$LOGDIR" ] || LOGDIR="/var/log/fai/dirinstall/$HOSTNAME" +[ -d "$LOGDIR" ] || mkdir $LOGDIR +LOGFILE="$LOGDIR/grml-live.conf" +# }}} + +# some important functions {{{ + +# log output: +# usage: log "string to log" +log() { echo "$*" >> $LOGFILE ; } + +# cut string at character number int = $1 +# usage: cut_string 5 "1234567890" will output "12345" +cut_string() { + [ -n "$2" ] || return 1 + echo "$2" | head -c "$1"; echo -ne "\n" +} + +# prepend int = $1 spaces before string = $2 +# usage: extend_string_begin 5 "123" will output " 123" +extend_string_begin() { + [ -n "$2" ] || return 1 + local COUNT="$(echo $2 | wc -c)" + local FILL="$(expr $COUNT - $1)" + while [ "$FILL" -gt 1 ] ; do + echo -n " " + local FILL=$(expr $FILL - 1) + done + while [ "$FILL" -lt 1 ] ; do + echo -n " " + local FILL=$(expr $FILL + 1) + done + echo "$2" | head -c "$1"; echo -ne "\n" +} + +# append int = $1 spaces to string = $2 +# usage: extend_string_begin 5 "123" will output "123 " +extend_string_end() { + [ -n "$2" ] || return 1 + echo -n "$2" | head -c "$1" + local COUNT="$(echo $2 | wc -c)" + local FILL="$(expr $COUNT - $1)" + while [ "$FILL" -gt 1 ] ; do + echo -n " " + local FILL=$(expr $FILL - 1) + done + while [ "$FILL" -lt 1 ] ; do + echo -n " " + local FILL=$(expr $FILL + 1) + done + echo -ne "\n" +} # }}} # usage information {{{ @@ -56,7 +121,8 @@ usage() echo " $PN - build process script for generating a (grml based) Linux Live-ISO -Usage: $PN [-c ] [-t ] [-s [-Fvh] +Usage: $PN [-c ] [-i ] [-r ] \\ + [-s ] [-t ] [-v ] [-Fvh] Usage examples: @@ -64,7 +130,8 @@ Usage examples: $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 + $PN -c GRMLBASE,I386 -v -i grml_0.0-1.iso + $PN -c GRMLBASE,I386 -s sid More details: man grml-live /usr/share/doc/grml-live/grml-live.html @@ -77,19 +144,21 @@ http://grml.org/bugs/ # command line parsing {{{ -while getopts "c:s:t:Fhv" opt; do +while getopts "c:i:r:s:t:v:FhV" opt; do case "$opt" in c) CLASSES="$OPTARG" ;; - # f) FLAVOUR="$OPTARG" ;; # TODO - F) FORCE=1 ;; - h) usage ; bailout 0 ;; + i) ISO_NAME="$OPTARG" ;; + r) RELEASENAME="$OPTARG" ;; s) SUITE="$OPTARG" ;; t) TARGET="$OPTARG" CHROOT_TARGET="$TARGET/grml_chroot" BUILD_TARGET="$TARGET/grml_cd" ISO_TARGET="$TARGET/grml_isos" ;; - v) VERBOSE="-v" ;; + v) VERSION="$OPTARG" ;; + F) FORCE=1 ;; + h) usage ; bailout 0 ;; + V) VERBOSE="-v" ;; ?) echo "invalid option -$OPTARG" >&2; bailout 1 ;; esac done @@ -98,16 +167,16 @@ 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 /etc/grml/grml-live.conf or +[ -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 /etc/grml/grml-live.conf or +[ -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 "${PN}: check your configuration (or use -F to force execution without prompting):" echo echo " FAI classes: $CLASSES" echo " main directory: $TARGET" @@ -124,45 +193,81 @@ if [ -z "$FORCE" ] ; then bailout 1 "Exiting as requested." fi echo + + start_seconds=$(cut -d . -f 1 /proc/uptime) + log "------------------------------------------------------------------------------" + log "Starting grml-live run [$(date)]" fi # }}} # on-the-fly configuration {{{ -if [ -n "$GRML_LIVE_SOURCES" ] ; then +if [ -n "$MIRROR_DIRECTORY" ] ; then + if ! [ -d "$MIRROR_DIRECTORY/debian" ] ; then + eerror "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting." + log "Sorry, $MIRROR_DIRECTORY/debian does not seem to exist. Exiting. [$(date)]" + 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 -# this heuristic is broken as it works exactly *once* by default :-/ -# TODO / FIXME -if [ -n "$SUITE" ] ; then - sed -i "s#etch #$SUITE #" /etc/grml/fai/make-fai-nfsroot.conf - sed -i "s#etch #$SUITE #" /etc/grml/grml-live.conf - sed -i "s# etch # $SUITE #" /etc/grml/grml-live.conf - sed -i "s# etch # $SUITE #" /etc/grml/fai/apt/sources.list +if [ -n "$FAI_DEBOOTSTRAP" ] ; then + sed -i "s#^FAI_DEBOOTSTRAP=.*#FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"#" /etc/grml/fai/make-fai-nfsroot.conf fi -if [ -n "$FAI_DEBOOTSTRAP" ] ; then - sed -i "s#^FAI_DEBOOTSTRAP#FAI_DEBOOTSTRAP=$FAI_DEBOOTSTRAP#" /etc/grml/fai/make-fai-nfsroot.conf +# 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'" +if [ -d "$CHROOT_TARGET/bin" ] ; then + ewarn "$CHROOT_TARGET exists already, skipping stage 'fai dirinstall'" ; eend 0 + log "$CHROOT_TARGET exists already, skipping stage 'fai dirinstall'" else mkdir -p "$CHROOT_TARGET" || bailout 5 "Problem with creating $CHROOT_TARGET for FAI" - fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" dirinstall "$CHROOT_TARGET" $FAI_ARGS + 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 | tee -a $LOGFILE umount $CHROOT_TARGET/proc 2>/dev/null || /bin/true umount $CHROOT_TARGET/sys 2>/dev/null || /bin/true - # notice: 'fai dirinstall' does not seem to exit appropriate -> - # we need better error handling - if [ -r "$CHROOT_TARGET"/etc/grml_cd ] ; then - echo " [*] Finished execution of stage 'fai dirinstall'" + [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_TARGET}/${MIRROR_DIRECTORY}" + + # notice: 'fai dirinstall' does not seem to exit appropriate, so: + ERROR='' + if [ -r "/var/log/fai/dirinstall/$HOSTNAME/software.log" ] ; then + grep 'dpkg: error processing' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=1 + fi + + if [ -r "/var/log/fai/dirinstall/$HOSTNAME/shell.log" ] ; then + grep 'FAILED with exit code' /var/log/fai/dirinstall/$HOSTNAME/shell.log >> $LOGFILE && ERROR=2 + fi + + if [ -n "$ERROR" ] ; then + eerror "There was an error during execution of stage 'fai dirinstall'" + echo " Check out /var/log/fai/dirinstall/$HOSTNAME/... for details. [exit ${ERROR}]" + log "There was an error during execution of stage 'fai dirinstall' [$(date)]" + eend 1 ; exit 1 else - echo " [!] There was an error during execution of stage 'fai dirinstall'" - exit 1 + einfo "Finished execution of stage 'fai dirinstall'" + log "Finished execution of stage 'fai dirinstall' [$(date)]" fi fi # }}} @@ -175,12 +280,12 @@ mkdir -p "$BUILD_TARGET" || bailout 6 "Problem with creating $BUILD_TARGET for s [ -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 + ewarn "$BUILD_TARGET/boot exists already, skipping stage 'boot/isolinux'" ; eend 0 + log "$BUILD_TARGET/boot exists already, skipping stage 'boot/isolinux'" else # booting stuff: mkdir -p "$BUILD_TARGET"/boot/isolinux - mkdir "$BUILD_TARGET"/GRML + [ -d "$BUILD_TARGET"/GRML ] || 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 @@ -196,6 +301,20 @@ if [ "$ARCH" = i386 ] ; then 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/ + + # adjust boot splash information: + ISO_DATE="$(date +%Y-%m-%d)" + VERSION="$(cut_string 5 "$VERSION")" ; VERSION="$(extend_string_end 5 "$VERSION")" + RELEASENAME="$(cut_string 30 "$RELEASENAME")" ; RELEASENAME="$(extend_string_end 30 "$RELEASENAME")" + + sed -i "s/%VERSION%/$VERSION/" "$BUILD_TARGET"/boot/isolinux/boot.msg + sed -i "s/%RELEASENAME%/$RELEASENAME/" "$BUILD_TARGET"/boot/isolinux/boot.msg + sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_TARGET"/boot/isolinux/boot.msg + + sed -i "s/%VERSION%/$VERSION/" "$BUILD_TARGET"/boot/isolinux/boot-beep.msg + sed -i "s/%RELEASENAME%/$RELEASENAME/" "$BUILD_TARGET"/boot/isolinux/boot-beep.msg + sed -i "s/%DATE%/$ISO_DATE/" "$BUILD_TARGET"/boot/isolinux/boot-beep.msg + # 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"/ @@ -203,58 +322,68 @@ if [ "$ARCH" = i386 ] ; then 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 + if [ -f "$BUILD_TARGET"/windows/putty.exe ] ; then + ewarn "$BUILD_TARGET/windows exists already, skipping stage 'WINDOWS_BINARIES'" ; eend 0 + log "$BUILD_TARGET/windows exists already, skipping stage 'WINDOWS_BINARIES'" else mkdir "$BUILD_TARGET"/windows ( cd "$BUILD_TARGET"/windows for file in pageant plink pscp psftp putty puttygen ; do - wget ${WINDOWS_BINARIES}/${file}.exe + wget -O ${file}.exe ${WINDOWS_BINARIES}/${file}.exe done ) fi - echo " [*] Finished execution of stage 'WINDOWS_BINARIES'" + einfo "Finished execution of stage 'WINDOWS_BINARIES'" ; eend 0 + log "Finished execution of stage 'WINDOWS_BINARIES' [$(date)]" fi - echo " [*] Finished execution of stage 'boot/isolinux'" + einfo "Finished execution of stage 'boot/isolinux'" ; eend 0 fi # amd64: elif [ "$ARCH" = amd64 ] ; then - echo 'Warning: gebi, it is your turn. :)'>&2 + ewarn 'Warning: gebi, it is your turn. :)'>&2 # ppc: elif [ "$ARCH" = powerpc ] ; then - echo 'Warning: formorer, it is your turn. :)'>&2 + ewarn 'Warning: formorer, it is your turn. :)'>&2 # unsuported: else - echo 'Warning: Unsupported ARCH, sorry. Want to support it? Contribute!'>&2 + eerror 'Error: Unsupported ARCH, sorry. Want to support it? Contribute!' ; eend 1 fi -if [ -d "$BUILD_TARGET"/live ] ; then - echo " [x] $BUILD_TARGET/live exists already, skipping stage 'squashfs'" +if [ -f "$BUILD_TARGET"/live/grml.squashfs ] ; then + ewarn "$BUILD_TARGET/live exists already, skipping stage 'squashfs'" ; eend 0 + log "$BUILD_TARGET/live exists already, skipping stage 'squashfs'" else mkdir "$BUILD_TARGET"/live mksquashfs $CHROOT_TARGET/* $BUILD_TARGET/live/grml.squashfs -noappend + einfo "Finished execution of stage 'squashfs'" ; eend 0 + log "Finished execution of stage 'squashfs' [$(date)]" 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'" +[ -n "$ISO_NAME" ] || ISO_NAME="grml_${VERSION}.iso" + +if [ -f "${ISO_TARGET}/${ISO_NAME}" ] ; then + ewarn "$ISO_TARGET exists already, skipping stage 'iso build'" ; eend 0 + log "$ISO_TARGET exists already, skipping 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 ' \ + mkisofs -V "grml $VERSION" -publisher 'grml-live | grml.org' \ -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 . + -o "${ISO_TARGET}/${ISO_NAME}" . ) - echo " [*] Finished execution of stage 'iso build'" + einfo "Finished execution of stage 'iso build'" ; eend 0 + log "Finished execution of stage 'iso build' [$(date)]" fi # }}} # finalize {{{ -echo " [*] Sucessfully finished execution of $PN" +SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]" +einfo "Sucessfully finished execution of $PN [running ${SECONDS} seconds]" ; eend 0 +log "Sucessfully finished execution of $PN [running ${SECONDS} seconds]" +log "------------------------------------------------------------------------------" bailout 0 # }}}