aboutsummaryrefslogtreecommitdiff
blob: 292c11a606602b36170ec4520a7bd9cb85f4dc09 (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
#!/usr/bin/env bash
###############################################################################
# KDE Version bumper
# Created by Gentoo kde-herd
# This tool is ment 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 \
			| 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 ^# \
			|sed -e "s/:${SLOT}//g" \
			>> ${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
}

# 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 "-l argument specify SET and is optional"
	echo "Example:"
	echo "$0 -a bump -s 4.1 -v 4.1.0 -b 4.1.1 -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"
	exit 0
}
###############################################################################
# main
###############################################################################
# argument passing
###############################################################################
if [[ $1 == "--help" ]]; then
	help
fi
SLOT=
VERSION=
OPERATION=
BUMP_VERSION=
SET=
DIR=
OUTPUT_DIR=
while getopts a:s:v:b:l:p:o: 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}";;
		*) help;;
		?) help;;
	esac
done
case ${OPERATION} in
	bump)
		if [ -z "${SLOT}" ] || [ -z "${VERSION}" ] || [ -z "${BUMP_VERSION}" ]; then
			help
		fi
		;;
	remove)
		if [ -z "${VERSION}" ]; then
			help
		fi
		;;
	slot)
		if [ -z "${SLOT}" ] || [ -z "${BUMP_VERSION}" ]; then
			help
		fi
		;;
	diff)
		if [ -z "${VERSION}" ] || [ -z "${BUMP_VERSION}" ] || [ -z "${DIR}" ] || [ -z "${OUTPUT_DIR}" ];  then
			help
		fi
		;;
	*)
		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
			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
				update_package_keywords ${NEW}
				# update manifest and changelog
				update_package_changelog ${EBUILD_NAME}
				update_package_manifest
			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/*\//}
			cd "${PORTDIR_BUMPING}"/"${EBUILD_BASEDIR}"
			git rm ${EBUILD_BASENAME}-${VERSION}*.ebuild
			echangelog "Version removed." >> /dev/null
			repoman manifest
			cd "${PORTDIR_BUMPING}" #go back to workdir
		done
		;;
	slot) add_new_sloted_version ;;
	diff) check_cmakelists ;;
	*) help ;;
esac
###############################################################################
# EOF
###############################################################################