#!/bin/bash

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

if [ -f /usr/libexec/helper-scripts/pre.bsh ]; then
   source /usr/libexec/helper-scripts/pre.bsh
fi
source /usr/libexec/helper-scripts/user_create.bsh
source /usr/libexec/helper-scripts/accountctl.sh

set -e

true "
#####################################################################
## INFO: BEGIN: $DPKG_MAINTSCRIPT_PACKAGE $DPKG_MAINTSCRIPT_NAME $@
#####################################################################
"

sysmaint_user_creation_and_groups_setup() {
   if [ -f "/var/lib/user-sysmaint-split/do_once/${FUNCNAME}_version_1" ]; then
      return 0
   fi
   mkdir --parents "/var/lib/user-sysmaint-split/do_once"

   USER_CREATE_USERNAME='sysmaint'
   add_linux_user_account
   password_empty_for_user_account
   USER_CREATE_GROUP_ADD_LIST=( 'sudo' 'ssh' 'console' )
   if [ -f /usr/share/qubes/marker-vm ]; then
      USER_CREATE_GROUP_ADD_LIST+=( 'qubes' )
   fi
   add_groups_to_linux_user_account
   linux_user_account_shell_to_zsh
   unlock_pass sysmaint

   touch "/var/lib/user-sysmaint-split/do_once/${FUNCNAME}_version_1"
}

## User configuration
sysmaint_user_creation_and_groups_setup

true "INFO: debhelper beginning here."

#DEBHELPER#

true "INFO: Done with debhelper."

true "
#####################################################################
## INFO: END  : $DPKG_MAINTSCRIPT_PACKAGE $DPKG_MAINTSCRIPT_NAME $@
#####################################################################
"

## Explicitly "exit 0", so eventually trapped errors can be ignored.
exit 0
