presenting the Rawhide Downgrade to past date script

The this script gets the latest updates via dnf log files and reversed the system back to a given date in time, that is still in the logfile.

Presenting the Rawhide Downgrade to past date script

It’s far from perfect, but tries it’s best.  You need to install koji package first:  „dnf install koji

Most likely outcome: some packages will be missing, because koji can’t find them and some will be double present, with different versions and you end up in a collision. Remove the higher version files manually and do „dnf downgrade ./*rpm

Usage: scriptname {timestamp}

#!/bin/bash

grep "Upgraded:" /var/log/dnf.rpm.log | sort -r > /tmp/liste

mkdir rpmdownload
cd rpmdownload

if [ "" == "$1" ]; then

	echo "Keine Zeit angegeben.. benutze 4.2.2021"
	since=$(date --date="2021-02-04T00:00:00+0100" "+%s")

else 
	since=$(date --date="$1" "+%s")

fi

packs=""

declare -A old = ()

IFS=$'\n'
for line in $(cat /tmp/liste)
do 

	date=$(echo $line|sed -e "s/ .*//g")
	pkg=$(echo $line|sed -e "s/^.*: //g")
	
	time=$(date --date="$date" "+%s")

	if [ $time -gt $since ]; then 
	
		echo "$date => OK => $pkg"
		
		koji download-build --rpm $pkg
		basename=$(rpm -q --queryformat="%{Name}" ./$pgk)

		if [ "${old[$basename]}" != "" ]; then
			echo "found old entry ${old[$basename]}";
			rm -f ${old[$basename]}
		fi 

		$old[$basename]="$pkg"
		packs="$packs $pkg"
		
	else 
	
		echo "$date => IGNORE => $pkg"
	fi
	
done

if [ "$packs" != "" ]; then

	dnf -y downgrade ./*rpm
	
fi 

When is it usefull?

If something, you don’t know of, broke the system by Updates and you need to undo tons of downgrades. Happend to pinephones on the 8th of February 2021.