epm-release_upgrade 7.84 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2013, 2016, 2017  Etersoft
# Copyright (C) 2013, 2016, 2017  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
	local BRD=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list \
		| grep -v "^#" \
40 41
		| grep "[tp][5-9]/branch/" \
		| sed -e "s|.*\([tp][5-9]\)/branch.*|\1|g" \
Vitaly Lipatov's avatar
Vitaly Lipatov committed
42
		| sort -u )
Vitaly Lipatov's avatar
Vitaly Lipatov committed
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 )
Vitaly Lipatov's avatar
Vitaly Lipatov committed
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
	#echo "Upgrading $DISTRNAME from $1 to $2 ..."
Vitaly Lipatov's avatar
Vitaly Lipatov committed
66
	docmd apt-repo list | sed -e "s|\($1\)|{\1}->{$2}|g" | grep -E --color -- "$1"
67
	# ask and replace only we will have changes
Vitaly Lipatov's avatar
Vitaly Lipatov committed
68
	if a='' apt-repo list | grep -E -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
	showcmd epm repofix
Vitaly Lipatov's avatar
Vitaly Lipatov committed
79
	quiet=1 pkg_filenames='' epm_repofix >/dev/null
80
	__replace_text_in_alt_repo "/^ *#/! s!\[[tp][6-9]\]![updates]!g"
81 82
}

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
__update_to_the_distro()
{
93
	local TO="$1"
94
	__alt_repofix
95
	case "$TO" in
96
		p7)
97
			docmd epm update || fatal
Vitaly Lipatov's avatar
Vitaly Lipatov committed
98
			docmd epm install apt rpm apt-conf-branch "$(get_fix_release_pkg "$TO")" || fatal "Check an error and run epm release-upgrade again"
99
			__alt_repofix
100
			__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g"
101
			docmd epm update || fatal
102
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
103
			;;
104
		p8)
105
			docmd epm update || fatal
Vitaly Lipatov's avatar
Vitaly Lipatov committed
106
			if ! docmd epm install apt rpm apt-conf-branch "$(get_fix_release_pkg "$TO")" ; then
107 108
				# 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"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
109
				docmd epm install apt rpm apt-conf-branch "$(get_fix_release_pkg "$TO")" || fatal "Check an error and run epm release-upgrade again"
110
			fi
111
			__alt_repofix
112
			__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g"
113
			docmd epm update || fatal
114
			if is_installed systemd && is_active_systemd systemd ; then
115 116
				docmd epm install systemd || fatal
			fi
117
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
118
			;;
119 120
		Sisyphus)
			docmd epm update || fatal
121
			docmd epm install apt rpm librpm7 librpm apt-conf-sisyphus altlinux-release-sisyphus || fatal "Check an error and run again"
122 123 124 125 126 127 128 129
			docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
			;;
		*)
	esac
}

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

183 184
epm_release_upgrade()
{
185
	assure_root
Vitaly Lipatov's avatar
Vitaly Lipatov committed
186
	info "Starting upgrade whole system to the next release"
187
	info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"
188

189 190
	case $DISTRNAME in
	ALTLinux)
191 192
		docmd epm update
		docmd epm install apt rpm
193 194 195

		# try to detect current release by repo
		if [ "$DISTRVERSION" = "Sisyphus" ] || [ -z "$DISTRVERSION" ] ; then
196 197 198 199 200 201
			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
202 203
		fi

204 205
		__alt_repofix

206 207 208 209 210 211
		# 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
212 213 214 215 216 217 218 219
		return
		;;
	*)
		;;
	esac

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

}