diff options
-rwxr-xr-x | cleanoldrpm | 50 | ||||
-rwxr-xr-x | mkrepo | 17 |
2 files changed, 61 insertions, 6 deletions
diff --git a/cleanoldrpm b/cleanoldrpm new file mode 100755 index 0000000..17d659c --- /dev/null +++ b/cleanoldrpm @@ -0,0 +1,50 @@ +#!/usr/bin/php +<?php + +if (!extension_loaded("rpminfo")) die("rpminfo extension is missing\n"); + +define('MODE_PREVIEW', 1); +define('MODE_DELETE', 2); +$mode = 0; +$keep = 0; +$dest = false; +$multi = [ + 'php' => 3, + 'redis' => 1, + 'composer' => 1, +]; +if (isset($_SERVER['argv'][1])) { + $keep = (int)$_SERVER['argv'][1]; +} +if (!$keep) { + printf("\nusage %s number [ trash_path ]\n\n", $_SERVER['argv'][0]); + die("Number to keep is missing\n"); +} +if (isset($_SERVER['argv'][2])) { + $dest = $_SERVER['argv'][2]; + if (!is_dir($dest)) { + die("$dest is not a directory\n"); + } +} + +$rpms = []; +foreach (glob("*.rpm") as $name) { + $info = rpminfo($name); + $i = $info['Name']; + if (isset($multi[$i])) { + $i .= "/" . substr($info['Version'], 0, $multi[$i]); + } + $rpms[$i][$info['Version']] = $name; +} + +foreach($rpms as $rpm) { + if (count($rpm) > $keep) { + uksort($rpm, "rpmvercmp"); + $i = count($rpm) - $keep; + while ($i--) { + $name = array_shift($rpm); + echo "\t$name\n"; + if ($dest) rename($name, "$dest/$name"); + } + } +} @@ -8,16 +8,19 @@ then dis=enterprise ver=8 old=2 + dst=/data/rpms/old elif [ "$nom" = "SRPMS" ] then dis=fedora ver=33 old=8 + dst=/data/rpms/SRPMS.remi else dis=${nom%%/*} ver=${nom#$dis/} ver=${ver%%/*} old=2 + dst=/data/rpms/old fi if [ ${1:-check} != nocheck ]; then @@ -55,14 +58,16 @@ fi if [ ${2:-clean} != noclean ]; then echo "+ Nettoyage des anciens ($old)" + cleanoldrpm $old $dst + + # https://bugzilla.redhat.com/show_bug.cgi?id=1899852 - repomanage is broken, reports not existing packages # use old deprecated yum command see https://bugzilla.redhat.com/1537981 #dnf repomanage --old --keep=$old . | tee $TMP - repomanage --old --keep=$old . 2>/dev/null | tee $TMP - LST=$(cat $TMP) - - if [ -n "$LST" ] - then mv $LST /data/rpms/old/ - fi + #repomanage --old --keep=$old . --setopt=metadata_expire=1 2>/dev/null | tee $TMP + #LST=$(cat $TMP) + #if [ -n "$LST" ] + #then mv $LST /data/rpms/old/ + #fi fi cache=/home/rpmbuild/site/rpms/.createrepocache/$nom |