read_file_with_variant() {
    base=$1
    if [ "$VARIANT" ] && [ -e "$base-$VARIANT" ]; then
        source "$base-$VARIANT"
    else
        source $base
    fi
}

read_config() {
    if [ -e ./config ]; then
        read_file_with_variant ./config
    elif [ -e ../config ]; then
        read_file_with_variant ../config
    else
        echo "No config file found"
        exit 1
    fi
}

read_common() {
    read_file_with_variant /usr/lib/scibian/scibian-cd/common
}

_debian_version_codename_mapping() {
    cat << EOF
1.1:buzz
1.2:rex
1.3:bo
2.0:hamm
2.1:slink
2.2:potato
3.0:woody
3.1:sarge
4.0:etch
5.0:lenny
6.0:squeeze
7:wheezy
8:jessie
9:stretch
10:buster
11:bullseye
12:bookworm
13:trixie
14:forky
EOF
}

debian_version_to_codename() {
    v="$1"
    _debian_version_codename_mapping | awk -F: "{ if (\$1 == $v) print \$2 }"
}

debian_codename_to_version() {
    n="$1"
    _debian_version_codename_mapping | awk -F: "{ if (\$2 == \"$n\") print \$1 }"
}
