epm-upgrade 4.08 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 [ "$DISTRNAME" = "ALTLinux" ] || [ "$DISTRNAME" = "ALTServer" ] ; 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

Vitaly Lipatov's avatar
Vitaly Lipatov committed
62
	info "Running command for upgrade packages"
63

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

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

167
	sudocmd $CMD "$@"
168

169
}