epm-release_upgrade 27.2 KB
Newer Older
1 2
#!/bin/sh
#
Vitaly Lipatov's avatar
Vitaly Lipatov committed
3 4
# Copyright (C) 2013, 2016-2025  Etersoft
# Copyright (C) 2013, 2016-2025  Vitaly Lipatov <lav@etersoft.ru>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# 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/>.
#

20
load_helper epm-query
21
load_helper epm-repofix
22
load_helper epm-reposave
23

24 25
assure_safe_run()
{
26
    if [ "$TERM" = "linux" ] ; then
27
        message "You have the best choise to run the '# epm release-upgrade' from text console."
28 29 30 31
        return
    fi
    if [ "$TERM" != "screen" ] ; then
        if [ -n "$force" ] ; then
32
            message 'You force me running not under screen (TERM=$TERM now)! You can lost your system!'
33 34
            return
        else
35
            warning 'It is very dangerous to upgrade to next release from a GUI (your TERM=$TERM).'
36 37 38 39 40 41 42 43 44 45 46
            if is_installed screen ; then
                warning "You have 'screen' already installed, just run upgrade via screen (check https://losst.ru/komanda-screen-linux if needed)."
            else
                warning "It is recommended install 'screen' and run upgrade via screen (check https://losst.ru/komanda-screen-linux if needed)."
            fi
            fatal "or run me with --force if you understand the risk."
        fi
    fi

    # run under screen, check if systemd will not kill our processes
    local res
47
    if ! is_active_systemd ; then
48 49 50
        return
    fi

51
    res="$(a= busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager KillUserProcesses)"
52
    if [ "$res" = "b false" ] ; then
53
        message "Good news: systemd-logind will not kill your screen processes (KillUserProcesses=false)"
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        return
    else
        if [ -n "$force" ] ; then
            warning "You force runnning even if systemd-logind kills screen on disconnect"
        else
            if ! epm installed systemd-settings-disable-kill-user-processes ; then
                docmd epm install systemd-settings-disable-kill-user-processes || fatal "Can't install the package above. Fix it or run with --force."
            fi
            # commented, will kick off the user from the system (ALT issue 50580)
            #docmd serv systemd-logind restart || fatal "Can't restart systemd-logind service. Fix it or run with --force."
            fatal "Now you need relogin to the system. In this session your screen still will be killed."
        fi
    fi

    # check too: KillExcludeUsers

    # can continue
    return 0
72 73
}

74 75
__wcount()
{
76
    echo "$*" | wc -w
77 78
}

79 80 81 82 83 84
__p11_upgrade_fix()
{
    if [[ ! $(docmd epm installed apt-conf-branch) ]]; then 
        info "Need to install default apt-conf package to avoid missing $TO repo"
        docmd epm install apt-conf-branch || fatal
    fi
85 86 87
    # файл /etc/openssl/openssl.cnf из устанавливаемого пакета openssl-config-3.2.0-alt1.noarch конфликтует с файлом из пакета libcrypto10-1.0.2u-alt1.p9.2.x86_64
    docmd epm remove libcrypto10 libssl10

88
    # libcrypto1.1 workaround
89 90
    docmd epm repo save
    docmd epm repo rm all
91
    docmd epm repo add archive sisyphus 2024/05/22
92 93
    docmd epm update
    docmd epm install libcrypto1.1
94
    #docmd epm repo rm all
95 96 97 98 99
    docmd epm repo restore
}

__sisyphus_downgrade_fix()
{
100
    if [[ ! $(docmd epm installed apt-conf-branch) ]]; then 
101
        info "Need to install default apt-conf package to avoid missing $TO repo"
102
        docmd epm install apt-conf-branch || fatal
103 104 105
    fi
}

106
# TODO: remove it or move to distro_info
107 108
__detect_alt_release_by_repo()
{
109 110
    local BRD=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list \
        | grep -v "^#" \
111 112
        | grep -E "[tpc][1-3]?[5-9][f.]?[0-9]?/branch/" \
        | sed -e "s|.*\([tpc][1-3]\?[5-9][f.]\?[0-9]\?\)/branch.*|\1|g" \
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        | sort -u )
    if [ "$(__wcount $BRD)" = "1" ] ; then
        echo "$BRD"
        return
    fi

    local BRD=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list \
        | grep -v "^#" \
        | grep "Sisyphus/" \
        | sed -e "s|.*\(Sisyphus\).*|\1|g" \
        | sort -u )
    if [ "$(__wcount $BRD)" = "1" ] ; then
        echo "$BRD"
        return
    fi

    return 1
130 131
}

132

133 134
__get_conflict_release_pkg()
{
135
    epm qf --quiet --short /etc/fedora-release | head -n1
136 137
}

138 139
get_fix_release_pkg()
{
140 141 142
    local TOINSTALL=''

    local FORCE=''
Vitaly Lipatov's avatar
Vitaly Lipatov committed
143
    if [ "$1" = "--force" ] ; then
144 145 146 147 148 149 150 151 152 153 154
        FORCE="$1"
        shift
    fi

    local TO="$1"

    if [ "$TO" = "Sisyphus" ] ; then
        TO="sisyphus"
        echo "apt-conf-$TO"
        # apt-conf-sisyphus and apt-conf-branch conflicts
        epm installed apt-conf-branch && echo "apt-conf-branch-"
155 156 157 158
        #for i in apt apt-rsync libapt libpackagekit-glib librpm7 packagekit rpm synaptic realmd libldap2 ; do
        #    epm installed $i && echo "$i"
        #done

159
    else
160
        epm installed apt-conf-branch && echo "apt-conf-branch" && epm installed apt-conf-sisyphus && echo "apt-conf-sisyphus-"
161 162
    fi

Vitaly Lipatov's avatar
Vitaly Lipatov committed
163
    if [ "$FORCE" = "--force" ] ; then
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        # assure we have set needed release
        TOINSTALL="altlinux-release-$TO"
    else
        # just assure we have /etc/altlinux-release and switched from sisyphus
        if [ ! -s /etc/altlinux-release ] || epm qf /etc/altlinux-release | grep -q sisyphus ; then
            TOINSTALL="altlinux-release-$TO"
        fi
    fi

    #local AR="$(epm --short qf /etc/altlinux-release)"
    #if [ -n "$AR" ] && [ "$AR" != "$TOINSTALL" ] ; then
    #    echo "$AR-"
    #fi

    # TODO: add bug?
    # workaround against obsoleted altlinux-release-sisyphus package from 2008 year
    [ "$TOINSTALL" = "altlinux-release-sisyphus" ] && TOINSTALL="branding-alt-sisyphus-release"

    if epm installed etersoft-gpgkeys ; then
        # TODO: we don't support LINUX@Etersoft for now
        # leave etersoft-gpgkeys only if we have LINUX@Etersoft repo
        #epm repo list | grep -q "LINUX@Etersoft" && echo "etersoft-gpgkeys" || echo "alt-gpgkeys"
186
        epm --quiet repo disable "LINUX@Etersoft"
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
        echo "alt-gpgkeys"
    else
        # update if installed (just print package name here to include in the install list)
        epm query --short alt-gpgkeys 2>/dev/null
    fi

    if [ -n "$TOINSTALL" ] ; then
        echo "$TOINSTALL"

        # workaround against
        #    file /etc/fedora-release from install of altlinux-release-p8-20160414-alt1 conflicts with file from package branding-simply-linux-release-8.2.0-alt1
        # problem
        local AR="$(__get_conflict_release_pkg)"
        if [ -n "$AR" ] && [ "$TOINSTALL" != "$AR" ] ; then
            #echo $AR-
            # remove conflicts package right here to workaround against asking 'Yes, do as I say!' later
            epm remove --nodeps $AR >/dev/null
        fi
    fi
206 207
}

208 209
__check_system()
{
210 211 212 213
    local TO="$1"
    shift

    # sure we have systemd if systemd is running
214
    if is_active_systemd ; then
215 216 217 218
        docmd epm --skip-installed install systemd || fatal
    fi

    if [ "$TO" != "Sisyphus" ] ; then
219
        # note: we get --base-version directy to get new version
220
        if [ "$($DISTRVENDOR --base-version)" != "$TO" ] || epm installed altlinux-release-sisyphus >/dev/null ; then
221 222
            warning 'Current distro still is not $TO, or altlinux-release-sisyphus package is installed.'
            warning 'Trying to fix with altlinux-release-$TO'
223
            docmd epm install altlinux-release-$TO
224
            docmd epm install altlinux-os-release
225 226 227 228
        fi
    fi

    # switch from prefdm: https://bugzilla.altlinux.org/show_bug.cgi?id=26405#c47
229
    if is_active_systemd ; then
230 231 232 233 234 235
        if serv display-manager exists || serv prefdm exists ; then
            # don't stop running X server!
            # docmd serv dm off
            docmd serv disable prefdm
            docmd serv disable display-manager
            docmd serv enable display-manager
236 237 238 239 240 241 242 243

# $ epm sf dm.service
# xinitrc: /lib/systemd/system/dm.service
# gdm: /lib/systemd/system/gdm.service
# lightdm: /lib/systemd/system/lightdm.service
# lxde-lxdm: /lib/systemd/system/lxdm.service
# xinitrc: /lib/systemd/system/prefdm.service
# sddm: /lib/systemd/system/sddm.service
244 245 246 247 248 249
            # enable first available DM
            for i in lightdm sddm lxde-lxdm gdm ; do
                serv $i exists && docmd serv enable $i && break
            done
        fi
    fi
250

251
}
252

253 254 255
__epm_ru_update()
{
    docmd epm update && return
256
    # TODO: there can be errors due obsoleted alt-gpgkeys
257 258 259 260 261 262
    epm update 2>&1 | grep "E: Unknown vendor ID" || return
    info "Drop vendor signs"
    __alt_replace_sign_name ""
    docmd epm update
}

263 264 265 266 267 268
__switch_repo_to()
{
    epm_reposwitch "$@"
    __epm_ru_update || fatal
}

269 270
get_next_release()
{
271 272 273 274 275 276 277 278 279 280
    local FROM="$1"
    case "$FROM" in
    "p6")
        echo "p7" ;;
    "p7")
        echo "p8" ;;
    "p8")
        echo "p9" ;;
    "p9")
        echo "p10" ;;
281 282
    "p10")
        echo "p11" ;;
283 284 285 286
    "c6")
        echo "c7" ;;
    "c7")
        echo "c8" ;;
287 288
#    "c8")
#        echo "c8.1" ;;
289 290 291 292 293 294
    "c8.1")
        echo "c8.2" ;;
    "c8")
        echo "c9f2" ;;
    "c9f1")
        echo "c9f2" ;;
295 296
    "c10f1")
        echo "c10f2" ;;
297 298
    "c10f2")
        echo "c10f3" ;;
299 300 301
    *)
        echo "$FROM" ;;
    esac
302 303
}

304 305
__do_upgrade()
{
306
    docmd epm $non_interactive $force_yes upgrade || fatal "Check the errors and run '# $0' again"
307 308
}

309 310
# TODO: install new conf without signs?
__switch_alt_to_distro()
311
{
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
    local TO="$2"
    local FROM="$1"
    info

    try_change_alt_repo

    case "$*" in
        "p6"|"p6 p7"|"t6 p7"|"c6 c7")
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
            __switch_repo_to $TO
            docmd epm install rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            end_change_alt_repo
            __do_upgrade
            docmd epm update-kernel
            info "Run epm release-upgrade again for update to p8"
            ;;
        "p7"|"p7 p8"|"t7 p8"|"c7 c8")
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
            __switch_repo_to $TO
            docmd epm install rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            end_change_alt_repo
            __do_upgrade
            __check_system "$TO"
            docmd epm update-kernel || fatal
            info "Run epm release-upgrade again for update to p9"
            ;;
        "c8"|"c8.1"|"c8.2"|"c8 c8.1"|"c8.1 c8.2"|"c8 c8.2")
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
            __switch_repo_to $TO
            docmd epm install rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            end_change_alt_repo
            __do_upgrade
            __check_system "$TO"
            docmd epm update-kernel || fatal
            ;;
        "p8 c8"|"p8 c8.1"|"p8 c8.2")
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
            __switch_repo_to $TO
            docmd epm install rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            if epm installed libcrypt ; then
                # glibc-core coflicts libcrypt
                docmd epm downgrade apt pam pam0_passwdqc glibc-core libcrypt- || fatal
            fi
            docmd epm $non_interactive $force_yes downgrade || fatal
            end_change_alt_repo
            __do_upgrade
            __check_system "$TO"
            docmd epm update-kernel || fatal
            ;;
        "p8"|"p8 p9"|"t8 p9"|"c8 c9"|"c8 p9"|"c8.1 p9"|"c8.2 p9"|"p9 p9"|"p9 c9f2")
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
            info "Workaround for https://bugzilla.altlinux.org/show_bug.cgi?id=35492 ..."
            if epm installed gdb >/dev/null ; then
                docmd epm remove gdb || fatal
            fi
            __switch_repo_to $TO
            end_change_alt_repo
            __do_upgrade
            docmd epm install rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            __check_system "$TO"
            docmd epm update-kernel || fatal
            info "Run epm release-upgrade again for update to p10"
            ;;
380
        "p9"|"p9 p10"|"p10 p10")
381 382 383 384
            info "Upgrade all packages to current $FROM repository"
            __do_upgrade
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
385
            if [ $TO = "p11" ]; then __p11_upgrade_fix; fi
386 387 388 389 390 391 392
            __switch_repo_to $TO
            end_change_alt_repo
            __do_upgrade
            docmd epm install rpm apt $(get_fix_release_pkg "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            __check_system "$TO"
            docmd epm update-kernel -t std-def || fatal
            ;;
393 394 395 396 397 398 399 400 401 402 403 404 405 406
        "p10 p11")
            info "Upgrade all packages to current $FROM repository"
            __do_upgrade
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
            __p11_upgrade_fix
            __switch_repo_to $TO
            end_change_alt_repo
            __do_upgrade
            docmd epm install rpm apt $(get_fix_release_pkg "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            __check_system "$TO"
            # will update to kernel 6.6
            docmd epm update-kernel || fatal
            ;;
407 408 409 410 411 412 413 414 415 416 417 418 419 420
        "c10f1 c10f2"|"c10f2 c10f3")
            info "Upgrade all packages to current $FROM repository"
            __do_upgrade
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
            __p11_upgrade_fix
            __switch_repo_to $TO
            end_change_alt_repo
            __do_upgrade
            docmd epm install rpm apt $(get_fix_release_pkg "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            __check_system "$TO"
            # will update to kernel 6.6
            docmd epm update-kernel || fatal
            ;;
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
        "p9 p8"|"c8.1 c8"|"c8.1 p8"|"p8 p8")
            confirm_info "Downgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install $(get_fix_release_pkg "$FROM")
            __switch_repo_to $TO
            docmd epm downgrade rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            if epm installed libcrypt >/dev/null ; then
                # glibc-core coflicts libcrypt
                docmd epm downgrade apt rpm pam pam0_passwdqc glibc-core libcrypt- || fatal
            fi
            docmd epm $force_yes $non_interactive downgrade || fatal "Check the error and run '# epm downgrade'"
            end_change_alt_repo
            __check_system "$TO"
            docmd epm upgrade || fatal
            ;;
        "p9 c8"|"p9 c8.1"|"p9 c8.2")
            confirm_info "Downgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install $(get_fix_release_pkg "$FROM")
            __switch_repo_to $TO
            docmd epm downgrade rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            #if epm installed libcrypt >/dev/null ; then
            #    # glibc-core coflicts libcrypt
            #    docmd epm downgrade apt rpm pam pam0_passwdqc glibc-core libcrypt- || fatal
            #fi
            docmd epm $force_yes $non_interactive downgrade || fatal "Check the error and run '# epm downgrade'"
            end_change_alt_repo
            __check_system "$TO"
            docmd epm upgrade || fatal
            ;;
449
        "p10 p9"|"p11 p9")
450 451 452 453 454 455 456 457 458
            confirm_info "Downgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install $(get_fix_release_pkg "$FROM")
            __switch_repo_to $TO
            docmd epm downgrade rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            docmd epm $force_yes $non_interactive downgrade || fatal "Check the error and run '# epm downgrade'"
            end_change_alt_repo
            __check_system "$TO"
            docmd epm upgrade || fatal
            ;;
459
        "Sisyphus p8"|"Sisyphus p9"|"Sisyphus p10"|"Sisyphus p11"|"Sisyphus c8"|"Sisyphus c8.1"|"Sisyphus c9f2"|"Sisyphus c10f1"|"Sisyphus c10f2"|"Sisyphus c10f3")
460 461
            confirm_info "Downgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install $(get_fix_release_pkg "$FROM")
462
            if [ $TO = "p11" ]; then __sisyphus_downgrade_fix; fi
463
            __switch_repo_to $TO
464
            docmd epm downgrade rpm apt $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
465 466 467 468 469
            docmd epm $force_yes $non_interactive downgrade || fatal "Check the error and run '# epm downgrade'"
            end_change_alt_repo
            __check_system "$TO"
            docmd epm upgrade || fatal
            ;;
470
        "p8 Sisyphus"|"p9 Sisyphus"|"p10 Sisyphus"|"p11 Sisyphus"|"Sisyphus Sisyphus")
471 472 473 474 475
            confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
            docmd epm install rpm apt $(get_fix_release_pkg "$FROM") || fatal
            docmd epm upgrade || fatal
            # TODO: epm_reposwitch??
            __replace_alt_version_in_repo "$FROM/branch/" "$TO/"
476
            __switch_repo_to $TO
477
            [ -s /etc/rpm/macros.d/p10 ] && rm -fv /etc/rpm/macros.d/p10
478
            [ -s /etc/rpm/macros.d/p11 ] && rm -fv /etc/rpm/macros.d/p11
479 480 481 482 483 484 485 486 487 488 489 490 491 492
            __epm_ru_update || fatal
            docmd epm fix || fatal
            docmd epm install $(get_fix_release_pkg --force "$TO") || fatal "Check the errors and run '# epm release-upgrade' again"
            #local ADDPKG
            #ADDPKG=$(epm -q --short make-initrd sssd-ad 2>/dev/null)
            #docmd epm install librpm7 librpm rpm apt $ADDPKG $(get_fix_release_pkg --force "$TO") ConsoleKit2- || fatal "Check an error and run again"
            end_change_alt_repo
            docmd epm $force_yes $non_interactive upgrade || fatal "Check the error and run '# epm release-upgrade' again or just '# epm upgrade'"
            docmd epm $force_yes $non_interactive downgrade || fatal "Check the error and run '# epm downgrade'"
            __check_system "$TO"
            docmd epm update-kernel || fatal
            ;;
        *)
            if [ "$FROM" = "$TO" ] ; then
493
                info 'It seems your system is already $DISTRNAME $TO'
494
            else
495
                warning 'Unknown distro version. Have no idea how to switch from $DISTRNAME $FROM to $DISTRNAME $TO.'
496 497 498 499 500 501 502 503
            fi
            end_change_alt_repo
            info "Try run f.i. '# epm release-upgrade p10' or '# epm release-downgrade p9' or '# epm release-upgrade Sisyphus'"
            info "Also possible you need install altlinux-release-p? package for correct distro version detecting"
            return 1
    esac
    docmd epm clean
    docmd epm update
504 505
}

506 507
epm_release_upgrade()
{
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
    assure_root
    assure_safe_run
    info "Starting upgrade/switch whole system to other release"
    info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"

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

    case $BASEDISTRNAME in
    "alt")
        __epm_ru_update || fatal

        # TODO: remove this hack (or move it to distro_info)
        # 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"
528
                info 'Detected running $DISTRNAME $DISTRVERSION (according to using repos)'
529 530 531 532
            fi
        fi

        TARGET=""
533
        [ -n "$3" ] && fatal 'Too many args: $*'
534 535
        if [ -n "$2" ] ; then
            DISTRVERSION="$1"
536
            info 'Force current distro version as $DISTRVERSION'
537 538 539 540 541
            TARGET="$2"
        elif [ -n "$1" ] ; then
            TARGET="$1"
        fi

542
        [ "$TARGET" = "Sisyphus" ] && info "Check also https://www.altlinux.org/Update/Sisyphus"
543 544 545 546 547

        [ -n "$TARGET" ] || TARGET="$(get_next_release $DISTRVERSION)"

        __alt_repofix

548
        __switch_alt_to_distro $DISTRVERSION $TARGET && info 'Done. The system has been successfully upgraded to the next release $TO.'
549 550 551 552 553 554 555 556 557 558 559 560 561 562

        return 0
        ;;
    *)
        ;;
    esac

    case $DISTRNAME in
    "Mageia")
        epm repo remove all
        sudocmd urpmi.addmedia --distrib --mirrorlist 'http://mirrors.mageia.org/api/mageia.8.$DISTRARCH.list'
        sudocmd urpmi --auto-update $non_interactive $force
        return
        ;;
563 564
     "OpenMandrivaLx")
        sudocmd dnf clean all
565
        sudocmd dnf distro-sync --allowerasing
566
        return
567
        ;;
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
    "ROSA")
        # TODO: move to distro related upgrade
        #epm repo remove all
        # FIXME: don't work:
        #epm repo add "http://mirror.rosalinux.ru/rosa/rosa2021.1/repository/$DISTRARCH"
        #showcmd urpmi.addmedia --distrib http://mirror.yandex.ru/mandriva/devel/2010.2/i586/
        #sudocmd urpmi --auto-update --replacefiles
        return
        ;;
    *)
        ;;
    esac

    case $PMTYPE in
    apt-rpm)
        #docmd epm update
584
        info 'Have no idea how to upgrade $DISTRNAME. It is possible you need use release-downgrade'
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
        ;;
    *-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 do 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
        ;;
    dnf-rpm)
        if [ "$DISTRNAME/$DISTRVERSION" = "CentOS/8" ] ; then
            if [ "$1" = "RockyLinux" ] ; then
                info "https://github.com/rocky-linux/rocky-tools/tree/main/migrate2rocky/"
                confirm_info "Switch to Rocky Linux 8.x"
                cd /tmp
                docmd epm install git
                sudocmd git clone https://github.com/rocky-linux/rocky-tools.git || fatal
                sudocmd bash rocky-tools/migrate2rocky/migrate2rocky.sh -r
                exit
            fi

            if [ "$1" = "OracleLinux" ] ; then
                info "Check https://t.me/srv_admin/1630"
                confirm_info "Switch to Oracle Linux 8.x"
                cd /tmp
                docmd epm install git
                sudocmd sed -i -r \
                    -e 's!^mirrorlist=!#mirrorlist=!' \
                    -e 's!^#?baseurl=http://(mirror|vault).centos.org/\$contentdir/\$releasever/!baseurl=https://dl.rockylinux.org/vault/centos/8.5.2111/!i' \
                        /etc/yum.repos.d/CentOS-*.repo
                sudocmd git clone https://github.com/oracle/centos2ol.git || fatal
                a= bash centos2ol/centos2ol.sh
                exit
            fi

            info "Check https://www.cyberciti.biz/howto/upgrade-migrate-from-centos-8-to-centos-stream-conversion/"
            confirm_info "Switch to CentOS Stream?"
            sudocmd sed -i -r \
                    -e 's!^mirrorlist=!#mirrorlist=!' \
                    -e 's!^#?baseurl=http://(mirror|vault).centos.org/\$contentdir/\$releasever/!baseurl=https://dl.rockylinux.org/vault/centos/8.5.2111/!i' \
                        /etc/yum.repos.d/CentOS-*.repo
            docmd epm install centos-release-stream
            sudocmd dnf swap centos-{linux,stream}-repos
            sudocmd dnf distro-sync
            info "You can run '# epm autoorphans' to remove orphaned packages"
            exit
        fi

        if [ "$DISTRNAME" = "RockyLinux" ] ; then
            sudocmd dnf --refresh upgrade || fatal
            sudocmd dnf clean all
            info "Check https://www.centlinux.com/2022/07/upgrade-your-servers-from-rocky-linux-8-to-9.html"
            info "For upgrading your yum repositories from Rocky Linux 8 to 9 ..."
            epm install "https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/Packages/r/rocky-gpg-keys*.rpm" || fatal
            epm install "https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/Packages/r/rocky-repos*.rpm" "https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/Packages/r/rocky-release*.rpm" || fatal

            # hack (TODO)
            DV=$(echo "$DISTRVERSION" | sed -e "s|\..*||")
            local RELEASEVER="$1"
            [ -n "$RELEASEVER" ] || RELEASEVER=$(($DV + 1))
651
            confirm_info 'Upgrade to $DISTRNAME/$RELEASEVER'
652

653
            sudocmd dnf distro-sync -y --releasever=$RELEASEVER --allowerasing --setopt=deltarpm=false
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
            sudocmd rpm --rebuilddb
            epm upgrade
            info "You can run '# epm autoorphans' to remove orphaned packages"
            info "Use # dnf module reset <module> to resolve 'nothing provides module' error"
            exit
        fi

        info "Check https://fedoraproject.org/wiki/DNF_system_upgrade for an additional info"
        #docmd epm install epel-release yum-utils
        sudocmd dnf --refresh upgrade || fatal
        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"
670
        confirm_info 'Upgrade to $DISTRNAME/$RELEASEVER'
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
        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 "You can run '# epm autoorphans' to remove orphaned packages"
        ;;
    zypper-rpm)
        docmd epm repolist
        # TODO: move to distro related upgrade
        # 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)
        docmd epm Upgrade
        ;;
    conary)
        docmd epm Upgrade
        ;;
    emerge)
        docmd epm Upgrade
        ;;
    guix)
        sudocmd guix pull --verbose
        ;;
    *)
702
        fatal 'Have no suitable command for $PMTYPE'
703 704
        ;;
    esac
705 706

}