#!/bin/bash

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

check_package_manager_running() {
   if check_package_manager_running_helper; then
      if [ "$systemcheck_package_manager_waiting" = "1" ]; then
         $output_x ${output_opts[@]} --progressbaridx "$progressbaridx" --progressx "100"
      fi
      local MSG="<p>Check Package Manager Running Result: None running, ok.</p>"
      if [ "$verbose" -ge "1" ]; then
         $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
         $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"
      fi
      return 0
   fi

   if [ ! "$systemcheck_package_manager_waiting" = "1" ]; then
      systemcheck_package_manager_waiting="1"

      progressbaridx="$(cat "/proc/sys/kernel/random/uuid")"

      local MSG="$package_manager_waiting_msg_x"
      $output_cli ${output_opts[@]} --waitmessagecli --typecli "info" --message "$MSG" --done
      ## Start progress bar to show we are waiting.
      $output_x ${output_opts[@]} --progressbaridx "$progressbaridx" --progressbarx --parentpid "$$" --progressbartitlex "$TITLE_X" --message "$MSG" --done
   fi

   sleep "10" &
   wait "$!" || true
   check_package_manager_running
}
