+
+check_exit()
+{
+ if test -e $BUILD_ROOT/exit; then
+ echo "exit ..."
+ cleanup_and_exit 1
+ fi
+}
+
+is_emulator_arch()
+{
+ local arch
+ local qarch=":$BUILD_ARCH:"
+ for arch in $EMULATOR_ARCHS; do
+ if test "$qarch" != "${qarch/:$arch:/}" -a "$BUILD_HOST_ARCH" != "$arch"; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+check_use_emulator()
+{
+ is_emulator_arch || return
+
+ if [ -z "$VM_TYPE" ]; then
+ return 0
+ fi
+
+ # to run the qemu initialization in the XEN chroot, we need to
+ # register it with a static program or shell script
+ case "$BUILD_HOST_ARCH" in
+ i?86|x86_64)
+ if test -e $BUILD_DIR/initvm && \
+ test -e $BUILD_DIR/qemu-reg; then
+ return 0 # prefer initvm to handle registration
+ elif test -e /bin/bash-static \
+ -a -e /bin/mount-static \
+ -a -e /usr/sbin/qemu-binfmt-conf.sh; then
+ return 0 # as backup use /usr/sbin/qemu-binfmt.conf.sh
+ else
+ # XXX: error?
+ echo "Warning: cross compile not possible due to missing static binaries"
+ fi
+ ;;
+ esac
+ return 1
+}
+
+# usage:
+# progress_setup LIST
+# for I in $LIST; do
+# progress_step LIST
+# action $I
+# done
+
+# $1 name of a textual list
+progress_setup() {
+ eval "$1__ARRAY__=(\$$1)"
+ eval "$1__INDEX__=1"
+ eval "$1__LENGTH__=\${#$1__ARRAY__[@]}"
+}
+
+# $1 name of a textual list
+# $2 optional, printf format for 2 numeric arguments (current, total)
+progress_step() {
+ local IDX=$1__INDEX__
+ local LEN=$1__LENGTH__
+ printf "${2-[%d/%d] }" $(($IDX++)) ${!LEN}
+}