epm-upgrade 5.67 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
            try_change_alt_repo
            epm_addrepo "$@"
54 55
            __epm_update
            (pkg_names="$installlist" epm_install) || fatal "Can't update repo"
56 57
            epm_removerepo "$@"
            end_change_alt_repo
58

59 60 61
            return
        fi
    fi
62

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

69 70 71 72 73 74 75
    # 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

76
    info "Running command for upgrade packages"
77

78

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    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
99

100 101
    case $PMTYPE in
    apt-rpm|apt-dpkg)
102
        local APTOPTIONS="$dryrun $(subst_option non_interactive -y) $(subst_option verbose "-V -o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
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 143 144 145 146 147 148 149 150 151
        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"
        ;;
152 153
    choco)
        CMD="choco update all"
154 155 156
        ;;
    homebrew)
        #CMD="brew upgrade"
157
        sudocmd brew upgrade $(brew outdated)
158 159 160 161 162 163 164 165 166 167 168 169 170 171
        return
        ;;
    opkg)
        CMD="opkg upgrade"
        ;;
    eopkg)
        CMD="eopkg upgrade"
        ;;
    slackpkg)
        CMD="/usr/sbin/slackpkg upgrade-all"
        ;;
    guix)
        CMD="guix package -u"
        ;;
172
    appget)
173 174
        CMD="$PMTYPE update-all"
        ;;
175 176 177 178 179 180 181
    winget)
        if [ -z "$1" ] ; then
            sudocmd winget upgrade --all
            return
        fi
        CMD="winget upgrade"
        ;;
182 183 184 185 186 187 188 189
    aptcyg)
        # shellcheck disable=SC2046
        docmd_foreach "epm install" $(short=1 epm packages)
        return
        ;;
    xbps)
        CMD="xbps-install -Su"
        ;;
190 191 192
    nix)
        CMD="nix-env -u $dryrun"
        ;;
193 194 195
    termux-pkg)
        CMD="pkg upgrade"
        ;;
196 197 198 199
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
    esac
200

201
    sudocmd $CMD "$@"
202

203
}