epm-release_upgrade 11.1 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2013, 2016, 2017, 2019  Etersoft
# Copyright (C) 2013, 2016, 2017, 2019  Vitaly Lipatov <lav@etersoft.ru>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# 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
# (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
# GNU Affero General Public License for more details.
#
# 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/>.
#

20 21
load_helper epm-query

22 23 24 25 26 27 28 29 30
confirm_info()
{
	info "$*"
	if [ -z "$non_interactive" ] ; then
		confirm "Are you sure? [y/N]" || fatal "Exiting"
	fi

}

31 32 33 34 35 36 37 38 39
__replace_text_in_alt_repo()
{
	local i
	for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
		[ -s "$i" ] || continue
		regexp_subst "$1" "$i"
	done
}

40 41 42 43 44
__wcount()
{
	echo "$*" | wc -w
}

45 46
__detect_alt_release_by_repo()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
47 48
	local BRD=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list \
		| grep -v "^#" \
49 50
		| grep "[tp][5-9]/branch/" \
		| sed -e "s|.*\([tp][5-9]\)/branch.*|\1|g" \
Vitaly Lipatov's avatar
Vitaly Lipatov committed
51
		| sort -u )
Vitaly Lipatov's avatar
Vitaly Lipatov committed
52
	if [ "$(__wcount $BRD)" = "1" ] ; then
53 54 55 56
		echo "$BRD"
		return
	fi

Vitaly Lipatov's avatar
Vitaly Lipatov committed
57 58 59 60 61
	local BRD=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list \
		| grep -v "^#" \
		| grep "Sisyphus/" \
		| sed -e "s|.*\(Sisyphus\).*|\1|g" \
		| sort -u )
Vitaly Lipatov's avatar
Vitaly Lipatov committed
62
	if [ "$(__wcount $BRD)" = "1" ] ; then
63 64 65 66 67 68 69
		echo "$BRD"
		return
	fi

	return 1
}

70 71 72 73
__replace_alt_version_in_repo()
{
	local i
	assure_exists apt-repo
74
	#echo "Upgrading $DISTRNAME from $1 to $2 ..."
Vitaly Lipatov's avatar
Vitaly Lipatov committed
75
	docmd apt-repo list | sed -e "s|\($1\)|{\1}->{$2}|g" | grep -E --color -- "$1"
76
	# ask and replace only we will have changes
Vitaly Lipatov's avatar
Vitaly Lipatov committed
77
	if a='' apt-repo list | grep -E -q -- "$1" ; then
78 79
		__replace_text_in_alt_repo "/^ *#/! s!$1!$2!g"
	fi
80 81 82
	docmd apt-repo list
}

83
__alt_repofix()
84
{
85
	local TO="$1"
86
	load_helper epm-repofix
87
	showcmd epm repofix
88
	(quiet=1 pkg_filenames='' epm_repofix >/dev/null)
89 90 91 92 93 94 95
	# replace sign name
	if [ -n "$TO" ] ; then
		__replace_text_in_alt_repo "/^ *#/! s!\[alt\]![$TO]!g"
		__replace_text_in_alt_repo "/^ *#/! s!\[sisyphus\]![$TO]!g"
		__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g"
		__replace_text_in_alt_repo "/^ *#/! s!\[[tpc][6-9]\]![$TO]!g"
	fi
96 97
}

98 99
__get_conflict_release_pkg()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
100
	epm qf --quiet --short /etc/fedora-release | head -n1
101 102
}

103 104
get_fix_release_pkg()
{
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
	local TOINSTALL=''

	local FORCE=''
	if [ "$1" == "--force" ] ; then
		FORCE="$1"
		shift
	fi

	local TO="$1"

	if [ "$TO" = "Sisyphus" ] ; then
		TO="sisyphus"
		echo "apt-conf-$TO"
	else
		echo "apt-conf-branch"
120
	fi
121 122 123 124 125 126 127 128 129 130 131 132 133 134

	if [ "$FORCE" == "--force" ] ; then
		# assure we have set needed release
		TOINSTALL="altlinux-release-$TO"
	else
		# just assure we have /etc/altlinux-release and switched from sisyphus
		if [ ! -s /etc/altlinux-release ] || epmqf /etc/altlinux-release | grep -q sisyphus ; then
			TOINSTALL="altlinux-release-$TO"
		fi
	fi

	# workaround against obsoleted altlinux-release-sisyphus package from 2008 year
	[ "$TOINSTALL" = "altlinux-release-sisyphus" ] && TOINSTALL="branding-alt-sisyphus-release"

135
	# update if installed (just print package name here to include in the install list)
136
	epm --quiet --short -q alt-gpgkeys 2>/dev/null
137 138
	epm --quiet --short -q etersoft-gpgkeys 2>/dev/null

139 140 141 142 143 144 145 146 147
	if [ -n "$TOINSTALL" ] ; then
		echo "$TOINSTALL"

		# workaround against
		#    file /etc/fedora-release from install of altlinux-release-p8-20160414-alt1 conflicts with file from package branding-simply-linux-release-8.2.0-alt1
		# problem
		if __get_conflict_release_pkg | grep -q -v "^altlinux-release" && [ "$TOINSTALL" != "$(__get_conflict_release_pkg)" ] ; then
			echo $(__get_conflict_release_pkg)-
		fi
148
	fi
149 150
}

151 152
__update_to_the_distro()
{
153 154
	local TO="$1"
	case "$TO" in
155
		p7)
156
			__alt_repofix
157
			docmd epm update || fatal
158
			docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again"
159
			__alt_repofix $TO
160
			docmd epm update || fatal
161
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
162
			;;
163 164
		p8)
			__alt_repofix
165
			docmd epm update || fatal
166
			docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again"
167
			__alt_repofix $TO
168
			docmd epm update || fatal
169
			# sure we have systemd if systemd is running
170
			if is_installed systemd && is_active_systemd systemd ; then
171 172
				docmd epm install systemd || fatal
			fi
173
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
174
			;;
175 176 177 178 179 180 181 182 183 184 185
		p9)
			#docmd epm update || fatal
			#docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again"
			__alt_repofix $TO
			docmd epm update || fatal
			# sure we have systemd if systemd is running
			#if is_installed systemd && is_active_systemd systemd ; then
			#	docmd epm install systemd || fatal
			#fi
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
			;;
186
		Sisyphus)
187
			__alt_repofix
188
			docmd epm update || fatal
189 190 191
			#local ADDPKG
			#ADDPKG=$(epm -q --short make-initrd sssd-ad 2>/dev/null)
			#docmd epm install librpm7 librpm rpm apt $ADDPKG "$(get_fix_release_pkg --force "$TO")" ConsoleKit2- || fatal "Check an error and run again"
192
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade or just epm upgrade again"
193 194 195 196 197
			;;
		*)
	esac
}

198

199 200
__update_alt_to_next_distro()
{
201
	local TO="$2"
202
	local FROM="$1"
203
	[ -n "$TO" ] || TO="$FROM"
204 205
	info
 	case "$*" in
206
		"p6"|"p6 p7"|"t6 p7"|"c6 c7")
207
			TO="p7"
208
			confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
209
			docmd epm install rpm apt "$(get_fix_release_pkg "$FROM")" || fatal
210
			__replace_alt_version_in_repo "Sisyphus/" "$TO/branch/"
211 212
			__replace_alt_version_in_repo "$FROM/branch/" "$TO/branch/"
			__update_to_the_distro "$TO"
213 214 215
			docmd epm update-kernel
			info "Done."
			info "Run epm release-upgrade again for update to p8"
216
			;;
217
		"p7"|"p7 p8"|"t7 p8"|"c7 c8"|"p8 p8")
218
			TO="p8"
219
			confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
220
			docmd epm install rpm apt "$(get_fix_release_pkg "$FROM")" || fatal
221 222 223 224 225 226 227 228 229 230 231
			__replace_alt_version_in_repo "Sisyphus/" "$TO/branch/"
			__replace_alt_version_in_repo $FROM/branch/ $TO/branch/
			__update_to_the_distro $TO
			docmd epm update-kernel || fatal
			info "Done."
			;;
		"p8"|"p8 p9"|"t8 p9"|"c8 c9"|"p9 p9")
			TO="p9"
			confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
			docmd epm install rpm apt "$(get_fix_release_pkg "$FROM")" || fatal
			__replace_alt_version_in_repo "Sisyphus/" "$TO/branch/"
232 233
			__replace_alt_version_in_repo $FROM/branch/ $TO/branch/
			__update_to_the_distro $TO
234 235
			docmd epm update-kernel || fatal
			info "Done."
236 237
			;;
		"Sisyphus p8")
238
			TO="p8"
239
			confirm_info "Downgrade $DISTRNAME from $FROM to $TO ..."
240
			docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal
241
			__replace_alt_version_in_repo "$FROM/" "$TO/branch/"
242
			#__replace_text_in_alt_repo "/^ *#/! s!\[alt\]![$TO]!g"
243
			__update_to_the_distro $TO
244 245
			docmd epm downgrade || fatal
			info "Done."
246
			;;
247 248 249 250 251
		"Sisyphus p9")
			TO="p9"
			confirm_info "Downgrade $DISTRNAME from $FROM to $TO ..."
			docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal
			__replace_alt_version_in_repo "$FROM/" "$TO/branch/"
252
			#__replace_text_in_alt_repo "/^ *#/! s!\[alt\]![$TO]!g"
253 254 255 256 257
			__update_to_the_distro $TO
			docmd epm downgrade || fatal
			info "Done."
			;;
		"p8 Sisyphus"|"p9 Sisyphus"|"Sisyphus Sisyphus")
258
			TO="Sisyphus"
259
			confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
260
			docmd epm install rpm apt "$(get_fix_release_pkg "$FROM")" || fatal
261
			docmd epm upgrade || fatal
262
			__replace_alt_version_in_repo "$FROM/branch/" "$TO/"
263
			__alt_repofix "sisyphus"
264
			__update_to_the_distro $TO
265 266
			docmd epm update-kernel || fatal
			info "Done."
267
			;;
268
		*)
269 270 271 272 273
			if [ "$FROM" = "$TO" ] ; then
				info "It seems your system is already updated to newest $DISTRNAME $TO"
			else
				warning "Have no idea how to update from $DISTRNAME $FROM to $DISTRNAME $TO."
			fi
274
			info "Try run f.i. # epm release-upgrade p8 or # epm release-upgrade Sisyphus"
275
			info "Also possible you need install altlinux-release-p? package for correct distro version detecting"
276 277 278 279
			return 1
	esac
}

280 281
epm_release_upgrade()
{
282
	assure_root
Vitaly Lipatov's avatar
Vitaly Lipatov committed
283
	info "Starting upgrade whole system to the next release"
284
	info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"
285

286
	cd /tmp || fatal
287 288 289
	# TODO: it is possible eatmydata does not do his work
	export EPMNOEATMYDATA=1

290 291
	case $DISTRNAME in
	ALTLinux)
292
		docmd epm update || fatal
293 294 295

		# try to detect current release by repo
		if [ "$DISTRVERSION" = "Sisyphus" ] || [ -z "$DISTRVERSION" ] ; then
296 297 298 299 300 301
			local dv
			dv="$(__detect_alt_release_by_repo)"
			if [ -n "$dv" ] && [ "$dv" != "$DISTRVERSION" ] ; then
				DISTRVERSION="$dv"
				info "Detected running $DISTRNAME $DISTRVERSION (according to using repos)"
			fi
302 303 304 305 306 307 308
		fi

		# check forced target
		if [ -n "$pkg_filenames" ] ; then
			[ "$(__wcount $pkg_filenames)" = "1" ] || fatal "Too many args: $pkg_filenames"
		fi

309 310 311 312 313
		TARGET="$pkg_filenames"

		__alt_repofix


314
		# TODO: ask before upgrade
315
		__update_alt_to_next_distro $DISTRVERSION $TARGET
316 317 318 319 320 321 322 323
		return
		;;
	*)
		;;
	esac

	case $PMTYPE in
	apt-rpm)
324
		#docmd epm update
325
		info "Have no idea how to upgrade $DISTRNAME"
326
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
327
	*-dpkg)
328
		assure_exists do-release-upgrade update-manager-core
Vitaly Lipatov's avatar
Vitaly Lipatov committed
329
		sudocmd do-release-upgrade
330
		;;
331
	packagekit)
332 333
		docmd pkcon upgrade-system $pkg_filenames
		;;
334 335 336 337 338
	yum-rpm)
		docmd epm install rpm yum
		sudocmd yum clean all
		# TODO
		showcmd rpm -Uvh http://mirror.yandex.ru/fedora/linux/releases/16/Fedora/x86_64/os/Packages/fedora-release-16-1.noarch.rpm
Vitaly Lipatov's avatar
Vitaly Lipatov committed
339
		showcmd epm Upgrade
340
		;;
341 342 343
	dnf-rpm)
		info "Check https://fedoraproject.org/wiki/DNF_system_upgrade for an additional info"
		docmd epm install dnf
Vitaly Lipatov's avatar
Vitaly Lipatov committed
344
		#docmd epm install epel-release yum-utils
345
		sudocmd dnf --refresh upgrade
346 347
		sudocmd dnf clean all
		assure_exists dnf-plugin-system-upgrade
348
		sudocmd dnf upgrade --refresh
349
		local RELEASEVER="$pkg_filenames"
350 351
		[ -n "$RELEASEVER" ] || RELEASEVER=$(($DISTRVERSION + 1))
		#[ -n "$RELEASEVER" ] || fatal "Run me with new version"
352
		confirm_info "Upgrade to $DISTRNAME/$RELEASEVER"
353
		sudocmd dnf system-upgrade download --refresh --releasever=$RELEASEVER
354 355 356
		# TODO: from docs:
		# dnf system-upgrade reboot
		# FIXME: download all packages again
357
		sudocmd dnf distro-sync --releasever=$RELEASEVER
358 359
		info "Run epm autoorphans to remove orphaned packages"
		;;
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
	urpm-rpm)
		sudocmd urpmi.removemedia -av
		# TODO
		showcmd urpmi.addmedia --distrib http://mirror.yandex.ru/mandriva/devel/2010.2/i586/
		sudocmd urpmi --auto-update --replacefiles
		;;
	zypper-rpm)
		docmd epm repolist
		# TODO
		# sudocmd zypper rr <номер_репозитория>
		showcmd rr N
		showcmd epm ar http://mirror.yandex.ru/opensuse/distribution/11.1/repo/oss 11.1oss
		showcmd zypper ref
		docmd epm update
		docmd epm install rpm zypper
		docmd epm upgrade
		;;
	pacman)
378
		epm Upgrade
379
		;;
380 381 382
	conary)
		epm Upgrade
		;;
383 384 385 386 387 388
	emerge)
		epm Upgrade
		;;
	guix)
		sudocmd guix pull --verbose
		;;
389
	*)
390
		fatal "Have no suitable command for $PMTYPE"
391 392 393 394
		;;
	esac

}