#!/bin/bash -e
# debconf script for raspbian-nspawn-64

# Source debconf library.
. /usr/share/debconf/confmodule

# If we are *not* already running a 64-bit kernel, and the user
# does not have arm_64bit set in /boot/config.txt, then prompt whether
# to set this (note we can't actually force a reboot though)
if [[ $(uname -m) == "aarch64" ]]; then
    # assume user knows what they are doing
    exit 0
fi
# running in 32-bit mode (or a QEMU user-mode chroot etc), but has
# the user already set arm_64bit in /boot/config.txt?
# note the below not a foolproof test, as it doesn't check the context
# filters ([pi4], [all] etc)
if ! grep -q '^[[:space:]]*arm_64bit=1' /boot/config.txt &>/dev/null; then
    # looks like this hasn't been set, so ask user if they would like us
    # to do this as part of the install (and cache the answer for use
    # during postinst)
    db_input critical raspbian-nspawn-64/arm_64bit || true
    db_go
fi

