epm-upgrade 5.39 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
epm_upgrade()
24
{
25
    local CMD
26

27 28
    # it is useful for first time running
    update_repo_if_needed
29

30
    warmup_bases
31

32 33 34 35 36 37 38
    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
39

40 41 42 43 44 45 46 47 48 49 50
            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
51

52 53 54 55 56
            try_change_alt_repo
            epm_addrepo "$@"
            (pkg_names="$installlist" epm_Install) || fatal "Can't update repo"
            epm_removerepo "$@"
            end_change_alt_repo
57

58 59 60
            return
        fi
    fi
61

62 63 64 65 66
    # Solus supports upgrade for a package (with all dependencies)
    if [ -n "$1" ] && [ "$DISTRNAME" = "Solus" ] ; then
        sudocmd eopkg upgrade "$@"
        return
    fi
67

68
    info "Running command for upgrade packages"
69

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    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
90

91 92
    case $PMTYPE in
    apt-rpm|apt-dpkg)
93
        local APTOPTIONS="$(subst_option non_interactive -y) $(subst_option verbose "-V -o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
        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
        CMD="yum $OPTIONS update $*"
        ;;
    dnf-rpm)
        local OPTIONS="$(subst_option non_interactive -y)"
        CMD="dnf $OPTIONS distro-sync $*"
        ;;
    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"
        ;;
143 144
    choco)
        CMD="choco update all"
145 146 147
        ;;
    homebrew)
        #CMD="brew upgrade"
148
        sudocmd brew upgrade $(brew outdated)
149 150 151 152 153 154 155 156 157 158 159 160 161 162
        return
        ;;
    opkg)
        CMD="opkg upgrade"
        ;;
    eopkg)
        CMD="eopkg upgrade"
        ;;
    slackpkg)
        CMD="/usr/sbin/slackpkg upgrade-all"
        ;;
    guix)
        CMD="guix package -u"
        ;;
163
    appget)
164 165
        CMD="$PMTYPE update-all"
        ;;
166 167 168 169 170 171 172
    winget)
        if [ -z "$1" ] ; then
            sudocmd winget upgrade --all
            return
        fi
        CMD="winget upgrade"
        ;;
173 174 175 176 177 178 179 180
    aptcyg)
        # shellcheck disable=SC2046
        docmd_foreach "epm install" $(short=1 epm packages)
        return
        ;;
    xbps)
        CMD="xbps-install -Su"
        ;;
181 182 183
    nix)
        CMD="nix-env -u $dryrun"
        ;;
184 185 186
    termux-pkg)
        CMD="pkg upgrade"
        ;;
187 188 189 190
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
    esac
191

192
    sudocmd $CMD "$@"
193

194
}