NBash

Форк
0
173 строки · 4.7 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2023  Etersoft
4
# Copyright (C) 2023  Vitaly Lipatov <lav@etersoft.ru>
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
15
#
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#
19

20
EHOG='\(apt-get\|rpm\)'
21
JCHAN='-t apt-get -t rpm'
22

23
__alt_epm_history_journal()
24
{
25
    a= journalctl $JCHAN
26
}
27

28
__alt_epm_history_uniq()
29
{
30
    __alt_epm_history_journal | grep "$EHOG\[[0-9][0-9]*\]:" | sed -e "s@.*$EHOG\[\([0-9][0-9]*\)\]: .*@\2@" | uniq | tac
31
}
32

33
# args: pid, removed|installed
34
__alt_epm_history_select()
35
{
36
    local pid="$1"
37
    local verb="$2"
38
    __alt_epm_history_journal | grep "$EHOG\[$pid\]: .*$verb" | sed -e "s@.*$EHOG\[[0-9][0-9]*\]: @@" | cut -d" " -f 1
39
}
40

41
_alt_epm_history_date()
42
{
43
    local pid="$1"
44
    __alt_epm_history_journal | grep "$EHOG\[$pid\]: " | head -n1 | cut -d" " -f 1-3,5 | sed -e 's|:$||'
45
}
46

47
_alt_epm_history_print_group()
48
{
49
    local i
50

51
    if [ -n "$2" ] ; then
52
        echo
53
        echo "$1 session:"
54
        shift
55
    else
56
        return
57
    fi
58

59
    for i in $* ; do
60
        echo "    $i"
61
    done
62
}
63

64

65
__alt_epm_history_removed()
66
{
67
    echo "Removed packages history:"
68
    __alt_epm_history_uniq | while read pid ; do
69
        date="$(_alt_epm_history_date $pid)"
70
        removed="$(epm print shortname for $(__alt_epm_history_select $pid "removed") )"
71
        installed="$(epm print shortname for $(__alt_epm_history_select $pid "installed") )"
72
        _alt_epm_history_print_group "$date" $(estrlist exclude "$installed" "$removed")
73
    done
74
}
75

76
__alt_epm_history_installed()
77
{
78
    echo "Installed packages history:"
79
    __alt_epm_history_uniq | while read pid ; do
80
        date="$(_alt_epm_history_date $pid)"
81
        #epm print shortname for $(__alt_epm_history_select $pid "installed") | sed -e "s|^|    |"
82
        removed="$(epm print shortname for $(__alt_epm_history_select $pid "removed") )"
83
        installed="$(epm print shortname for $(__alt_epm_history_select $pid "installed") )"
84
        _alt_epm_history_print_group "$date" $(estrlist exclude "$removed" "$installed")
85
    done
86
}
87

88
__alt_epm_history_updated()
89
{
90
    echo "Updated packages history:"
91
    __alt_epm_history_uniq | while read pid ; do
92
        date="$(_alt_epm_history_date $pid)"
93
        #epm print shortname for $(__alt_epm_history_select $pid "installed") | sed -e "s|^|    |"
94
        removed="$(epm print shortname for $(__alt_epm_history_select $pid "removed") )"
95
        installed="$(epm print shortname for $(__alt_epm_history_select $pid "installed") )"
96
        _alt_epm_history_print_group "$date" $(estrlist intersection "$removed" "$installed")
97
    done
98
}
99

100
epm_history_help()
101
{
102
    echo "package management history"
103
            get_help HELPCMD $SHAREDIR/epm-history
104
    cat <<EOF
105
Examples:
106
  epm history
107
  epm history --removed
108
EOF
109
}
110

111

112
epm_history()
113
{
114

115
if [ $PMTYPE = "apt-rpm" ] ; then
116
    case "$1" in
117
        "-h"|"--help"|"help")      # HELPCMD: help
118
            epm_history_help
119
            return
120
            ;;
121
        --installed)               # HELPCMD: print only new installed packages
122
            __alt_epm_history_installed
123
            return
124
            ;;
125
        --removed)                 # HELPCMD: print only removed packages
126
            __alt_epm_history_removed
127
            return
128
            ;;
129
        --updated)                 # HELPCMD: print only updated packages
130
            __alt_epm_history_updated
131
            return
132
            ;;
133
        --list)                    # HELPCMD: (or empty) print all history entries
134
            docmd journalctl $JCHAN
135
            return
136
            ;;
137
        "")
138
            ;;
139
        *)
140
            fatal "Unknown option $1. Use epm history --help to get help."
141
    esac
142
fi
143

144
[ -z "$*" ] || fatal "No arguments are allowed here"
145

146
case $PMTYPE in
147
    apt-rpm)
148
        docmd journalctl $JCHAN -r
149
        ;;
150
    apt-dpkg)
151
        docmd cat /var/log/dpkg.log
152
        ;;
153
    dnf-rpm)
154
        sudocmd dnf history
155
        ;;
156
    eopkg)
157
        sudocmd eopkg history
158
        ;;
159
    zypper-rpm)
160
        docmd cat /var/log/zypp/history
161
        ;;
162
    pacman)
163
        docmd cat /var/log/pacman.log
164
        ;;
165
    emerge)
166
        docmd cat /var/log/portage
167
        ;;
168
    *)
169
        fatal "Have no suitable command for $PMTYPE"
170
        ;;
171
esac
172

173
}
174

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.