Move echo's to debug setting + move template initiator

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2022-05-26 20:05:21 +02:00
parent ec9366e51c
commit 425bd3961a
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57

View File

@ -14,6 +14,8 @@ weekmode=7
#for daily cron: #for daily cron:
#weekmode=0 #weekmode=0
debug=false
admins="system" admins="system"
declare -r aged=21 # minimum days after expiration before admins are emailed, set to 0 for "always" declare -r aged=21 # minimum days after expiration before admins are emailed, set to 0 for "always"
@ -58,7 +60,9 @@ secondsperday=86400 # set this to 1 for no division
#secondsperday=1 #secondsperday=1
today=$(($($dateprog $useUTC $epochseconds $dateformat)/$secondsperday)) today=$(($($dateprog $useUTC $epochseconds $dateformat)/$secondsperday))
echo "today: $today" if [ "$debug" = true ]; then
echo "today: $today"
fi
oIFS=$IFS oIFS=$IFS
# ### END SETUP ### # ### END SETUP ###
@ -93,44 +97,60 @@ users=$($awkprog -F: -v uidfield=$uidfield \
for user in $users; for user in $users;
do do
echo "user: $user" if [ "$debug" = true ]; then
echo "user: $user"
fi
IFS=":" IFS=":"
usershadow=$($grepprog ^$user $shadowfile) usershadow=$($grepprog ^$user $shadowfile)
echo "usershadow 1: $usershadow" if [ "$debug" = true ]; then
echo "usershadow 1: $usershadow"
fi
# make an array out of it # make an array out of it
usershadow=($usershadow) usershadow=($usershadow)
echo "usershadow 2: $usershadow" if [ "$debug" = true ]; then
echo "usershadow 2: $usershadow"
fi
IFS=$oIFS IFS=$oIFS
mustchange=${usershadow[$must]} mustchange=${usershadow[$must]}
echo "mustchange: $mustchange" if [ "$debug" = true ]; then
echo "mustchange: $mustchange"
fi
disabledate=${usershadow[$disable]:-$doesntmust} disabledate=${usershadow[$disable]:-$doesntmust}
echo "disabledate: $disabledate" if [ "$debug" = true ]; then
echo "disabledate: $disabledate"
fi
# skip users that aren't expiring or that are disabled # skip users that aren't expiring or that are disabled
if [[ $mustchange -ge $doesntmust || $disabledate -le $today ]] ; then continue; fi; if [[ $mustchange -ge $doesntmust || $disabledate -le $today ]] ; then continue; fi;
lastchange=${usershadow[$last]} lastchange=${usershadow[$last]}
echo "lastchange: $lastchange" if [ "$debug" = true ]; then
echo "lastchange: $lastchange"
fi
warndays=${usershadow[$warn]:-$warndefault} warndays=${usershadow[$warn]:-$warndefault}
echo "warndays: $warndays" if [ "$debug" = true ]; then
echo "warndays: $warndays"
fi
expdate=$(("$lastchange" + "$mustchange")) expdate=$(("$lastchange" + "$mustchange"))
echo "expdate: $expdate" if [ "$debug" = true ]; then
echo "expdate: $expdate"
fi
threshhold=$(($today + $warndays + $weekmode)) threshhold=$(($today + $warndays + $weekmode))
echo "threshhold: $treshhold" if [ "$debug" = true ]; then
echo "threshhold: $treshhold"
fi
if [[ $expdate -lt $threshhold ]]; if [[ $expdate -lt $threshhold ]];
gentemplate_userbody "$(($expdate - $today))"
then then
gentemplate_userbody "$(($expdate - $today))"
if [[ $expdate -ge $today ]]; if [[ $expdate -ge $today ]];
then then
subject=$(eval "echo \"$usersubjecttemplate\"") subject=$(eval "echo \"$usersubjecttemplate\"")
@ -145,6 +165,5 @@ do
fi fi
fi fi
fi fi
done done
unset debug