#
# Common bourne shell subroutines used by the Debian-Edu install.
#

debian_edu_error_flag_file=/tmp/debian-edu-install-failed

print() {
    # stdout is busy talking to debconf.  Print to stderr
    echo "$*" 1>&2
}

info() {
    if [ "$debug" != "true" ] ; then
	print "info: $*"
    fi
}

init_debconf() {
    if test "$debug" = "true"; then
	db_set() {
	    info "  db_set '$1' '$2'"
	}
	db_fset() {
	    info "  db_fset '$1' '$2' '$3'"
	}
	db_input() {
	    true
	}
	db_go() {
	    true
	}
	db_get() {
	    RET=""
	}
    else
        # Load db_*
	. /usr/share/debconf/confmodule
    fi
}

report_bug() {
    msg="$1"
    echo "  $msg" >> $debian_edu_error_flag_file
    print "$msg"
#    print "Continuing in 10 seconds."
#    sleep 10
}

error() {
    msg="$1"
    report_bug "error: $0: $msg"
}

load_config() {
    if test -r /etc/debian-edu/config ; then
	print "info: $0: Loading config from /etc/debian-edu/config"
	. /etc/debian-edu/config
    else
	error "Unable to read from /etc/debian-edu/config."
	report_bug
    fi
}

jump_to() {
    jump_num="$1"
    jump_label="$2"
    print "info: Jumping to $2 (exit code $1)"
    # Only present in base-config 2.x.
    if [ -e show-menu ]; then
        echo "$jump_label" > jump-to
        exit 0
    else
        exit "$jump_num"
    fi
}
