#!/bin/sh
# RJP 15.8.2025 simple update reminder for FreeBSD
# Packages yad and pkg are needed
# This checks when you have run pkg last time
# This do not check freebsd-update, so modify the script if you want
# freebsd-update is located in /var/db/freebsd-update
# Add the script to the startup applications
#
if ! nc -zw1 google.com 443; then   exit;  fi
# 
(stat -f "%m" /var/cache/pkg) > /tmp/lastupdate0
#
date +%s > /tmp/today
# last update + 3 days in seconds is 259200 (60 x 60 x 24 x 3)
awk "BEGIN {print ($(cat /tmp/lastupdate0) + 259200)}" > /tmp/lastupdate

awk "BEGIN {print ($(cat /tmp/today) - $(cat /tmp/lastupdate0))}" > /tmp/erotus
awk "BEGIN {print ($(cat /tmp/erotus) / 86400)}" > /tmp/lastday0
awk -v FS='.' '{print $1}' /tmp/lastday0 > /tmp/lastday

if [ "$(cat /tmp/lastupdate)" -lt "$(cat /tmp/today)" ]
then
yad --width=400 --text-align=center --center --title="You should check updates:" --text="
You have not run pkg update for $(cat /tmp/lastday) days
       
       Update your system  "
else
exit 0
fi
sleep 2
cd /tmp && rm erotus lastday lastday0 lastupdate lastupdate0 today
