#!/bin/bash

# First, we must get the date of what the last snapshot
# should be from zypper, and strip away the extra stuff,
checkup=$(sudo zypper refresh) #an easy way to run the refresh repositories without it being displayed.
checkup=$(zypper if MicroOS-release|grep Version)
checkup=${checkup#*: }
checkup=${checkup%-*}

# Then we must do the same for the date of the
# current snapshot of the system.
checkcurr=$(cat /etc/os-release|grep VERSION_ID)
checkcurr=${checkcurr#*=\"}
checkcurr=${checkcurr%\"}

# Now we must convert those dates to seconds since
# 1/1/1970, then take the difference and convert
# them to days
dateup=$(date +%s -d ${checkup})
datecurr=$(date +%s -d ${checkcurr})
let diff=(${dateup}-${datecurr})/86400

# Then we display the results.
[[ $diff -eq 1 ]] && diff="$diff day" || diff="$diff days" 
printf "The current system's update is: "
printf "%(%m-%d-%Y)T \n" ${datecurr}
printf "Zypper reports that the last update is: "
printf "%(%m-%d-%Y)T \n" ${dateup}
echo "Which is a total of ${diff} old."

exit


