#!/bin/bash

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

show_versions() {
   if [ ! "$verbose" -ge "1" ]; then
      return 0
   fi

   local link_raw
   link_raw="${PROJECT_HOMEPAGE}/wiki/Systemcheck#Build_Version"

   local link
   link="<a href=$link_raw>build version</a>"

   local MSG="<p>$PROJECT_NAME $link: <code>$derivative_build_version</code></p>"
   $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
   $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "\
$MSG
$link_raw"

   local temp
   temp="$(/usr/bin/sanitize-string -- nolimit "$derivative_deb_package_version")"

   local MSG="<p>$derivative_deb_package_name: <code>$temp</code></p>"
   $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
   $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"

   local MSG="<p>derivative_major_release_version /etc/${PROJECT_NAME_LOWERCASE}_version: <code>$derivative_major_release_version</code></p>" || true
   $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
   $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"
}

## systemcheck --gui --cli --function show_deprecation_notice
show_deprecation_notice() {
   ## https://forums.whonix.org/t/one-time-popup-notification-of-whonix-15-deprecation-once-whonix-16-was-released/11720
   [ -n "$derivative_deprecated_major_release_versions_list" ] || derivative_deprecated_major_release_versions_list="14"

   local deprecated_version
   for deprecated_version in $derivative_deprecated_major_release_versions_list ; do
      if [ "$derivative_major_release_version" = "$deprecated_version" ]; then
         deprecated_derivative=true
      fi
   done

   ## Any package could drop a snippet /etc/systemcheck.d/40_deprecation.conf with content:
   ## deprecated_derivative=true

   ## Testing.
   #deprecated_derivative=true

   if [ ! "$deprecated_derivative" = "true" ]; then
      local MSG="<p>$PROJECT_NAME Support Status of this Major Version: 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

   local MSG="<p>$PROJECT_NAME Support Status of this Major Version: <b>Deprecated!</b>
<br />
<br />$PROJECT_NAME major release version <u><code>$derivative_major_release_version</code></u> has been deprecated!
<br />
<br />No more security and user support will be provided.
<br />
<br /><b>A <u><a href=${PROJECT_HOMEPAGE}/wiki/Release_Upgrade>Release Upgrade</a> is strongly recommended!</u></b>
<br />
<br /><u>Further Recommendations</u>:
<br />
<br />Stay tuned! Follow $PROJECT_NAME News!
<br />
<br /><a href=${PROJECT_HOMEPAGE}/wiki/Stay_Tuned>${PROJECT_HOMEPAGE}/wiki/Stay_Tuned</a>
<br />
<br />It is <a href=${PROJECT_HOMEPAGE}/wiki/Stay_Tuned#Reason>absolutely crucial</a> to subscribe to and read the latest $PROJECT_NAME news category 'important-news' to stay in touch with ongoing developments. This way users benefit from notifications concerning important security advisories, potential upgrade issues and improved releases which address identified issues, like those affecting the updater or other core elements.</p>"

   $output_x ${output_opts[@]} --messagex --typex "warning" --message "$MSG"
   $output_cli ${output_opts[@]} --messagecli --typecli "warning" --message "$MSG"
   EXIT_CODE="1"
}
