#
# Common bourne shell subroutines used by the Skolelinux install.
#

skolelinux_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" >> $skolelinux_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/skolelinux/config ; then
	print "info: $0: Loading config from /etc/skolelinux/config"
	. /etc/skolelinux/config
    else
	error "Unable to read from /etc/skolelinux/config."
	report_bug
    fi
}
