# vim: filetype=sh

generate_fstab()
{
    layout_dir="$1"

    echo "# <file system> <mount point>   <type>  <options>       <dump>  <pass>" > etc/fstab

    generate_mount_info "$layout_dir" | while read vol_dir mounttype uuid vol_mountpoint
    do
        echo "UUID=$uuid    $vol_mountpoint $mounttype    errors=remount-ro   0   1" >> etc/fstab
    done
}

generate_hosts_file()
{
    cat > /etc/hosts << EOF
127.0.0.1   localhost
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
}

resolv_conf_is_invalid()
{
    # note: we will generate a resolv.conf file if it is missing
    # or if it is a file but no 'nameserver' directive is found.
    # in more complex scenarios (e.g. it is a symlink), we consider
    # the setup is OK and/or the user knows what he is doing.
    if [ ! -e "/etc/resolv.conf" ]
    then
        echo 1; return
    elif [ -f "/etc/resolv.conf" ]
    then
        if ! grep -q "^nameserver" /etc/resolv.conf
        then
            echo 1; return
        fi
    fi
    echo 0  # file seems valid
}

generate_resolv_conf_file()
{
    # note: this generated file may be overriden later in the procedure
    # if debootstick has to install one missing package including a DNS
    # resolver (e.g. systemd). In any case this file is needed right
    # know for the package downloading to succeed.
    cat > /etc/resolv.conf << EOF
# cloudflare
nameserver 1.1.1.1
# google
nameserver 8.8.8.8
# opendns
nameserver 208.67.220.220
EOF
}
