epm-release_downgrade 4.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/bin/sh
#
# Copyright (C) 2013, 2016, 2017, 2019, 2020, 2021  Etersoft
# Copyright (C) 2013, 2016, 2017, 2019, 2020, 2021  Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

load_helper epm-release_upgrade

get_prev_release()
{
24 25 26 27 28 29 30 31
    local FROM="$1"
    case "$FROM" in
    "p8")
        echo "p7" ;;
    "p9")
        echo "p8" ;;
    "p10")
        echo "p9" ;;
32 33
    "p11")
        echo "p10" ;;
34 35 36 37 38 39 40 41 42 43 44 45
    "c7")
        echo "c6" ;;
    "c8")
        echo "c7" ;;
    "c8.1")
        echo "c8" ;;
    "c8.2")
        echo "c8.1" ;;
    "c9f1")
        echo "c8" ;;
    "c9f2")
        echo "c9f1" ;;
46 47
    "c10f2")
        echo "c10f1" ;;
48 49 50 51 52
    "10")
        echo "9" ;;
    *)
        echo "$FROM" ;;
    esac
53 54 55 56 57
}

# FIXME: see epm_release_upgrade
epm_release_downgrade()
{
58 59 60 61
    assure_root
    assure_safe_run
    info "Starting upgrade/switch whole system to other release"
    info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"
62

63 64 65
    cd /tmp || fatal
    # TODO: it is possible eatmydata does not do his work
    export EPMNOEATMYDATA=1
66

67 68 69
    case $BASEDISTRNAME in
    "alt")
        __epm_ru_update || fatal
70

71 72 73 74 75 76
        # try to detect current release by repo
        if [ "$DISTRVERSION" = "Sisyphus" ] || [ -z "$DISTRVERSION" ] ; then
            local dv
            dv="$(__detect_alt_release_by_repo)"
            if [ -n "$dv" ] && [ "$dv" != "$DISTRVERSION" ] ; then
                DISTRVERSION="$dv"
77
                info 'Detected running $DISTRNAME $DISTRVERSION (according to using repos)'
78 79
            fi
        fi
80

81 82 83 84 85 86 87 88 89
        TARGET=""
        [ -n "$3" ] && fatal "Too many args: $*"
        if [ -n "$2" ] ; then
            DISTRVERSION="$1"
            info "Force current distro version as $DISTRVERSION"
            TARGET="$2"
        elif [ -n "$1" ] ; then
            TARGET="$1"
        fi
90

91
        [ -n "$TARGET" ] || TARGET="$(get_prev_release $DISTRVERSION)"
92

93
        __alt_repofix
94

95
        __switch_alt_to_distro $DISTRVERSION $TARGET && info 'Done. The system has been successfully downgraded to the previous release $TARGET.'
96

97 98 99 100 101
        return 0
        ;;
    *)
        ;;
    esac
102

103 104 105
    case $PMTYPE in
    apt-rpm)
        #docmd epm update
106
        info 'Have no idea how to downgrade $DISTRNAME'
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
        ;;
    *-dpkg)
        assure_exists do-release-upgrade update-manager-core
        sudocmd do-release-upgrade
        ;;
    packagekit)
        docmd pkcon upgrade-system "$@"
        ;;
    yum-rpm)
        docmd epm install rpm yum
        sudocmd yum clean all
        info "Try manually:"
        showcmd rpm -Uvh http://mirror.yandex.ru/fedora/linux/releases/16/Fedora/x86_64/os/Packages/fedora-release-16-1.noarch.rpm
        showcmd epm Upgrade
        ;;
122
    dnf-rpm|dnf5-rpm)
123 124 125 126 127 128 129 130 131 132
        info "Check https://fedoraproject.org/wiki/DNF_system_upgrade for an additional info"
        docmd epm install dnf
        #docmd epm install epel-release yum-utils
        sudocmd dnf --refresh upgrade
        sudocmd dnf clean all
        assure_exists dnf-plugin-system-upgrade
        sudocmd dnf upgrade --refresh
        local RELEASEVER="$1"
        [ -n "$RELEASEVER" ] || RELEASEVER=$(($DISTRVERSION + 1))
        #[ -n "$RELEASEVER" ] || fatal "Run me with new version"
133
        confirm_info 'Upgrade to $DISTRNAME/$RELEASEVER'
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
        sudocmd dnf system-upgrade download --refresh --releasever=$RELEASEVER
        # TODO: from docs:
        # dnf system-upgrade reboot
        # FIXME: download all packages again
        sudocmd dnf distro-sync --releasever=$RELEASEVER
        info "Run epm autoorphans to remove orphaned packages"
        ;;
    urpm-rpm)
        sudocmd urpmi.removemedia -av
        info "Try do manually:"
        showcmd urpmi.addmedia --distrib http://mirror.yandex.ru/mandriva/devel/2010.2/i586/
        sudocmd urpmi --auto-update --replacefiles
        ;;
    zypper-rpm)
        docmd epm repolist
        # TODO
        # sudocmd zypper rr <номер_репозитория>
        showcmd rr N
        showcmd epm ar http://mirror.yandex.ru/opensuse/distribution/11.1/repo/oss 11.1oss
        showcmd zypper ref
        docmd epm update
        docmd epm install rpm zypper
        docmd epm upgrade
        ;;
    pacman)
        epm Upgrade
        ;;
    conary)
        epm Upgrade
        ;;
    emerge)
        epm Upgrade
        ;;
    guix)
        sudocmd guix pull --verbose
        ;;
    *)
171
        fatal 'Have no suitable command for $PMTYPE'
172 173
        ;;
    esac
174 175

}