scripts
/
upgrade_status
/
1 contributor
#!/usr/bin/awk -f
function list_pkgs (type, label, test) {
count = 0
for (p in pkg)
if (pkg[p][type]) {
count++
}
if (count) {
if (label) print count " paquets " label
n = asorti(pkg, pkg_sorted)
for (i = 1; i <= n; i++) {
p = pkg_sorted[i]
pkg_ok = 0
if (test) {
if (pkg[p][type] && pkg[p][test])
pkg_ok = 1
}
else {
if (pkg[p][type])
pkg_ok = 1
}
if (pkg_ok) {
if (label) print " -> " p
delete pkg[p]
}
}
}
}
function show_help_and_exit (exitcode) {
print "USAGE"
print ENVIRON["_"] " [date formattée] [[-]stdin] [help]\n"
print "OPTIONS"
print " date : format 20AA-MM-JJ"
print " défaut: date du jour\n"
print " -stdin, stdin : lit depuis l'entrée standard"
print " défaut: lit /var/log/dpkg.log\n"
print " help : affiche cette aide et quitte"
exit exitcode
}
BEGIN {
installed = "installed"
remove = "remove"
upgrade = "upgrade"
notinstalled = "not-installed"
trigproc = "trigproc"
errors = 0
datefound = 0
filename = "/var/log/dpkg.log"
for (i = 1; i < ARGC; i++)
switch (ARGV[i]) {
case /^-?stdin$/:
filename = "-"
break
case /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/:
date = ARGV[i]
break
case "help":
show_help_and_exit(0)
default:
print ARGV[i] " : option inconnue"
show_help_and_exit(1)
}
if (date == "")
date = strftime("%F")
while ((getline < filename) == 1) {
if ($1 == date) {
datefound = 1
switch ($3) {
case "status":
pkg[$5][$4] = $NF
break
case "upgrade":
pkg[$4][upgrade] = $NF
break
case "remove":
pkg[$4][remove]++
break
case "trigproc":
pkg[$4][trigproc]++
break
case "configure":
default:
break
}
}
}
if (! datefound) {
printf("date %s non trouvée %s\n", date, filename != "-" ? "dans " filename : "")
exit 1
}
list_pkgs(trigproc, "", installed) # pas d'affichage si OK
list_pkgs(upgrade, "mis à jour", installed)
list_pkgs(remove, "supprimés", notinstalled)
list_pkgs(installed, "nouvellement installés")
count = 0
for (p in pkg)
count++
if (count)
print count " erreurs"
for (p in pkg) {
status = ""
for (s in pkg[p]) if (pkg[p][s]) status = status " " s
print " -> " p " (" gensub(" ", "", 1, status) ")"
}
}