#!/bin/zsh
# Filename: grml-live
-# Purpose:
+# Purpose: build script for creating grml live-cd
# 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.
-# Latest change: Thu Feb 08 21:06:07 CET 2007
+# Latest change: Tue Feb 13 00:16:11 CET 2007
################################################################################
-echo TODO
+LANG=C ; LC_ALL=C
+set -e # fail on any error
+
+# functions
+FUNCTIONSFILE='functions.sh' # TODO: fix location
+for file in $FUNCTIONSFILE /etc/grml/lsb-functions /etc/grml/script-functions ; do
+ [ -r "$file" ] && source "$file" || { print "Reading $file failed. Fatal error, exiting." ; exit 1 }
+done
+
+# Clean exit
+trap bailout 1 2 3 15
+
+# We need root permissions to execute all the chroot stuff
+check4root || bailout 1
+
+# default variables
+[ -n "$DEBOOTSTRAP" ] || DEBOOTSTRAP='debootstrap'
+[ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)"
+[ -n "$RELEASE" ] || RELEASE='sid'
+[ -n "$MIRROR" ] || MIRROR='ftp://ftp.tugraz.at/mirror/debian'
+[ -n "$TARGET" ] || TARGET="$(pwd)/grml-live/chroot/"
+
+# cmdline parsing, allow overwriting of variables
+while true ; do
+ case "${1}" in
+ (-c|--config) CONFIG="${2}"
+ shift 2 ;;
+ (-r|--root) TARGET="${2}"
+ shift 2 ;;
+ (-h|--hook) HOOK="${2}"
+ shift 2 ;;
+ (-v|--version) usage
+ exit 1 ;;
+ (--) shift
+ break ;;
+ (*) break ;;
+ esac
+done
+
+# configuration file
+if [ -n "$CONFIG" ] ; then
+ [ -r "$CONFIG" ] || bailout 1 "Sorry, configuration file $CONFIG could not be read. Fatal error, exiting"
+ debug "sourcing $CONFIG"
+ source "$CONFIG"
+else
+ source ../config/grml-live.conf # TODO: fix location
+fi
+
+# make sure we have some variables, directories,... available before main execution
+[ -d "$TARGET" ] || mkdir "$TARGET"
+[ -n "$ARCH" ] && ARCH="$DEB_HOST_ARCH" || bailout 1 "\$ARCH not set, exiting."
+
+# TODO: fix location
+source 01_bootstrap.sh
+source 02_chroot.sh
+
+if [ -n "$HOOK" ] ; then
+ debug "executing given hook $HOOK"
+ $HOOK
+ exit 0
+fi
+
+## main execution
+
+# 01_bootstrap.sh
+bootstrap
+
+# 02_chroot.sh
+patch_chroot apply
+chroot_live_prepare
+chroot_live_execute
+chroot_shell
+patch_chroot deapply
## END OF FILE #################################################################
+# vim: ai tw=80 ft=zsh expandtab