#!/bin/bash

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

check_user_sysmaint_split() {
   check_user_sysmaint_split_package
   check_user_sysmaint_split_boot_mode
}

check_user_sysmaint_split_package() {
   local link_cli link_gui

   link_cli="https://www.kicksecure.com/wiki/sysmaint"
   link_gui="<a href=\"$link_cli\">user-sysmaint-split</a>"

   local MSG

   if ! leaprun user-sysmaint-split-check &>/dev/null ; then
      MSG="<p>$link_gui: <font color=\"orange\">Absent</font></p>"
      $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
      MSG="\
user-sysmaint-split-check installation check result: ${yellow}Absent${nocolor}
$link_cli"
      $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"
      return 0
   fi

   MSG="<p>$link_gui: <font color=\"green\">Enabled</font></p>"
   $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
   MSG="\
user-sysmaint-split-check installation check result: ${green}Enabled${nocolor}
$link_cli"
   $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"
   return 0
}

check_user_sysmaint_split_boot_mode() {
   if ! [ "$booted_in_sysmaint_session" = 'true' ]; then
      MSG="<p>user-sysmaint-split session detection result: USER Session.</p>"
   else
      MSG="<p>user-sysmaint-split session detection result: SYSMAINT Session.</p>"
   fi

   $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
   $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"
}
