+# 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