#!/bin/sh -e

##########################################################################
#   Synopsis:
#       auto-last-update
#
#   Description:
#       Prints the time in hours since the last successful run of
#       auto-update-system.
#
#   Files:
#       $(auto-localbase)/etc/auto-admin/last-update
#
#   See also:
#       auto-update-system(1)
#       
#   History:
#   Date        Name        Modification
#   2021-12-15  J Bacon     Begin
##########################################################################

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

