#!/usr/bin/env bash

# Commands provided by Bash_AVpres.
#
# Copyright (c) 2003-2026 by Reto Kromer <https://reto.ch/>
#
# This Bash script is released under a 3-Clause BSD License and is provided
# "as is" without warranty or support of any kind.


# initialise constants
VERSION='2026-01-02'
SCRIPT_NAME="$(basename "$0")"
CONFIG_PATH="${HOME}/.config/AVpres/Bash_AVpres"
BLUE='\033[1;34m'
NC='\033[0m'

# initialise variable
unset bash_version


# get date-and-time stamp
date_time() {
  TZ='UTC' date +'[%F %T %Z]'
}


# start log file
[[ -d '/tmp/AVpres' ]] || mkdir -p '/tmp/AVpres'
LOG_FILE="$(mktemp "/tmp/AVpres/${SCRIPT_NAME}.XXXXXXXXXX")"
echo "$(date_time) ${SCRIPT_NAME} ${VERSION}" > "${LOG_FILE}"
echo "$(date_time) $0 $*" >> "${LOG_FILE}"
echo "$(date_time) START" >> "${LOG_FILE}"

# check that Bash 3.2 or later is running
bash_version="$(bash -c 'echo ${BASH_VERSION}')"
echo "$(date_time) running bash version = '${bash_version}'" >> "${LOG_FILE}"
if ! printf '%s\n%s\n' "${bash_version}" "3.2" | sort -rVC; then
  echo -e "${BLUE}Warning: This 'bash' binary is very old."
  echo -e "We strongly recommend that you use the current version 5.3.${NC}"
fi

# print installed commands and manual pages
cat << EOF

Bash AVpres ${VERSION} provides the following commands:

  bash_avpres         make_h264           undo_bagit
  check_ltfs          make_manifest       verify_bagit
  display_config      make_prores         verify_ffv1
  ffmpeg_head         metadata_csv        verify_framemd5
  make_bagit          missing_files       verify_manifest
  make_ffv1           name_hash
  make_framemd5       nano_config

EOF

# end log file
echo "$(date_time) END" >> "${LOG_FILE}"
