#!/bin/sh

## Copyright (C) 2019 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## Want to disable serial console?
## Feel free to delete this configuration file.

## Forum discussion:
## https://forums.whonix.org/t/how-do-i-enter-the-whonix-shell-from-cli/7271
## https://forums.whonix.org/t/serial-console-in-virtualbox/8021
## https://forums.whonix.org/t/grub-serial-menu-in-virsh-console/8097

## Cope up with "set -o nounset".
: "${GRUB_CMDLINE_LINUX:=""}" || echo "$0: Setting default GRUB_CMDLINE_LINUX failed! Please report this bug!" >&2
: "${GRUB_TERMINAL:=""}" || echo "$0: Setting default GRUB_TERMINAL failed! Please report this bug!" >&2
: "${GRUB_SERIAL_COMMAND:=""}" || echo "$0: Setting default GRUB_SERIAL_COMMAND failed! Please report this bug!" >&2

if [ "$GRUB_TERMINAL" = "" ]; then
   GRUB_TERMINAL="console serial"
else
   GRUB_TERMINAL="$GRUB_TERMINAL console serial"
fi

## Quote https://www.virtualbox.org/wiki/Serial_redirect but not specific to VirtualBox:
##
##     console=ttyS0 console=tty0 ignore_loglevel
##
## The first parameter will ensure that all kernel output is redirected to the serial console. The second parameter will ensure that the kernel output is still logged to the guest text console. The third parameter enforces the guest Linux kernel to print all kernel messages to the console.

if [ "$GRUB_CMDLINE_LINUX" = "" ]; then
   GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"
else
   GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX console=tty0 console=ttyS0,115200n8"
fi

if [ "$GRUB_SERIAL_COMMAND" = "" ]; then
   GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
fi
