#!/bin/bash

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

## https://forums.whonix.org/t/one-time-popup-notification-of-whonix-15-deprecation-once-whonix-16-was-released/11720
## https://forums.whonix.org/t/do-not-show-this-message-again-generic-one-time-popup/8066

#set -x
set -e

## sets: PROJECT_NAME
## sets: PROJECT_HOMEPAGE
## sets: derivative_major_release_version
source /usr/libexec/helper-scripts/origins-parser

source /usr/libexec/helper-scripts/log_run_die.sh

still_supported_version=18
status_file=~"/.config/legacy-dist/deprecation-notice/dismissed-version-${still_supported_version}"

if [ "$1" = "cli" ]; then
  cli=true
elif [ "$1" = "gui" ]; then
  gui=true
else
  cli=true
  gui=true
fi

if [ "$derivative_major_release_version" = "" ]; then
  printf '%s\n' "INFO: version file does not exist or is empty. This is expected during initial installation." >&2
  exit 1
fi

if [ "$derivative_major_release_version" -ge "${still_supported_version}" ]; then
  true "INFO: Not yet deprecated, ok."
  exit 0
fi

if test -e /usr/share/qubes/marker-vm; then
  true "INFO: Not yet deprecated, ok.

Kicksecure ${still_supported_version} and Whonix ${still_supported_version} will remain supported until 1 month after Qubes R4.3 stable has been released.

See also:
decide availability of Kicksecure, and Whonix 18 (Debian trixie based) on Qubes R4.2 versus R4.3 #10219
https://github.com/QubesOS/qubes-issues/issues/10219"
  exit 0
fi

title="DEPRECATION NOTICE"

text="<p>Support Status of this Major Version: <b>Deprecated!</b>
<br />
<br />Major release version <u><code>$derivative_major_release_version</code></u> has been deprecated.
<br />
<br />No more security support will be provided.
<br />
<br /><b>A Release Upgrade is strongly recommended!</u></b>
<br />
<br />${PROJECT_HOMEPAGE}/wiki/Stay_Tuned
<br />${PROJECT_HOMEPAGE}/wiki/Release_Upgrade
</p>"

stripped_text="$(strip-markup -- "$text")"

if [ "$cli" = "true" ]; then
  log warn "$stripped_text"
elif [ "$gui" = "true" ]; then
  /usr/libexec/msgcollector/one-time-popup "$status_file" "$title" "$text"
fi
