NBash

Форк
0
153 строки · 4.1 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2012,2014,2016  Etersoft
4
# Copyright (C) 2012,2014,2016  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
load_helper epm-check_updated_repo
21

22
__epm_add_alt_apt_downgrade_preferences()
23
{
24
    [ -r /etc/apt/preferences ] && fatal "/etc/apt/preferences already exists"
25
    cat <<EOF | sudocmd tee /etc/apt/preferences
26
# classic repo
27
Package: *
28
Pin: release c=classic
29
Pin-Priority: 1001
30

31
# overload with addon repo
32
Package: *
33
Pin: release c=addon
34
Pin-Priority: 1101
35

36
# main repo
37
Package: *
38
Pin: release c=main
39
Pin-Priority: 1201
40

41
# overload with test (task) repo
42
Package: *
43
Pin: release c=task
44
Pin-Priority: 1301
45
EOF
46
}
47

48
# See https://wiki.debian.org/ru/AptPreferences
49
__epm_add_deb_apt_downgrade_preferences()
50
{
51
    [ -r /etc/apt/preferences ] && fatal "/etc/apt/preferences already exists"
52
    info "Running with /etc/apt/preferences:"
53
    cat <<EOF | sudorun tee /etc/apt/preferences
54
Package: *
55
Pin: release a=stable
56
Pin-Priority: 1001
57

58
Package: *
59
Pin: release a=testing
60
Pin-Priority: 900
61

62
Package: *
63
Pin: release a=unstable
64
Pin-Priority: 800
65
EOF
66
}
67

68
__epm_remove_apt_downgrade_preferences()
69
{
70
    sudocmd rm -f /etc/apt/preferences
71
}
72

73
epm_downgrade()
74
{
75
    local CMD
76

77
    # it is useful for first time running
78
    update_repo_if_needed
79

80
    # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
81
    if [ -n "$pkg_urls" ] ; then
82
        info "Downloading packages assigned to downgrade ..."
83
        load_helper epm-download
84
        __handle_pkg_urls_to_install
85
    fi
86

87
    info "Running command for downgrade packages"
88

89
    case $BASEDISTRNAME in
90
    alt)
91
        # pass pkg_filenames too
92
        if [ -n "$pkg_names" ] ; then
93
            __epm_add_alt_apt_downgrade_preferences || return
94
            load_helper epm-install
95
            (pkg_names=$(get_only_installed_packages $pkg_names) epm_install)
96
            __epm_remove_apt_downgrade_preferences
97
        elif [ -n "$pkg_files" ] ; then
98
            load_helper epm-install
99
            local pkgs=''
100
            local i
101
            for i in $pkg_files ; do
102
                local pkgname="$(epm print name for package $i)"
103
                is_installed $pkgname || continue
104
                pkgs="$pkgs $i"
105
            done
106
            (force="$force --oldpackage" epm_install_files $pkgs)
107
        else
108
            __epm_add_alt_apt_downgrade_preferences || return
109
            load_helper epm-upgrade
110
            epm_upgrade "$@"
111
            __epm_remove_apt_downgrade_preferences
112
        fi
113
        return
114
        ;;
115
    esac
116

117
    case $PMTYPE in
118
    #apt-rpm)
119
    #    ;;
120
    apt-dpkg)
121
        local APTOPTIONS="$(subst_option non_interactive -y) $force_yes"
122
        __epm_add_deb_apt_downgrade_preferences || return
123
        if [ -n "$pkg_filenames" ] ; then
124
            sudocmd apt-get $APTOPTIONS install $pkg_filenames
125
        else
126
            sudocmd apt-get $APTOPTIONS dist-upgrade
127
        fi
128
        __epm_remove_apt_downgrade_preferences
129
        ;;
130
    yum-rpm)
131
        # can do update repobase automagically
132
        if [ -n "$pkg_filenames" ] ; then
133
            sudocmd yum downgrade $pkg_filenames
134
        else
135
            sudocmd yum distro-sync
136
        fi
137
        ;;
138
    dnf-rpm)
139
        if [ -n "$pkg_filenames" ] ; then
140
            sudocmd dnf downgrade $pkg_filenames
141
        else
142
            sudocmd dnf distro-sync
143
        fi
144
        ;;
145
    urpm-rpm)
146
        assure_exists urpm-reposync urpm-tools
147
        sudocmd urpm-reposync -v
148
        ;;
149
    *)
150
        fatal "Have no suitable command for $PMTYPE"
151
        ;;
152
    esac
153
}
154

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

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

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

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