epm-release_upgrade 7.69 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2013, 2016  Etersoft
# Copyright (C) 2013, 2016  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
__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
}

31 32 33 34 35
__wcount()
{
	echo "$*" | wc -w
}

36 37
__detect_alt_release_by_repo()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
38 39 40 41 42
	local BRD=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list \
		| grep -v "^#" \
		| grep "p[5-9]/branch/" \
		| sed -e "s|.*\(p[5-9]\)/branch.*|\1|g" \
		| sort -u )
43
	if [ $(__wcount $BRD) = "1" ] ; then
44 45 46 47
		echo "$BRD"
		return
	fi

Vitaly Lipatov's avatar
Vitaly Lipatov committed
48 49 50 51 52
	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 )
53
	if [ $(__wcount $BRD) = "1" ] ; then
54 55 56 57 58 59 60
		echo "$BRD"
		return
	fi

	return 1
}

61 62 63 64
__replace_alt_version_in_repo()
{
	local i
	assure_exists apt-repo
65 66
	#echo "Upgrading $DISTRNAME from $1 to $2 ..."
	docmd apt-repo list | sed -e "s|\($1\)|{\1}->{$2}|g" | egrep --color -- "$1"
67
	# ask and replace only we will have changes
68
	if a= apt-repo list | egrep -q -- "$1" ; then
69 70 71
		confirm "Are these correct changes? [y/N]" || fatal "Exiting"
		__replace_text_in_alt_repo "/^ *#/! s!$1!$2!g"
	fi
72 73 74
	docmd apt-repo list
}

75
__alt_repofix()
76
{
77
	load_helper epm-repofix
78 79
	showcmd epm repofix
	quiet=1 pkg_filenames= epm_repofix >/dev/null
80 81 82
	__replace_text_in_alt_repo "/^ *#/! s!\[p[6-9]\]![updates]!g"
}

83 84 85 86 87 88 89 90
get_fix_release_pkg()
{
	# TODO: check for version incompatibilities
	if epmqf /etc/altlinux-release | grep -q sisyphus ; then
		echo altlinux-release-$1
	fi
}

91 92 93 94 95
__update_to_the_distro()
{
	__alt_repofix
	case "$1" in
		p7)
96
			docmd epm update || fatal
97
			docmd epm install apt rpm apt-conf-branch $(get_fix_release_pkg p7) || fatal "Check an error and run epm release-upgrade again"
98
			__alt_repofix
99 100
			__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![p7]!g"
			docmd epm update || fatal
101
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
102
			;;
103
		p8)
104
			docmd epm update || fatal
105
			if ! docmd epm install apt rpm apt-conf-branch $(get_fix_release_pkg p8) ; then
106 107
				# Hack for error: execution of %post scriptlet from glibc-core-2.23-alt1.eter1
				docmd rpm -ev glibc-core-2.17 || fatal "Check an error and run epm release-upgrade again"
108
				docmd epm install apt rpm apt-conf-branch $(get_fix_release_pkg p8) || fatal "Check an error and run epm release-upgrade again"
109
			fi
110
			__alt_repofix
111
			__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![p8]!g"
112
			docmd epm update || fatal
113
			if is_installed systemd && is_active_systemd systemd ; then
114 115
				docmd epm install systemd || fatal
			fi
116
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
117
			;;
118 119
		Sisyphus)
			docmd epm update || fatal
120
			docmd epm install apt rpm librpm7 librpm apt-conf-sisyphus altlinux-release-sisyphus || fatal "Check an error and run again"
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
			;;
		*)
	esac
}

__update_alt_to_next_distro()
{
	local FROMTO=$(echo "$*" | sed -e "s| | to |")
	info
 	case "$*" in
		"p6"|"p6 p7")
			info "Upgrade $DISTRNAME from p6 to p7 ..."
			docmd epm install apt-conf-branch || fatal
			__replace_alt_version_in_repo p6/branch/ p7/branch/
			__update_to_the_distro p7
137 138 139
			docmd epm update-kernel
			info "Done."
			info "Run epm release-upgrade again for update to p8"
140 141 142
			;;
		"p7"|"p7 p8")
			info "Upgrade $DISTRNAME from p7 to p8 ..."
143
			docmd epm install apt-conf-branch $(get_fix_release_pkg p7) || fatal
144 145
			__replace_alt_version_in_repo p7/branch/ p8/branch/
			__update_to_the_distro p8
146 147
			docmd epm update-kernel || fatal
			info "Done."
148 149 150 151 152
			;;
		"Sisyphus p8")
			info "Downgrade $DISTRNAME from Sisyphus to p8 ..."
			docmd epm install apt-conf-branch || fatal
			__replace_alt_version_in_repo Sisyphus/ p8/branch/
153
			__replace_text_in_alt_repo "/^ *#/! s!\[alt\]![p8]!g"
154
			__update_to_the_distro p8
155 156
			docmd epm downgrade || fatal
			info "Done."
157 158 159 160 161 162
			;;
		"p8 Sisyphus")
			info "Upgrade $DISTRNAME from p8 to Sisyphus ..."
			docmd epm install apt-conf-branch || fatal
			docmd epm upgrade || fatal
			__replace_alt_version_in_repo p8/branch/ Sisyphus/
163 164
			__alt_repofix
			__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![alt]!g"
165
			__update_to_the_distro Sisyphus
166 167
			docmd epm update-kernel || fatal
			info "Done."
168
			;;
169
		*)
170
			warning "Have no idea how to update from $DISTRNAME $DISTRVERSION."
171
			info "Try run f.i. # epm release-upgrade p8 or # epm release-upgrade Sisyphus"
172
			info "Also possible you need install altlinux-release-p? package for correct distro version detecting"
173 174 175 176
			return 1
	esac
}

177 178
epm_release_upgrade()
{
179
	assure_root
Vitaly Lipatov's avatar
Vitaly Lipatov committed
180
	info "Starting upgrade whole system to the next release"
181
	info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"
182

183 184
	case $DISTRNAME in
	ALTLinux)
185 186
		docmd epm update
		docmd epm install apt rpm
187 188 189

		# try to detect current release by repo
		if [ "$DISTRVERSION" = "Sisyphus" ] || [ -z "$DISTRVERSION" ] ; then
190 191 192 193 194 195
			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
196 197
		fi

198 199
		__alt_repofix

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

		__update_alt_to_next_distro $DISTRVERSION $pkg_filenames
206 207 208 209 210 211 212 213
		return
		;;
	*)
		;;
	esac

	case $PMTYPE in
	apt-rpm)
214
		#docmd epm update
215
		info "Have no idea how to upgrade $DISTRNAME"
216
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
217
	*-dpkg)
218
		assure_exists do-release-upgrade update-manager-core
219 220 221 222 223 224 225 226 227
		sudocmd do-release-upgrade -d
		;;
	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
		docmd epm Upgrade
		;;
228 229 230 231 232 233 234
	dnf-rpm)
		info "Check https://fedoraproject.org/wiki/DNF_system_upgrade for an additional info"
		docmd epm install dnf
		sudocmd dnf clean all
		assure_exists dnf-plugin-system-upgrade
		sudocmd dnf system-upgrade
		local RELEASEVER="$pkg_filenames"
235 236 237
		[ -n "$RELEASEVER" ] || RELEASEVER=$(($DISTRVERSION + 1))
		#[ -n "$RELEASEVER" ] || fatal "Run me with new version"
		info "Upgrate to $DISTRNAME/$RELEASEVER"
238
		sudocmd dnf system-upgrade download --refresh --releasever=$RELEASEVER
239
		sudocmd dnf distro-sync --releasever=$RELEASEVER
240 241
		info "Run epm autoorphans to remove orphaned packages"
		;;
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
	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)
260
		epm Upgrade
261
		;;
262 263 264
	conary)
		epm Upgrade
		;;
265 266 267 268 269 270
	emerge)
		epm Upgrade
		;;
	guix)
		sudocmd guix pull --verbose
		;;
271
	*)
272
		fatal "Have no suitable command for $PMTYPE"
273 274 275 276
		;;
	esac

}