summaryrefslogtreecommitdiff
path: root/Documentation/maintainers/bump_new_revision.sh
blob: 10f86300cbb3a05ece2cca48d75d43bcffec20c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/usr/bin/env bash
###############################################################################
# KDE Version bumper
# Created by Gentoo kde-herd
# This tool is meant to be used for ease of version bumping for KDE ebuilds
# v 0.21
###############################################################################
# functions
###############################################################################
# took lines from slots which does not point to other slots
get_packages_from_slot() {
	local SLOTFILE

	# if user specify set then use desired one only
	find ${PORTDIR_BUMPING}/sets/ -maxdepth 1 -type f -name ${SET}\*-${SLOT} -print \
			| grep -v kdedeps | while read SLOTFILE; do
		echo ${SLOTFILE} # debug
		# remove empty lines, another slots and comments, replace slot by
		# version.ebuild
		cat ${SLOTFILE} |grep -v ^@ |grep -v ^$ |grep -v ^#| grep 'kde-base/' \
			|sed -e "s/:${SLOT}//g" \
			>> ${TMPFILE}
		# metas bumping.
		find ${PORTDIR_BUMPING} -mindepth 2 -maxdepth 2 -type d -name \*-meta |sed -e "s:${PORTDIR_BUMPING}::" \
			>> ${TMPFILE}
	done
}

# update package keywords from anything to testing
update_package_keywords() {
	ekeyword ~all ${1}
}

# regenerate manifest files
update_package_manifest() {
	cd "${PORTDIR_BUMPING}"/"${EBUILD_BASEDIR}"/
	repoman manifest
	cd "${PORTDIR_BUMPING}" #go back to workdir
}

# add basic line to changelog telling that we bumped new revision
update_package_changelog() {
	local EBUILD=${1}

	cd "${PORTDIR_BUMPING}"/"${EBUILD_BASEDIR}"/
	git add ${EBUILD}
	# be quiet when creating changelog
#	echangelog "Version bump." >> /dev/null
	cd "${PORTDIR_BUMPING}" # go back to workdir
}

# create new slot for all packages when creating new minor bump 4.1 -> 4.2
add_new_sloted_version() {
	local SLOTFILE
	local NEWSLOTFILE

	find ${PORTDIR_BUMPING}/sets/ -maxdepth 1 -type f -name \*-${SLOT} -print \
		| while read SLOTFILE; do
		NEWSLOTFILE=${SLOTFILE/${SLOT}/${BUMP_VERSION}}
		echo "creating ${NEWSLOTFILE}"
		# copy actualy that file
		cp ${SLOTFILE} ${NEWSLOTFILE}
		# fix versioning
		sed -i \
			-e "s:${SLOT}:${BUMP_VERSION}:" \
			${NEWSLOTFILE} || die "unable to update slotfile versioning"
		# add to git
		git add ${NEWSLOTFILE}
	done
}

# write ebuild directories in which i will work to file.
find_packagedirs_for_removal() {
	find ${PORTDIR_BUMPING}/kde-base/ -name \*${VERSION}\*.ebuild -print |while read FILE; do
		echo ${FILE} |sed -e "s:${PORTDIR_BUMPING}/kde-base/::" \
			|awk -F'/' '{print "kde-base/"$1}' \
			>> ${TMPFILE}
	done
}

# diff CMakeLists.txt recursively through new sources again old one to see
# if there are any added ebuilds
check_cmakelists() {
	cd "${OUTPUT_DIR}"
	find ${DIR} -maxdepth 1 -type f -name kde\*-${BUMP_VERSION}.tar.bz2 -print \
			|while read FILE; do
		FILENAME=${FILE/*\/}
		FILENAME=${FILENAME/.tar.bz2/}
		rm CMakeListsDiff-${FILENAME}.diff > /dev/null
		touch CMakeListsDiff-${FILENAME}.diff
		echo "Checking CMakeLists.txt in: ${FILENAME} > ${OUTPUT_DIR}/CMakeListsDiff-${FILENAME}.diff"
		# unpack files into /var/tmp/portage/
		tar -xjf ${FILE} -C "${OUTPUT_DIR}"/
		tar -xjf ${FILE/${BUMP_VERSION}/${VERSION}} \
			-C "${OUTPUT_DIR}"/
		find ${FILENAME} -type f -name CMakeLists.txt -print \
				|while read CLIST; do
			# echo ${CLIST/${BUMP_VERSION}/${VERSION}}
			# echo ${CLIST}
			diff -urNibB ${CLIST/${BUMP_VERSION}/${VERSION}} ${CLIST} \
			>> CMakeListsDiff-${FILENAME}.diff
		done
		if [ `cat CMakeListsDiff-${FILENAME}.diff |grep -i [+-]addsubdirectory |wc -l` -gt 0 ]; then
			echo "I found something really interesting in ${FILENAME}"
			echo "You should really look into ${OUTPUT_DIR}/CMakeListsDiff-${FILENAME}.diff"
			echo
		fi
		# cleanup our dirt
		rm -rf ${FILENAME}*
		rm -rf ${FILENAME/${BUMP_VERSION}/${VERSION}}*
	done
}

# Check in tree keywords and push them to the overlay,
# If there is no ebuild add ~amd64 and ~x86 only.
# If there is more archs in overlay drop them, only tree one counts.
# These syncs are done druing update and during move back to MAIN tree.
sync_main_keywords_with_overlay() {
	local sep dir
	# first strip of all keywords
	ekeyword ^all ${1} &> /dev/null
	# then apply them back
	dir="$(portageq portdir)/${2}"
	if [[ -d "${dir}" ]] ; then
		pushd "${dir}" &> /dev/null
		# the grep is for removing 3.5 ebuilds from knowledge
		if [[ ${3} = intree ]]; then	
			KEYWORDS="$(find ./ -name \*ebuild |grep -v "\-3.5" | sort | tail -n 2 | head -n 1 | xargs -i grep KEYWORDS {} |sed -e "s:KEYWORDS=::g" -e "s:\"::g")"
		else
			KEYWORDS="$(find ./ -name \*ebuild |grep -v "\-3.5" | sort | tail -n 1 | xargs -i grep KEYWORDS {} |sed -e "s:KEYWORDS=::g" -e "s:\"::g")"
		fi
		popd &> /dev/null
	else
		KEYWORDS="~amd64 ~x86" # want to be here, well ask us :]
	fi
	[[ ${KEYWORDS} = "" ]] && KEYWORDS="~amd64 ~x86"
	ekeyword $KEYWORDS ${1} &> /dev/null
}

# print out help function
help() {
	echo "Welcome to KDE package version bumper"
	echo
	echo "When bumping:"
	echo "For correct usage set SLOT, VERSION and BUMP_VERSION arguments."
	echo "BUMP_VERSION is used as target version and version specify what ebuilds are used as base."
	echo "-l argument specify SET and is optional"
	echo "Example:"
	echo "$0 -a bump -s 4.2 -v 9999 -b 4.2.90 -l kdebase"
	echo
	echo "When removing:"
	echo "$0 -a remove -v 4.1.0"
	echo
	echo "When creating new slot:"
	echo "-s STARTSLOT -b BUMPSLOT"
	echo "$0 -a slot -s 4.1 -b 4"
	echo
	echo "When diffing two versions for cmakelists"
	echo "-v OLDVERSION -b NEWVERSION -p DIRECTORY_WHERE_ARE_TBZS -o OUTPUT_DIR"
	echo "$0 -a diff -v 4.1.0 -b 4.1.1 -p \"/usr/portage/distfiles\" -o /tmp"
	echo
	echo "When moving kde from overlay to the main tree"
	echo "-v VERSION"
	echo "$0 -a cvsmove -v 4.2.4"
	exit 0
}

_cvsupdate() {
	pushd "${1}" &> /dev/null
	cvs up
	popd &> /dev/null
}
_addcvsfile() {
	pushd "${1}" &> /dev/null
	echo "${1}/${2}"
	cvs add ${2}
	popd &> /dev/null
}
_check_patches() {
	pushd "${1}" &> /dev/null
	rm ${TMPFILE} &> /dev/null
	touch ${TMPFILE} &> /dev/null
	[[ -d files/ ]] || return
	find ./files/ -type f |grep -v "CVS/" |grep -v ".svn" |sort -u |sed -e "s:\./files/::g" |while read PATCH; do
		P1="`echo ${3}| sed -e "s:.ebuild::g"`"
		[[ ${P1/*-/} == r* ]] && P1=`echo ${P1} |  sed -e "s:${P1/*-/}::g" -e "s:-$::g"`
		PV=${P1/*-/}
		PN=`echo ${P1} |  sed -e "s:${P1/*-/}::g" -e "s:-$::g"`
		if [[ $(cat ${3} | sed -e "s:\${PN}:${PN}:g" -e "s:\${PV}:${PV}:g" -e "s:\${P}:${PN}-${PV}:g" |grep "${PATCH}" |wc -l) -gt 0 ]]; then
			echo "${PATCH}" >> ${TMPFILE}
		fi
	done
	popd &> /dev/null
}
###############################################################################
# main
###############################################################################
# argument passing
###############################################################################
if [[ $1 == "--help" ]]; then
	help
fi
SLOT=
VERSION=
OPERATION=
BUMP_VERSION=
KEYWORDS=
SET=
DIR=
OUTPUT_DIR=
while getopts a:s:v:b:l:p:o:n arg ; do
	case ${arg} in
		a) OPERATION=${OPTARG} ;;
		s) SLOT=${OPTARG} ;;
		v) VERSION=${OPTARG} ;;
		b) BUMP_VERSION="${OPTARG}" ;;
		l) SET="${OPTARG}" ;;
		p) DIR="${OPTARG}" ;;
		o) OUTPUT_DIR="${OPTARG}" ;;
		n) KEYWORDS="no" ;;
		*) help ;;
		?) help ;;
	esac
done
case ${OPERATION} in
	bump)
		[[ -z "${SLOT}" || -z "${VERSION}" || -z "${BUMP_VERSION}" ]] && help
		;;
	remove)
		[[ -z "${VERSION}" ]] && help
		;;
	slot)
		[[ -z "${SLOT}" || -z "${BUMP_VERSION}" ]] && help
		;;
	diff)
		[[ -z "${VERSION}" || -z "${BUMP_VERSION}" || -z "${DIR}" || -z "${OUTPUT_DIR}" ]] && \
			help
		;;
	cvsmove)
		[[ -z "${VERSION}" ]] && help
		;;
	*)
		help
		;;
esac
###############################################################################
# global variables
###############################################################################
# these variables needs to be full paths!
# for portdir bumping it should be addable by another argument
PORTDIR_BUMPING="`pwd`" # for time being could be env portagedir
TMPFILE=/tmp/kdeBumpList.txt
###############################################################################
# Remove the temporary file before starting our run
if [[ -e ${TMPFILE} ]]; then
	rm ${TMPFILE}
fi
case ${OPERATION} in
	bump)
		get_packages_from_slot
		EBUILD_BASEDIR_LIST=`cat ${TMPFILE} |sort -u`
		INFO_LIST=
		for EBUILD_BASEDIR in ${EBUILD_BASEDIR_LIST}; do
			EBUILD_BASENAME=${EBUILD_BASEDIR/*\//}
			#OLD_BASE="$(portageq portdir)"/"${EBUILD_BASEDIR}"/
			OLD_BASE="${PORTDIR_BUMPING}"/"${EBUILD_BASEDIR}"/ # uncoment if you work in overlay only
			# by default we should pick-up live stable or live ebuilds. But we need to restore the keywords from the previous version of kde
			# ie. bumping 4.2.71 you pick keywords from 4.2.70 but the ebuilds from 9999.
			# and bumping 4.2.3 you pick keywords from 4.2.2 but ebuilds from 4.2.9999.
			OLD=`find ${OLD_BASE} -name \*${VERSION}\*.ebuild |sort -r |head -n 1`
			mkdir "${PORTDIR_BUMPING}"/"${EBUILD_BASEDIR}"/ -p # wont harm kittens
			NEW="${PORTDIR_BUMPING}"/"${EBUILD_BASEDIR}"/"${EBUILD_BASENAME}"-${BUMP_VERSION}.ebuild
			EBUILD_NAME="${EBUILD_BASENAME}"-${BUMP_VERSION}.ebuild
			# echo ${OLD} # debug
			# echo ${NEW} # debug
			if [ -f ${NEW} ]; then
				echo "Skipping ${NEW} already created!";
				# rm -rf ${NEW} # debug
			else
				# actualy create our desired ebuild files
				# echo "Creating: ${NEW}" # verbosity
				cp "${OLD}" "${NEW}"
				if [ `grep ".patch" ${NEW} |wc -l` -gt 0 ]; then
						INFO_LIST="${INFO_LIST} You should pay more attention to ebuild ${NEW}, because it has some patches.\n"
				fi
				# we have update keywords
				sync_main_keywords_with_overlay ${NEW} ${EBUILD_BASEDIR} outtree
				update_package_keywords ${NEW}
				# update manifest and changelog
				update_package_changelog ${EBUILD_NAME}
				update_package_manifest
				git add .
			fi
		done
		echo -e ${INFO_LIST}
		;;
	remove)
		find_packagedirs_for_removal
		EBUILD_BASEDIR_LIST=`cat ${TMPFILE} |sort -u`
		for EBUILD_BASEDIR in ${EBUILD_BASEDIR_LIST}; do
			EBUILD_BASENAME=${EBUILD_BASEDIR/*\//}
			pushd "${PORTDIR_BUMPING}"/"${EBUILD_BASEDIR}" > /dev/null
			git rm ${EBUILD_BASENAME}-${VERSION}*.ebuild
#			if [[ -d files/ ]]; then
#				# generate list of patches.
#				find ./files/ -type f |grep -v "CVS/" |grep -v ".svn" |sort -u |sed -e "s:\./files/::g" > /tmp/patches-per-package.txt
#				PATCHES="`cat /tmp/patches-per-package.txt`"
#				for PATCH in ${PATCHES}; do
#					PATCH_IN_USE="false"
#					find ./ -type f -name \*.ebuild |sort -u |sed -e "s:\./::g" > ${TMP}/ebuild-list-per-package.txt
#					EBUILDS="`cat ${TMP}/ebuild-list-per-package.txt`"
#					for EBUILD in ${EBUILDS}; do
#						P1="`echo ${EBUILD}| sed -e "s:.ebuild::g"`"
#						[[ ${P1/*-/} == r* ]] && P1=`echo ${P1} |  sed -e "s:${P1/*-/}::g" -e "s:-$::g"`
#						PV=${P1/*-/}
#						PN=`echo ${P1} |  sed -e "s:${P1/*-/}::g" -e "s:-$::g"`
#						if [[ $(cat ${EBUILD} | sed -e "s:\${PN}:${PN}:g" -e "s:\${PV}:${PV}:g" -e "s:\${P}:${PN}-${PV}:g" |grep "${PATCH}" |wc -l) -gt 0 ]]; then
#							PATCH_IN_USE="true"
#							break
#						fi
#					done
#					if [[ ${PATCH_IN_USE} = "false" ]]; then
#						echo "Removing ${PATCH}. No longer used in package ${EBUILD_BASEDIR}."
#						git rm -rf $(find ./files/ -type f -name ${PATCH})
#					fi
#				done
#			fi
			repoman manifest
			git add .
			popd &> /dev/null #go back to workdir
		done
		;;
	slot) add_new_sloted_version ;;
	diff) check_cmakelists ;;
	cvsmove)
		MAINTREE="$(portageq portdir)"
		OVERLAY="`pwd`"
		# course of action we are doing here
		# cvs up whole tree, then kde-base
		# then start going per each dir
		# cvs up, move the ebuild, its patches if needed, run echangelog, run keywords check, manifest, commit
		_cvsupdate "${MAINTREE}"
		find ./kde-base/ -mindepth 1 -maxdepth 1 -type d |sed -e "s:./::" | sort |while read dir; do
			# we also have to check if directory contains our version if not, we dont copy it
			pushd "${OVERLAY}/${dir}" &> /dev/null
			if [[ `find ./ -name \*.ebuild|grep ${VERSION} |wc -l` -gt 0 ]]; then
				popd &> /dev/null
				WRKDIR="${MAINTREE}/${dir}"
				if [[ ! -d "${WRKDIR}" ]]; then
					# we need to add the directory to scm tracking
					mkdir -p "${WRKDIR}"
					_addcvsfile "${MAINTREE}/${dir/\/*/}" ${dir/*\//}
				fi
				_cvsupdate "${WRKDIR}"
				# we need to copy the file we want to play with
				## first generate the correct filename, we expect that if someone added -rX to the package it has reason.
				pushd "${OVERLAY}/${dir}" &> /dev/null
				EBUILD=`find ./ -name \*.ebuild |grep ${VERSION} | sort |tail -n 1`
				cp ${EBUILD} "${WRKDIR}"
				popd &> /dev/null
				_addcvsfile "${WRKDIR}" ${EBUILD/*\//}
				# now we need to search up all patches ebuild is containing and move them along if they are needed.
				_check_patches "${OVERLAY}/${dir}" "${WRKDIR}" ${EBUILD/*\//}
				if [[ `cat ${TMPFILE} |wc -l` -gt 0 ]]; then
					cat ${TMPFILE} |while read file; do
						# we actualy have to check if the file is not in subdir and create corresponding directory structure
						if [[ ! -d "${WRKDIR}/files" ]]; then
							# create files dir
							mkdir -p "${WRKDIR}/files"
							_addcvsfile "${WRKDIR}" files/
						fi
						pushd "${OVERLAY}/${dir}" &> /dev/null
						PTH=`find ./ -name ${file/*\//} |sed -e "s:./::" -e "s:${file/*\//}::"`
						PDIR=""
						if [[ ${PTH} != "files/" ]]; then
							# fixme i expect only one depth folders
							# anyway no kde package don't use more than one so i wont bother for now
							PDIR=${PTH/files\//}
							mkdir -p "${PDIR}"
							_addcvsfile "${WRKDIR}/files/" "${PDIR}"
						fi
						# note that we always replace the patches, no warnings we just poke ourselves over them :]
						cp "files/${PDIR}${file}" "${WRKDIR}/files/${PDIR}"
						_addcvsfile "${WRKDIR}/files/${PDIR}" ${file}
						popd &> /dev/null
					done
				fi
				# now we have to check up the keywords
				pushd "${WRKDIR}" &> /dev/null
				sync_main_keywords_with_overlay "${EBUILD/*\//}" ${dir} intree
				ekeyword ~all "${EBUILD/*\//}"
				echangelog "Version bump"
				repoman manifest
				repoman commit -m "Version bump KDE ${VERSION}" -f
				popd &> /dev/null
			else
				popd &> /dev/null
			fi
		done
		;;
	*) help ;;
esac
###############################################################################
# EOF
###############################################################################