#!/bin/bash

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

check_initializer() {
   local log_file start_file done_file skip_file todo_file fail_file
   log_file="/var/lib/initializer-dist/status-files/first_run_initializer.log"
   start_file="/var/lib/initializer-dist/status-files/first_run_initializer.start"
   done_file="/var/lib/initializer-dist/status-files/first_run_initializer.done"
   skip_file="/var/lib/initializer-dist/status-files/first_run_initializer.skip"
   todo_file="/var/lib/initializer-dist/status-files/first_run_initializer.todo"
   fail_file="/var/lib/initializer-dist/status-files/first_run_initializer.fail"

   if [ -f "$fail_file" ]; then
      local MSG="<p>Check Initializer Result: <b><code>$fail_file</code> exists. Your system could be unstable!</b> Please consider reporting any bugs inside: <code>$log_file</code>
(Be careful not to copy and paste personal information.)</p>"
      $output_x ${output_opts[@]} --messagex --typex "error" --message "$MSG"
      $output_cli ${output_opts[@]} --messagecli --typecli "error" --message "$MSG"
      EXIT_CODE="1"
      return 0
   fi

   if [ "$verbose" -ge "1" ]; then
      local MSG="<p>Check Initializer Result: <code>$fail_file</code> does not exist, ok.</p>"
      $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
      $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"
   fi
}
