#!/bin/bash

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

set -e

title="Manual Clock Randomization"

date_start="$(date)"

if user_input=$(yad \
   --entry \
   --title="$title" \
   --text="Please enter the time (in UTC!) in the following format.

Example:
$date_start" \
   --entry-text "$date_start")
  then \
     true "zentry entry ok."
else
   type="info"
   msg="<p>Ok, aborted.</p>"
   /usr/libexec/msgcollector/msgdispatcher_dispatch_x "$type" "$title" "$msg" "$icon"
   exit 3
fi

if echo "$user_input" | sudo --non-interactive /usr/bin/clock-random-manual-cli ; then
   date_end="$(date)"
   type="info"
   msg="<p>Success, date set from (user input):
<br />$date_start
<br />to (randomized):
<br />$date_end.</p>"
   /usr/libexec/msgcollector/msgdispatcher_dispatch_x "$type" "$title" "$msg" "$icon"
   exit 0
else
   type="error"
   msg="<p>ERROR!
<br />Please report this bug!
<br />
<br />Please open a console and use:
<br /><blockquote><code>sudo /usr/bin/clock-random-manual-cli</code></blockquote></p>"
   /usr/libexec/msgcollector/msgdispatcher_dispatch_x "$type" "$title" "$msg" "$icon"
   exit 1
fi
