epm-upgrade 4.23 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
	if [ "$BASEDISTRNAME" = "alt" ] ; then
33
		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
			local installlist="$(get_task_packages $*)"
41 42
			# hack: drop -devel packages to avoid package provided by multiple packages
			installlist="$(estrlist reg_exclude ".*-devel .*-devel-static" "$installlist")"
43 44
			[ -n "$verbose" ] && info "Packages from task(s): $installlist"
			# install only installed packages (simulate upgrade packages)
45
			installlist="$(get_only_installed_packages "$installlist")"
46
			[ -n "$verbose" ] && info "Packages to upgrade: $installlist"
47 48
			if [ -z "$installlist" ] ; then
				warning "There is no installed packages for upgrade from task $*"
49
				return 22
50 51 52 53
			fi

			try_change_alt_repo
			epm_addrepo "$@"
54
			(pkg_names="$installlist" epm_Install) || fatal "Can't update repo"
55
			epm_removerepo "$@"
56 57
			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

Vitaly Lipatov's avatar
Vitaly Lipatov committed
68
	info "Running command for upgrade packages"
69

70 71 72 73 74 75 76 77 78
	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
79 80 81 82 83
				# hack for https://bugzilla.altlinux.org/41225
				case "$pkg_names" in
					-*)
						fatal "Option $pkg_names is not allowed here"
				esac
84 85 86 87 88 89 90
				load_helper epm-install
				(pkg_names=$(get_only_installed_packages $pkg_names) epm_install)
				return
			fi
		;;
	esac

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

176
	sudocmd $CMD "$@"
177

178
}