#!/bin/sh -e

##########################################################################
#   Script description:
#       Create a pw age file
#       
#   History:
#   Date        Name        Modification
#   2019-06-18  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0 user-name max-days\n"
    exit 1
}


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

if [ $# != 2 ]; then
    usage
fi
user_name=$1
days=$2

LOCALBASE=$(cluster-localbase)

pw_age_file="$LOCALBASE/etc/spcm/pw-age/$user_name"
if [ ! -e $pw_age_file ]; then
    now=$(( $(date +%s) / 3600 / 24 ))
    printf "%s %s\n" $days $now > $pw_age_file
    group=$(id -g $user_name)
    chown root:$group $pw_age_file
    chmod 640 $pw_age_file
    printf "Created $pw_age_file:\n"
    ls -l $pw_age_file
else
    printf "$pw_age_file already exists.  Aborting...\n"
fi
