#!/bin/bash

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

get_build_version_file() {
   if [ -f "/usr/share/whonix/build_timestamp" ]; then
      ## Originally, this was a Whonix specific script.
      ## Prefer the eventually existing older version.
      build_version_file="/usr/share/whonix/build_timestamp"
   elif [ -f "/var/lib/anon-dist/build_version" ]; then
      ## Legacy.
      build_version_file="/var/lib/anon-dist/build_version"
   elif [ -f "/var/lib/dist-base-files/build_version" ]; then
      ## Legacy.
      build_version_file="/var/lib/dist-base-files/build_version"
   fi
}

get_build_timestamp() {
   BUILD_UNIXTIME="$(date -r "$build_version_file" +%s)"
   BUILD_TIME="$(date -r "$build_version_file")"
}

get_build_version() {
   BUILD_VERSION="$(cat "$build_version_file")"
}

get_build_version_file
get_build_timestamp
get_build_version

echo "BUILD_VERSION='$BUILD_VERSION'"
echo "BUILD_UNIXTIME='$BUILD_UNIXTIME'"
echo "BUILD_TIME='$BUILD_TIME'"
