NBash

Форк
0
155 строк · 4.8 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2015, 2017  Etersoft
4
# Copyright (C) 2015, 2017  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
__epm_orphan_altrpm()
21
{
22
    docmd apt-cache list-extras
23
}
24

25
epm_autoorphans()
26
{
27

28
[ -z "$*" ] || fatal "No arguments are allowed here"
29

30
case $BASEDISTRNAME in
31
    alt)
32
        # ALT Linux only
33
        assure_exists /usr/share/apt/scripts/list-extras.lua apt-scripts
34
        if [ -z "$dryrun" ] ; then
35
            echo "We will try remove all installed packages which are missed in repositories"
36
            warning "Use with caution!"
37
        fi
38
        epm Upgrade || fatal
39
        info "Retrieving orphaned packages list ..."
40
        local PKGLIST=$(__epm_orphan_altrpm \
41
            | sed -e "s/\.32bit//g" \
42
            | grep -v -- "^eepm$" \
43
            | grep -v -- "^distro_info$" \
44
            | grep -v -- "^kernel")
45

46
        # TODO: implement for other PMTYPE
47
        info "Retrieving packages installed via epm play ..."
48
        local play_installed="$(epm play --list-installed-packages)"
49
        if [ -n "$play_installed" ] ; then
50
            echo "Skip follow packages installed via epm play: $(echo $play_installed | xargs -n1000 echo)"
51
            PKGLIST="$(estrlist exclude "$play_installed" "$PKGLIST")"
52
        fi
53

54
        # TODO: implement for other PMTYPE
55
        local hold_packages="$(epm mark --short showhold)"
56
        if [ -n "$hold_packages" ] ; then
57
            echo "Skip follow packages on hold: $(echo $hold_packages | xargs -n1000 echo)"
58
            PKGLIST="$(estrlist exclude "$hold_packages" "$PKGLIST")"
59
        fi
60

61
        if [ -n "$PKGLIST" ] ; then
62
            if [ -z "$dryrun" ] ; then
63
                showcmd epm remove $dryrun $force $PKGLIST
64
                confirm_info "We will remove packages above."
65
            fi
66
            info
67
            info
68
            docmd epm remove $dryrun $force $(subst_option non_interactive --auto) $PKGLIST
69
        else
70
            echo "There are no orphan packages in the system."
71
        fi
72
        return 0
73
        ;;
74
esac
75

76
case $PMTYPE in
77
    apt-dpkg|aptitude-dpkg)
78
        assure_exists deborphan
79
        showcmd deborphan
80
        a='' deborphan | docmd epm remove $dryrun
81
        ;;
82
    #aura)
83
    #    sudocmd aura -Oj
84
    #    ;;
85
    yum-rpm)
86
        docmd epm upgrade
87
        assure_exists package-cleanup yum-utils
88
        showcmd package-cleanup --orphans
89
        local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-")
90
        docmd epm remove $dryrun $PKGLIST
91
        ;;
92
    dnf-rpm)
93
        # TODO: dnf list extras
94
        docmd epm upgrade
95
        assure_exists package-cleanup dnf-utils
96
        showcmd package-cleanup --orphans
97
        local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-")
98
        docmd epm remove $dryrun $PKGLIST
99
        ;;
100
    urpm-rpm)
101
        if [ -n "$dryrun" ] ; then
102
            fatal "--dry-run is not supported yet"
103
        else
104
            showcmd urpme --report-orphans
105
            sudocmd urpme --auto-orphans
106
        fi
107
        ;;
108
    #emerge)
109
    #    sudocmd emerge --depclean
110
    #    assure_exists revdep-rebuild
111
    #    sudocmd revdep-rebuild
112
    #    ;;
113
    pacman)
114
        if [ -n "$dryrun" ] ; then
115
            info "Autoorphans packages list:"
116
            sudocmd pacman -Qdtq
117
        else
118
            sudocmd pacman -Qdtq | sudocmd pacman -Rs -
119
        fi
120
        ;;
121
    slackpkg)
122
        # clean-system removes non official packages
123
        sudocmd slackpkg clean-system
124
        ;;
125
    eopkg)
126
        sudocmd eopkg remove-orphans
127
        ;;
128
    #guix)
129
    #    sudocmd guix gc
130
    #    ;;
131
    #pkgng)
132
    #    sudocmd pkg autoremove
133
    #    ;;
134
    zypper-rpm)
135
        # https://www.linux.org.ru/forum/desktop/11931830
136
        assure_exists zypper zypper 1.9.2
137
        # For zypper < 1.9.2: zypper se -si | grep 'System Packages'
138
        sudocmd zypper packages --orphaned
139
        # FIXME: x86_64/i586 are duplicated
140
        local PKGLIST=$(zypper packages --orphaned | tail -n +5 | cut -d \| -f 3 | sort -u)
141
        docmd epm remove $dryrun --clean-deps $PKGLIST
142
        ;;
143
    xbps)
144
        if [ -n "$dryrun" ] ; then
145
            fatal "--dry-run is not supported yet"
146
        else
147
            sudocmd xbps-remove -o
148
        fi
149
        ;;
150
    *)
151
        fatal "Have no suitable command for $PMTYPE"
152
        ;;
153
esac
154

155
}
156

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

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

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

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