#!/bin/sh

# THIS SCRIPT OVERWRITES PUAVO-CONF VARIABLES

set -eu

default_target='graphical.target'

is_netboot_exception() {
  # Laptops and wirelessaccesspoints that have been booted from NBD
  # should go to the admin menu.  It provides tools to update/configure
  # the system.
  if [ -e /run/puavo/nbd-server ]; then
    # XXX get rid of hosttype handling
    puavo_hosttype=$(puavo-conf puavo.hosttype)
    case "$puavo_hosttype" in
      laptop|wirelessaccesspoint)
        return 0
        ;;
    esac
  fi

  return 1
}

dm=$(puavo-conf puavo.xsessions.display_manager)

case "$dm" in
  gdm|lightdm)
    if is_netboot_exception; then
      puavo-conf puavo.xsessions.display_manager puavo-darkdm
      default_target='multi-user.target'
    fi
    ;;
  *)
    default_target='multi-user.target'
    ;;
esac

systemctl set-default "$default_target"
