epm-upgrade 3.87 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 29

	# it is useful for first time running
	update_repo_if_needed

30
	warmup_bases
31 32 33

	if [ "$DISTRNAME" = "ALTLinux" ] ; then
		load_helper epm-sh-altlinux
34
		if tasknumber "$@" >/dev/null ; then
35
			load_helper epm-addrepo
36
			load_helper epm-reposave
37 38
			load_helper epm-removerepo
			load_helper epm-Install
39 40

			try_change_alt_repo
41
			epm_addrepo "$@"
42
			local installlist="$(get_task_packages $*)"
43 44
			# hack: drop -devel packages to avoid package provided by multiple packages
			installlist="$(estrlist reg_exclude ".*-devel .*-devel-static" "$installlist")"
45 46
			[ -n "$verbose" ] && info "Packages from task(s): $installlist"
			# install only installed packages (simulate upgrade packages)
47
			installlist="$(get_only_installed_packages "$installlist")"
48
			[ -n "$verbose" ] && info "Packages to upgrade: $installlist"
49
			(pkg_names="$installlist" epm_Install) || fatal "Can't update repo"
50
			epm_removerepo "$@"
51 52
			end_change_alt_repo

53 54 55 56
			return
		fi
	fi

Vitaly Lipatov's avatar
Vitaly Lipatov committed
57
	info "Running command for upgrade packages"
58

59 60 61 62 63 64 65 66 67
	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
68 69 70 71 72
				# hack for https://bugzilla.altlinux.org/41225
				case "$pkg_names" in
					-*)
						fatal "Option $pkg_names is not allowed here"
				esac
73 74 75 76 77 78 79
				load_helper epm-install
				(pkg_names=$(get_only_installed_packages $pkg_names) epm_install)
				return
			fi
		;;
	esac

80
	case $PMTYPE in
81
	apt-rpm|apt-dpkg)
82
		local APTOPTIONS="$(subst_option non_interactive -y) $(subst_option verbose "-o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
83
		CMD="apt-get $APTOPTIONS $noremove $force_yes dist-upgrade"
84
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
85 86 87
	aptitude-dpkg)
		CMD="aptitude dist-upgrade"
		;;
88
	packagekit)
89 90 91
		docmd pkcon update
		return
		;;
92
	yum-rpm)
93
		local OPTIONS="$(subst_option non_interactive -y)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
94
		# can do update repobase automagically
95
		CMD="yum $OPTIONS update $*"
96
		;;
97
	dnf-rpm)
98
		local OPTIONS="$(subst_option non_interactive -y)"
99
		CMD="dnf $OPTIONS distro-sync $*"
100
		;;
101 102 103
	snappy)
		CMD="snappy update"
		;;
104
	urpm-rpm)
105
		# or --auto-select --replace-files
106
		CMD="urpmi --update --auto-select $*"
107 108
		;;
	zypper-rpm)
109
		CMD="zypper dist-upgrade"
110
		;;
111
	pacman)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
112
		CMD="pacman -S -u $force"
113
		;;
114 115 116
	aura)
		CMD="aura -A -u"
		;;
117 118 119
	emerge)
		CMD="emerge -NuDa world"
		;;
120 121 122
	conary)
		CMD="conary updateall"
		;;
123
	pkgsrc)
124 125
		CMD="freebsd-update fetch install"
		;;
126 127 128
	pkgng)
		CMD="pkg upgrade"
		;;
129 130 131
	chocolatey)
		CMD="chocolatey update all"
		;;
132
	homebrew)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
133
		#CMD="brew upgrade"
134
		docmd "brew upgrade $(brew outdated)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
135
		return
136
		;;
137 138
	opkg)
		CMD="opkg upgrade"
139
		;;
140
	slackpkg)
141
		CMD="/usr/sbin/slackpkg upgrade-all"
142
		;;
143 144 145
	guix)
		CMD="guix package -u"
		;;
146 147 148
	appget|winget)
		CMD="$PMTYPE update-all"
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
149
	aptcyg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
150
		# shellcheck disable=SC2046
Vitaly Lipatov's avatar
Vitaly Lipatov committed
151 152 153
		docmd_foreach "epm install" $(short=1 epm packages)
		return
		;;
154 155 156
	xbps)
		CMD="xbps-install -Su"
		;;
157
	*)
158
		fatal "Have no suitable command for $PMTYPE"
159
		;;
160
	esac
161

162
	sudocmd $CMD "$@"
163

164
}