#!/bin/sh -e

##########################################################################
#   Title:
#       Optional, defaults to the name of the script sans extention
#
#   Section:
#       8
#
#   Synopsis:
#       auto-last-update
#       
#   Description:
#       Prints the time in hours since the last successful run of
#       auto-update-system.
#       
#   Arguments:
#       
#   Returns:
#
#   Examples:
#
#   Files:
#       $(auto-localbase)/etc/auto-admin/last-update
#
#   Environment:
#
#   See also:
#       auto-update-system(1)
#       
#   History:
#   Date        Name        Modification
#   2021-12-15  J Bacon     Begin
#   2024-11-12  Jason Bacon Add man page template and usage
##########################################################################

usage()
{
    printf "Usage: $0\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 0 ]; then
    usage
fi

current_time=$(date '+%s')
current_time=$((current_time / 3600))
sys_update_file=$(auto-localbase)/etc/auto-admin/last-system-update
if [ -e $sys_update_file ]; then
    last_update=$(cat $sys_update_file)
    printf "$((current_time - last_update))\n"
else
    printf "unknown\n"
fi
