scripts / upgrade_status /
Newer Older
113 lines | 3.084kb
ajout
Sébastien MARQUE authored on 2016-10-31
1
#!/usr/bin/awk -f
2
function list_pkgs (type, label, test) {
3
    count = 0
4
    for (p in pkg)
5
        if (pkg[p][type]) {
6
            count++
7
        }
8
    if (count) {
9
        if (label) print count " paquets " label
10
        n = asorti(pkg, pkg_sorted)
11
        for (i = 1; i <= n; i++) {
12
            p = pkg_sorted[i]
13
            pkg_ok = 0
14
            if (test) {
15
                if (pkg[p][type] && pkg[p][test])
16
                    pkg_ok = 1
17
            }
18
            else {
19
                if (pkg[p][type])
20
                    pkg_ok = 1
21
            }
22
            if (pkg_ok) {
23
                if (label) print " -> " p
24
                delete pkg[p]
25
            }
26
        }
27
    }
28
}
29

            
30
function show_help_and_exit (exitcode) {
31
    print "USAGE"
32
    print ENVIRON["_"] " [date formattée] [[-]stdin] [help]\n"
33
    print "OPTIONS"
34
    print "  date          : format 20AA-MM-JJ"
35
    print "                  défaut: date du jour\n"
36
    print "  -stdin, stdin : lit depuis l'entrée standard"
37
    print "                  défaut: lit /var/log/dpkg.log\n"
38
    print "  help          : affiche cette aide et quitte"
39
    exit exitcode
40
}
41

            
42
BEGIN {
43
    installed = "installed"
44
    remove = "remove"
45
    upgrade = "upgrade"
46
    notinstalled = "not-installed"
47
    trigproc = "trigproc"
48
    errors = 0
49
    datefound = 0
50
    filename = "/var/log/dpkg.log"
51

            
52
    for (i = 1; i < ARGC; i++)
53
        switch (ARGV[i]) {
54
            case /^-?stdin$/:
55
                filename = "-"
56
                break
57
            case /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/:
58
                date = ARGV[i]
59
                break
60
            case "help":
61
                show_help_and_exit(0)
62
            default:
63
                print ARGV[i] " : option inconnue"
64
                show_help_and_exit(1)
65
        }
66

            
67
    if (date == "")
68
        date = strftime("%F")
69

            
70
    while ((getline < filename) == 1) {
71
        if ($1 == date) {
72
            datefound = 1
73
            switch ($3) {
74
                case "status":
75
                    pkg[$5][$4] = $NF
76
                    break
77
                case "upgrade":
78
                    pkg[$4][upgrade] = $NF
79
                    break
80
                case "remove":
81
                    pkg[$4][remove]++
82
                    break
83
                case "trigproc":
84
                    pkg[$4][trigproc]++
85
                    break
86
                case "configure":
87
                default:
88
                    break
89
            }
90
        }
91
    }
92

            
93
    if (! datefound) {
94
        printf("date %s non trouvée %s\n", date, filename != "-" ? "dans " filename : "")
95
        exit 1
96
    }
97

            
98
    list_pkgs(trigproc,  "",         installed) # pas d'affichage si OK
99
    list_pkgs(upgrade,   "mis à jour", installed)
100
    list_pkgs(remove,    "supprimés",  notinstalled)
101
    list_pkgs(installed, "nouvellement installés")
102

            
103
    count = 0
104
    for (p in pkg)
105
        count++
106
    if (count)
107
        print count " erreurs"
108
    for (p in pkg) {
109
        status = ""
110
        for (s in pkg[p]) if (pkg[p][s]) status = status " " s
111
        print " -> " p " (" gensub(" ", "", 1, status) ")"
112
    }
113
}