Log to /var/log/grml-live.log by default and support $ZERO_LOGFILE
[grml-live.git] / grml-live
index 9ce2284..db8fd63 100755 (executable)
--- a/grml-live
+++ b/grml-live
@@ -4,7 +4,7 @@
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2 or any later version.
-# Latest change: Wed Oct 24 10:11:02 CEST 2007 [mika]
+# Latest change: Sun Oct 28 14:43:27 CET 2007 [mika]
 ################################################################################
 
 # read configuration files, set some misc variables {{{
@@ -71,11 +71,16 @@ trap bailout 1 2 3 15
 [ -n "$RELEASENAME" ] || RELEASENAME="grml-live rocks"
 [ -n "$GRML_NAME" ] || GRML_NAME='grml'
 
-[ -d /var/log/fai/dirinstall/"${HOSTNAME}" ] || mkdir -p /var/log/fai/dirinstall/${HOSTNAME}
-if [ -d /var/log/fai/dirinstall/"${HOSTNAME}" ] ; then
-   LOGFILE=/var/log/fai/dirinstall/${HOSTNAME}/grml-live.log
-else
-   LOGFILE="$LOGDIR/grml-live.log"
+# logfile:
+if [ -z "$LOGFILE" ] ; then
+   LOGFILE=/var/log/grml-live.log
+fi
+touch $LOGFILE
+chown root:adm $LOGFILE
+chmod 640 $LOGFILE
+# clean/zero logfile:
+if [ -n "$ZERO_LOGFILE" ] ; then
+   echo -n > $LOGFILE
 fi
 
 NFSROOT_CONF=/etc/grml/fai/make-fai-nfsroot.conf
@@ -184,9 +189,6 @@ while getopts "a:c:g:i:o:r:s:t:v:FhV" opt; do
   esac
 done
 shift $(($OPTIND - 1))  # set ARGV to the first not parsed commandline parameter
-
-echo "Executing grml-live $GRML_LIVE_VERSION using the commandline:" >> $LOGFILE
-echo "$(basename $0) $@" >> $LOGFILE
 # }}}
 
 # some misc checks before executing FAI {{{
@@ -214,6 +216,7 @@ if [ -z "$FORCE" ] ; then
    [ -n "$BOOT_METHOD" ]   && echo "  Boot method:       $BOOT_METHOD"
    [ -n "$TEMPLATE_DIRECTORY" ] && echo "  Template files:    $TEMPLATE_DIRECTORY"
    [ -n "$FAI_ARGS" ]      && echo "  additional arguments for FAI: $FAI_ARGS"
+   [ -n "$LOGFILE" ]       && echo "  Logging to file:   $LOGFILE"
    [ -n "$VERBOSE" ]       && echo "  Using VERBOSE mode."
    echo
    echo -n "Is this ok for you? [y/N] "
@@ -222,13 +225,14 @@ if [ -z "$FORCE" ] ; then
       bailout 1 "Exiting as requested."
    fi
    echo
-
 fi
 
 start_seconds=$(cut -d . -f 1 /proc/uptime)
 log "------------------------------------------------------------------------------"
-log "Starting grml-live run [$(date)]"
-log "Executed command line: $0 $*"
+log "Starting grml-live [${GRML_LIVE_VERSION}] run [$(date)]"
+log "Executed command line: $0 $@"
+
+einfo "Logging actions to logfile $LOGFILE"
 # }}}
 
 # on-the-fly configuration {{{
@@ -257,6 +261,15 @@ if [ -n "$SUITE" ] ; then
    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
+   # notice: activate grml-live pool only if we are building against unstable:
+   if grep -qe unstable -qe sid /etc/grml/fai/apt/sources.list ; then
+      grep -q 'grml-live.*main' /etc/grml/fai/apt/sources.list || \
+      grep grml-stable /etc/grml/fai/apt/sources.list | \
+           sed 's/grml-stable/grml-live/' >> /etc/grml/fai/apt/sources.list
+   else
+      grep -q 'grml-live.*main' /etc/grml/fai/apt/sources.list && \
+      sed -i 's/.*grml-live.*/# removed grml-live repository/' /etc/grml/fai/apt/sources.list
+   fi
 
    sed -i "s|FAI_DEBOOTSTRAP=\"[a-z]* |FAI_DEBOOTSTRAP=\"$SUITE |" $LIVE_CONF
    sed -i "s|FAI_DEBOOTSTRAP=\"[a-z]* |FAI_DEBOOTSTRAP=\"$SUITE |" $NFSROOT_CONF
@@ -292,6 +305,7 @@ else
    ERROR=''
    if [ -r "/var/log/fai/dirinstall/$HOSTNAME/software.log" ] ; then
       # 1 errors during executing of commands
+      # Unable to write mmap - msync (28 No space left on device)
       grep 'dpkg: error processing' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=1
       grep 'E: Method http has died unexpectedly!' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=2
       grep 'ERROR: chroot' /var/log/fai/dirinstall/$HOSTNAME/software.log >> $LOGFILE && ERROR=3