summaryrefslogtreecommitdiff
blob: ddf3028c1572c206081c8e65a8e7f2a9c1b8c4ed (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
#!/bin/bash
# Copyright 2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header$

# This utility rolls a tarball.
# It takes a single argument:
#	the path to the ebuild the tarball is for.
# A second optional argument is the gentoo username
# It autodetects what the name of the tarball should be,
# creates the tarball, and drops it on 
# /space/distfiles-local on dev.gentoo.org
# (It get's your username from CVS information)
# It also modified the GENTOO_PATCHSTAMP variable in the ebuild
# to have the same datestamp the tarball is named after.

# -------------------------------------------------------------
# import some functions and configs

. /sbin/functions.sh
. /etc/make.globals
. /etc/make.conf

die() {
	eerror $@
	exit 1
}

# void einfol(level, text...)
#
# print only when verbosity level equal or higher than $1
einfol() {
	if [ "${VERBOSE}" -ge "${1}" ]; then
		shift 1
		if [ $# -ne 0 ]; then
			einfo "${*}"
		else
			echo
		fi
	fi
}

# -------------------------------------------------------------
# configuration w/ default values

EBUILD=
G_USER=
VERBOSE=0 				# verbosity level
DRY_RUN= 				# does nothing (yet)
UPLOAD= 				# upload tarball?
DISTLOCAL= 				# copy tarball to DISTDIR
DIGEST= 				# -> and update digests

# -------------------------------------------------------------
# parse command-line arguments

usage_error() {
	if [ $# -ne 0 ]; then
		eerror "Usage error: ${*}"
		echo
	fi
	einfo "usage: $0 [--dry-run] [--verbose|-v] [--upload|-p]"
	einfo "           [--user=NAME|-u NAME] [--dist-local|-d]"
	einfo "           [--digest|-g] [--stfu]"
	einfo "           /path/to/apache-herd.ebuild"
	echo
	einfo "You may specify -v repeatily to increase verbosity."
	einfo "short arguments may be glued together (like -vv or -dgp)."
	exit 1
}

while test $# != 0; do
	case $1 in
		--*=*)
			opt_key=`expr "x$1" : 'x\([^=]*\)='`
			opt_val=`expr "x$1" : 'x[^=]*=\(.*\)'`
			opt_type=long
			;;
		-*)
			opt_key=$1
			opt_val=$2
			opt_type=short
			;;
		*)
			opt_key=
			opt_val=$1
			opt_type=raw
			;;
	esac

	einfol 3 "key($opt_key) value($opt_val)"

	if [ "${opt_key}" = "" ]; then
		# raw arguments are supposed to be ebuild location(s)
		EBUILD=${opt_val}
		shiftNum=1
	else
		shiftNum=1
		case ${opt_key} in
			--silent|--quiet|--stfu|--STFU) # yeah, STFU is what I like most ;-)
				VERBOSE=-1
				;;
			--verbose)
				VERBOSE=$[VERBOSE + 1]
				;;
			-v)
				VERBOSE=$[VERBOSE + 1]
				;;
			-vv)
				VERBOSE=$[VERBOSE + 2]
				;;
			-vvv)
				VERBOSE=$[VERBOSE + 3]
				;;
			--dry-run)
				DRY_RUN=1
				;;
			--user)
				G_USER=${opt_val}
				test "${opt_type}" = "short" && shiftNum=2
				;;
			-u)
				G_USER=${opt_val}
				shiftNum=2
				;;
			--upload|-p)
				UPLOAD=1
				;;
			--dist-local|-d)
				DISTLOCAL=1
				;;
			--digest)
				DIGEST=1
				;;
			-g)
				DIGEST=1
				;;
			-dg|-gd)
				DISTLOCAL=1
				DIGEST=1
				;;
			-dgp|-dpg|-gdp|-gpd|-pdg|-pgd)
				DISTLOCAL=1
				DIGEST=1
				UPLOAD=1
				;;
			*)
				usage_error "Unknown argument '${opt_key}'"
				;;
		esac
	fi
	shift ${shiftNum}
done

# -------------------------------------------------------------
# argument validation and post-handling

if [ "${VERBOSE}" -ge 2 ]; then
	exec 9>&1
else
	exec 9>/dev/null
fi

if [ -z "${EBUILD}" ]; then
	usage_error "No ebuild specified."
fi

if [ -z "${DISTLOCAL}" ] && [ -n "${DIGEST}" ]; then
	usage_error "digest can be only created when --dist-local is specified."
fi

# detect username
if [ "x${G_USER}" == "x" ]
then
	G_USER=$(cat CVS/Root)
	G_USER=${G_USER/:ext:/}
	G_USER=${G_USER%@*}
fi
einfol 1 "Gentoo developer: ${G_USER}"

# -------------------------------------------------------------
# Check for updates

einfol 1 "Updating the tree and checking for program updates ..."
my_mtime=$(stat --format=%Y $0)
cvs up >&9 || die "cvs up failed!"
new_mtime=$(stat --format=%Y $0)
einfol 2 "... done!"
einfol 2

if [ "${my_mtime}" -ne "${new_mtime}" ]
then
	die "I have been updated, please restart me!"
fi

# -------------------------------------------------------------
# detect the tarball name

EBUILD_BASE=$(basename ${EBUILD})
EBUILD_NAME=${EBUILD_BASE/-[0-9]*/}
TB_VER=${EBUILD_BASE/${EBUILD_NAME}-/}
TB_VER=${TB_VER/.ebuild/}
DATESTAMP=$(date +%Y%m%d)

einfol 2 "EBUILD_BASE : ${EBUILD_BASE}"
einfol 2 "EBUILD_NAME : ${EBUILD_NAME}"
einfol 2 "TB_VER      : ${TB_VER}"
einfol 2 "DATESTAMP   : ${DATESTAMP}"

case ${EBUILD_NAME} in
	apache)
		TREE=${TB_VER%.*}
		TB=gentoo-apache-${TB_VER}-${DATESTAMP}.tar.bz2
		TB_DIR=gentoo-apache-${TB_VER}
		UPDATE_EBUILD=1
		;;
	gentoo-webroot-default)
		TREE=gentoo-webroot-default
		TB=gentoo-webroot-default-${TB_VER}.tar.bz2
		TB_DIR=gentoo-webroot-default-${TB_VER}
		;;
	*)	
		die "Unknown ebuild (ebuild name: ${EBUILD_NAME})";;
esac

# -------------------------------------------------------------
# create tarball

einfol 1 "Creating ${TB} from ${TREE}/ ..."
cp -rl ${TREE} ${TB_DIR} || die "Copy failed"
date -u > ${TB_DIR}/DATESTAMP
einfol 1 "Packaged by ${G_USER}" >> ${TB_DIR}/DATESTAMP
tar --create --bzip2 --verbose --exclude=CVS --file ${TB} ${TB_DIR} >&9 || die "Tarball creation failed"
rm -rf ${TB_DIR} || ewarn "Couldn't clean up, manually remove ${TB_DIR}/"
einfol 2 "... done!"
einfol 2

# -------------------------------------------------------------
if [ "${UPLOAD}" = "1" ]; then
	einfol 1 "Putting ${TB} on the mirrors ..."
	scp ${TB} ${G_USER}@dev.gentoo.org:/space/distfiles-local >&9 || die "Couldn't upload tarball"
	einfol 2 "... done!"
	einfol 1
	einfol 1 "Please remember it can take up to 24 hours for full propogation"
	einfol 1 "Make sure the tarball is on the mirrors before marking a package as stable"
	einfol 1
fi

# -------------------------------------------------------------
if [ "${UPDATE_EBUILD}" == "1" ]; then
	einfol 1 "Updating datestamp in ebuild ${EBUILD}"
	sed -i -e "s/GENTOO_PATCHSTAMP=\"[0-9]*\"/GENTOO_PATCHSTAMP=\"${DATESTAMP}\"/" ${EBUILD}
	einfol 1

	einfol 0 "Please double check the change in the ebuild (should only effect the"
	einfol 0 "setting of GENTOO_PATCHSTAMP)"
	einfol 0
fi

# -------------------------------------------------------------
if [ -n "${DISTLOCAL}" ]; then
	cp -v ${TB} ${DISTDIR} >&9
	if [ -n "${DIGEST}" ]; then
		ebuild ${EBUILD} digest >&9 || ewarn "Sorry. creation digest failed"
	fi
else
	einfol 0 "Copy ${TB} to \${DISTFILES}, and run"
	einfol 0 "ebuild \${EBUILD} digest."
	einfol 0
	einfol 0 "Make sure to cvs up and echangelog before a repoman commit."
fi

einfol 3 "Done."

# vim:ai:noet:ts=4:nowrap