epm-upgrade 6.28 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2014, 2016, 2019, 2021  Etersoft
# Copyright (C) 2012, 2014, 2016, 2019, 2021  Vitaly Lipatov <lav@etersoft.ru>
5
#
6 7 8
# 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
9 10 11 12 13
# (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
14
# GNU Affero General Public License for more details.
15
#
16 17
# 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/>.
18 19
#

20
load_helper epm-check_updated_repo
21
load_helper epm-sh-warmup
22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

__check_upgrade_conditions()
{
    #[ "$BASEDISTRNAME" = "alt" ] || return 0
    [ "$DISTRVERSION" = "Sisyphus" ] || return 0

    # fast skip if already updated
    [ -L "/bin" ] && return 0

    # https://www.altlinux.org/Usrmerge
    epm status --installed filesystem 3.1 && return 0
    info "Installing usrmerge-hier-convert to merge file hierarhy, check https://www.altlinux.org/Usrmerge."
    epm upgrade vim-minimal vim-console
    epm install usrmerge-hier-convert
    return 0
}


41
epm_upgrade()
42
{
43
    local CMD
44

45 46
    # it is useful for first time running
    update_repo_if_needed
47

48
    warmup_bases
49

50 51 52 53 54 55 56
    if [ "$BASEDISTRNAME" = "alt" ] ; then
        load_helper epm-sh-altlinux
        if tasknumber "$@" >/dev/null ; then
            load_helper epm-addrepo
            load_helper epm-reposave
            load_helper epm-removerepo
            load_helper epm-Install
57

58 59 60 61 62 63 64 65 66 67 68
            local installlist="$(get_task_packages $*)"
            # hack: drop -devel packages to avoid package provided by multiple packages
            installlist="$(estrlist reg_exclude ".*-devel .*-devel-static" "$installlist")"
            [ -n "$verbose" ] && info "Packages from task(s): $installlist"
            # install only installed packages (simulate upgrade packages)
            installlist="$(get_only_installed_packages "$installlist")"
            [ -n "$verbose" ] && info "Packages to upgrade: $installlist"
            if [ -z "$installlist" ] ; then
                warning "There is no installed packages for upgrade from task $*"
                return 22
            fi
69

70 71
            try_change_alt_repo
            epm_addrepo "$@"
72 73
            __epm_update
            (pkg_names="$installlist" epm_install) || fatal "Can't update repo"
74 75
            epm_removerepo "$@"
            end_change_alt_repo
76

77 78
            return
        fi
79

80 81 82
        if [ -z "$*" ] ; then
            __check_upgrade_conditions || fatal "upgrade conditions is not satisfied."
        fi
83
    fi
84

85 86 87 88 89
    # Solus supports upgrade for a package (with all dependencies)
    if [ -n "$1" ] && [ "$DISTRNAME" = "Solus" ] ; then
        sudocmd eopkg upgrade "$@"
        return
    fi
90

91 92 93 94 95 96 97
    # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
    if [ -n "$pkg_urls" ] ; then
        info "Downloading packages assigned to upgrade ..."
        load_helper epm-download
        __handle_pkg_urls_to_install
    fi

98
    info "Running command for upgrade packages"
99

100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    case $PMTYPE in
        *-rpm)
            # upgrade only install files from the list
            if [ -n "$pkg_files" ] ; then
                load_helper epm-install
                #sudocmd rpm -Fvh $pkg_files
                (pkg_files=$pkg_files force="$force -F" epm_install)
                return
            elif [ -n "$pkg_names" ] ; then
                # hack for https://bugzilla.altlinux.org/41225
                case "$pkg_names" in
                    -*)
                        fatal "Option $pkg_names is not allowed here"
                esac
                load_helper epm-install
                (pkg_names=$(get_only_installed_packages $pkg_names) epm_install)
                return
            fi
        ;;
    esac
121

122 123
    case $PMTYPE in
    apt-rpm|apt-dpkg)
124
        local APTOPTIONS="$dryrun $(subst_option non_interactive -y) $(subst_option verbose "-V -o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
125 126 127 128 129 130 131 132 133 134 135 136
        CMD="apt-get $APTOPTIONS $noremove $force_yes dist-upgrade"
        ;;
    aptitude-dpkg)
        CMD="aptitude dist-upgrade"
        ;;
    packagekit)
        docmd pkcon update
        return
        ;;
    yum-rpm)
        local OPTIONS="$(subst_option non_interactive -y)"
        # can do update repobase automagically
137
        CMD="yum $OPTIONS upgrade $*"
138 139 140
        ;;
    dnf-rpm)
        local OPTIONS="$(subst_option non_interactive -y)"
141
        CMD="dnf $OPTIONS upgrade $*"
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 171 172 173
        ;;
    snappy)
        CMD="snappy update"
        ;;
    urpm-rpm)
        # or --auto-select --replace-files
        CMD="urpmi --update --auto-select $*"
        ;;
    zypper-rpm)
        CMD="zypper $(subst_option non_interactive --non-interactive) dist-upgrade"
        ;;
    pacman)
        CMD="pacman -S -u $force"
        ;;
    aura)
        CMD="aura -A -u"
        ;;
    emerge)
        CMD="emerge -NuDa world"
        ;;
    conary)
        CMD="conary updateall"
        ;;
    pkgsrc)
        CMD="freebsd-update fetch install"
        ;;
    pkgng)
        CMD="pkg upgrade"
        ;;
    apk)
        CMD="apk upgrade"
        ;;
174 175
    choco)
        CMD="choco update all"
176 177 178
        ;;
    homebrew)
        #CMD="brew upgrade"
179
        sudocmd brew upgrade $(brew outdated)
180 181 182 183 184 185 186 187 188 189 190 191 192 193
        return
        ;;
    opkg)
        CMD="opkg upgrade"
        ;;
    eopkg)
        CMD="eopkg upgrade"
        ;;
    slackpkg)
        CMD="/usr/sbin/slackpkg upgrade-all"
        ;;
    guix)
        CMD="guix package -u"
        ;;
194
    appget)
195 196
        CMD="$PMTYPE update-all"
        ;;
197 198 199 200 201 202 203
    winget)
        if [ -z "$1" ] ; then
            sudocmd winget upgrade --all
            return
        fi
        CMD="winget upgrade"
        ;;
204 205 206 207 208 209 210 211
    aptcyg)
        # shellcheck disable=SC2046
        docmd_foreach "epm install" $(short=1 epm packages)
        return
        ;;
    xbps)
        CMD="xbps-install -Su"
        ;;
212 213 214
    nix)
        CMD="nix-env -u $dryrun"
        ;;
215 216 217
    termux-pkg)
        CMD="pkg upgrade"
        ;;
218 219 220 221
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
    esac
222

223
    sudocmd $CMD "$@"
224

225
}