# vim: set ft=sh:

run_hook() {
    if [[ -n "${ip}" && -n "${parabolaiso_nfs_srv}" ]]; then

        parabolaiso_nfs_srv=$(eval echo ${parabolaiso_nfs_srv})
        [[ -n "${parabolaiso_nfs_opt}" ]] && parabolaiso_nfs_opt="-o ${parabolaiso_nfs_opt}"

        mount_handler="parabolaiso_nfs_mount_handler"
    fi
}

parabolaiso_nfs_mount_handler() {
    newroot="${1}"
    mkdir -p "/run/parabolaiso/bootmnt"
    msg ":: Mounting '${parabolaiso_nfs_srv}'"
    # Do not put "${parabolaiso_nfs_opt}" nfsmount fails!
    if ! nfsmount ${parabolaiso_nfs_opt} "${parabolaiso_nfs_srv}" "/run/parabolaiso/bootmnt"; then
        echo "ERROR: Mounting '${parabolaiso_nfs_srv}'"
        echo "   Falling back to interactive prompt"
        echo "   You can try to fix the problem manually, log out when you are finished"
        launch_interactive_shell
    fi

    if [[ "${copytoram}" != "n" ]]; then
        copytoram="y"
    fi

    parabolaiso_mount_handler ${newroot}
}
