#!/bin/bash
#
# RJP 27.6.2026 Simple update-cherker for PCLinuxOS and other systems which uses DNF package management
# Packages yad, xterm and dnf are needed

LIST=$(dnf upgrade --assumeno > /tmp/update-check.txt)
#
touch ~/.Xresources
echo ' ! Use a truetype font and size.
xterm*faceName: Monospace ' | grep -xFv -f $HOME/.Xresources >> $HOME/.Xresources
echo 'xterm*faceSize: 14 ' | grep -xFv -f $HOME/.Xresources >> $HOME/.Xresources
xrdb -merge ~/.Xresources

dnf upgrade --assumeno > /tmp/update-check.txt

112=$({                                   
echo '#!/bin/bash
LIST=$(dnf upgrade --assumeno > /tmp/update-check.txt)
export DISPLAY=:0.0
echo "$LIST" | yad --list --title "Search Results" --width=1000 --height=500 --text "INFORMATION" --column "AVAILABLE UPDATES" --button=OK:1
yad --text="Would you like to install updates?" --title="UPDATER"
if [ $? = 0 ];
then
xterm -hold -e su -c "dnf makecache --refresh && dnf update && dnf upgrade "
else 
exit 0
fi
'
} > /tmp/run-updates) 

chmod +x /tmp/run-updates

grep -o 'x86_64' /tmp/update-check.txt > /tmp/u2.txt

A=$(awk 'FNR <= 1' /tmp/u2.txt)
B=$(grep -o 'x86_64' /opt/UPDATE/b.txt)
if [ "$A" = "$B" ]
then
cd /tmp && ./run-updates
else
##echo "NO UPDATES AVAILABLE."
yad --width=400 --title=$"NO UPDATES AVAILABLE" --text-align=center --button=OK:1 --text=$"No updades available this moment."
fi
sleep 300
cd /tmp && rm u2.txt update-check.txt run-updates
