/[apache]/trunk/dist/rolltarball.sh
Gentoo

Contents of /trunk/dist/rolltarball.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (show annotations) (download) (as text)
Sun Sep 20 08:32:03 2009 UTC (5 years, 2 months ago) by hollow
File MIME type: text/x-sh
File size: 12565 byte(s)
fix digest generation
1 #!/bin/bash
2 #
3 # rolltarball.sh - rolls a tarball for distribution
4 #
5 # Copyright 2005 Gentoo Foundation
6 # Distributed under the terms of the GNU General Public License v2
7 #
8 # Before commiting large changes, or if you don't completely understand a
9 # small change you are about to commit, please consult the Primary Maintainer
10 # first to make sure it won't break things. Thanks!
11 #
12 # Contributors:
13 # Michael Stewart <vericgar@gentoo.org> (Primary Maintainer)
14 # Christian Parpart <trapni@gentoo.org>
15 #
16 # Changes:
17 # 05-Jun-2005 Complete rewrite to clean up code
18 #
19 MYVERSION='$Revision$'
20 MYVERSION=${MYVERSION#* }
21 MYVERSION=${MYVERSION% *}
22
23 # ********** Begin functions **********
24
25 usage() {
26
27 if [ -n "$1" ]
28 then
29 eerror $1
30 else
31 cat <<-USAGE_HEADER
32 Gentoo Apache Tarball Generator
33 Version: ${MYVERSION}
34 USAGE_HEADER
35 fi
36
37 # there are no tabs in the following!!!
38 cat <<USAGE
39
40 Usage: $0 [options] ebuild
41
42 Where options is any of:
43 -a --ask Display what would be done, then ask to do it (default)
44 -A --no-ask Disable ask
45 -t --color Turn on color
46 -T --no-color Turn off color
47 -c --copyto=path Copy tarball to local path (default: /usr/portage/distfiles)
48 -C --no-copy Don't copy tarball
49 -d --devspace Upload to devspace (default)
50 -D --no-devspace Don't upload to devspace
51 -g --digest Create the digest (default)
52 -G --no-digest Don't create the digest
53 -e --ebuild Modify ebuild (default)
54 -E --no-ebuild Don't modify ebuild
55 -h --help Display this output
56 -m --mirror Upload to mirror://gentoo
57 -M --no-mirror Don't upload to mirror://gentoo (default)
58 -p --pretend Only display what would be done
59 --quiet Set verbosity to 0
60 -q Lower verbosity by 1
61 -s --datestamp Use alternate datestamp
62 -u --user=username Gentoo Username (Required)
63 --verbosity=n Verbosity Level (0-4)
64 -v Increase verbosity by 1
65
66 For convienence, ~/.apache-rolltarball will be sourced so you can set any
67 of the following instead of using the command line:
68
69 ASK Ask before doing anything (0 = no, 1 = yes)
70 COLOR Output in color (0 = no, 1 = yes)
71 COPYTO Local path to copy tarball to (set to blank to disable copy)
72 G_USER Gentoo Username
73 MOD_EBUILD Modify ebuild (0 = no, 1 = yes)
74 UPLOAD_DEV Whether to upload to devspace (0 = no, 1 = yes)
75 UPLOAD_MIRROR Whether to upload to gentoo mirrors (0 = no, 1 = yes)
76 VERBOSE Level of verbosity (0-3)
77
78 USAGE
79
80 exit
81 }
82
83
84 eerror() {
85 echo -e " ${BAD}*${NORMAL} ${*}"
86 }
87
88
89 die() {
90 if [ "$#" -gt 0 ]
91 then
92 eerror ${*}
93 fi
94 exit 1
95 }
96
97
98 einfo() {
99 if [ "${VERBOSE}" -ge "1" ]
100 then
101 echo -e " ${GOOD}*${NORMAL} ${*}"
102 fi
103 }
104
105
106 ebegin() {
107 if [ "${VERBOSE}" -ge "1" ]
108 then
109 echo -e " ${GOOD}*${NORMAL} ${*}..."
110 fi
111 }
112
113
114 eend() {
115
116 if [ "$#" -eq 0 ] || ([ -n "$1" ] && [ "$1" -eq 0 ])
117 then
118 if [ "${VERBOSE}" -ge "1" ]
119 then
120 echo -e "${ENDCOL} ${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
121 fi
122 else
123 retval=$1
124
125 if [ "$#" -ge 2 ]
126 then
127 shift
128 eerror "${*}"
129 fi
130 if [ "${VERBOSE}" -ge "1" ]
131 then
132 echo -e "${ENDCOL} ${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}"
133 fi
134 return ${retval}
135 fi
136
137 }
138
139
140 ewarn() {
141 if [ "${VERBOSE}" -ge "2" ]
142 then
143 echo -e " ${WARN}*${NORMAL} ${*}"
144 fi
145 }
146
147
148 edebug() {
149 if [ "${VERBOSE}" -ge "4" ]
150 then
151 echo -e " ${HILITE}*${NORMAL} ${*}"
152 fi
153 }
154
155
156 nocolor() {
157 COLS="80"
158 ENDCOL=" *****>>"
159 GOOD=
160 WARN=
161 BAD=
162 NORMAL=
163 HILITE=
164 BRACKET=
165 COLOR=0
166 edebug "Color disabled"
167 }
168
169
170 color() {
171 COLS=$(stty size 2> /dev/null)
172 COLS=${COLS#* }
173 COLS=$((${COLS} - 7))
174 ENDCOL=$'\e[A\e['${COLS}'G'
175 GOOD=$'\e[32;01m'
176 WARN=$'\e[33;01m'
177 BAD=$'\e[31;01m'
178 NORMAL=$'\e[0m'
179 HILITE=$'\e[36;01m'
180 BRACKET=$'\e[34;01m'
181 COLOR=1
182 edebug "Color enabled"
183 }
184
185 # ********** End functions, begin primary code **********
186
187 # Defaults
188 # If you change these, change usage()
189 ASK=1
190 COLOR=1
191 COPYTO=/usr/portage/distfiles
192 DIGEST=1
193 G_USER=
194 MOD_EBUILD=1
195 PRETEND=0
196 UPLOAD_DEV=1
197 UPLOAD_MIRROR=0
198 VERBOSE=1
199
200 # load configuration
201 if [ -e ~/.apache-rolltarball ]
202 then
203 . ~/.apache-rolltarball
204 edebug "Loaded configuration from ~/.apache-rolltarball"
205 fi
206
207 if [ "${COLOR}" -eq "0" ]
208 then
209 nocolor;
210 else
211 color;
212 fi
213
214 # Process command line
215 until [ -z "$1" ]
216 do
217 case "$1" in
218 --*)
219 # long options
220 OPTFULL=${1/--/}
221 OPT=${OPTFULL%=*}
222 VALUE=${OPTFULL#*=}
223 case "${OPT}" in
224 ask) ASK=1;;
225 no-ask) ASK=0;;
226 color) color;;
227 no-color) nocolor;;
228 copyto) COPYTO=${VALUE};;
229 no-copy) COPYTO=;;
230 datestamp) DATESTAMP=${VALUE};;
231 devspace) UPLOAD_DEV=1;;
232 no-devspace) UPLOAD_DEV=0;;
233 digest) DIGEST=1;;
234 no-digest) DIGEST=0;;
235 ebuild) MOD_EBUILD=1;;
236 no-ebuild) MOD_EBUILD=0;;
237 help) usage;;
238 mirror) UPLOAD_MIRROR=1;;
239 no-mirror) UPLOAD_MIRROR=0;;
240 pretend) PRETEND=1;;
241 quiet) VERBOSE=0;;
242 user) G_USER=${VALUE};;
243 verbosity) VERBOSE=${VALUE};;
244 *)
245 usage "Unknown option: --${OPT}"
246 ;;
247 esac
248 shift
249 ;;
250 -*)
251 # short options
252 OPTLIST=${1/-/}
253 shift
254 while [ -n "${OPTLIST}" ]
255 do
256 OPT=${OPTLIST:0:1}
257 OPTLIST=${OPTLIST#?}
258 case "${OPT}" in
259 a) ASK=1;;
260 A) ASK=0;;
261 c) COPYTO=$1; shift;;
262 C) COPYTO=;;
263 d) UPLOAD_DEV=1;;
264 D) UPLOAD_DEV=0;;
265 e) MOD_EBUILD=1;;
266 E) MOD_EBUILD=0;;
267 g) DIGEST=1;;
268 G) DIGEST=0;;
269 h) usage;;
270 m) UPLOAD_MIRROR=1;;
271 M) UPLOAD_MIRROR=0;;
272 p) PRETEND=1;;
273 q) VERBOSE=$((${VERBOSE} - 1));;
274 s) DATESTAMP=$1; shift;;
275 t) color;;
276 T) nocolor;;
277 u) G_USER=$1; shift;;
278 v) VERBOSE=$((${VERBOSE} + 1));;
279 *)
280 usage "Unknown option: -${OPT}"
281 ;;
282 esac
283 done
284 ;;
285 *)
286 if [ -n "${EBUILD}" ]
287 then
288 usage "Only one ebuild can be specified"
289 else
290 EBUILD=$1
291 shift
292 fi
293 ;;
294 esac
295 done
296
297 if [ -z "${EBUILD}" ]
298 then
299 usage "You must specify an ebuild"
300 fi
301
302 if [ "${EBUILD##*.}" != "ebuild" ]
303 then
304 usage "You must specify an ebuild"
305 fi
306
307 if [ ! -f ${EBUILD} ]
308 then
309 die "Ebuild ${EBUILD} does not exist or is not a file"
310 fi
311
312 if [ "${VERBOSE}" -lt "0" ]
313 then
314 VERBOSE=0
315 fi
316
317 if [ "${VERBOSE}" -gt "4" ]
318 then
319 VERBOSE=4
320 fi
321
322 if [ "${VERBOSE}" -ge "3" ]
323 then
324 edebug "Program output enabled"
325 exec 9>&1
326 else
327 edebug "Program output disabled"
328 exec 9>/dev/null
329 fi
330
331 if [ "${ASK}" -eq "1" ]
332 then
333 PRETEND=1
334 fi
335
336 if [ -z "${G_USER}" ]
337 then
338 # Autodetect not available for SVN
339 # G_USER=$(cat CVS/Root)
340 # G_USER=${G_USER/:ext:/}
341 # G_USER=${G_USER%@*}
342 # einfo "Detected Gentoo Developer: ${G_USER}"
343 usage "Gentoo Developer Not specified!"
344 fi
345
346 edebug "Current configuration:"
347 edebug " ASK: ${ASK}"
348 edebug " COLOR: ${COLOR}"
349 edebug " COPYTO: ${COPYTO}"
350 edebug " DIGEST: ${DIGEST}"
351 edebug " EBUILD: ${EBUILD}"
352 edebug " G_USER: ${G_USER}"
353 edebug " MOD_EBUILD: ${MOD_EBUILD}"
354 edebug " PRETEND: ${PRETEND}"
355 edebug " UPLOAD_DEV: ${UPLOAD_DEV}"
356 edebug " UPLOAD_MIRROR: ${UPLOAD_MIRROR}"
357 edebug " VERBOSE: ${VERBOSE}"
358
359 my_mtime=$(stat --format=%Y $0)
360
361 ebegin "Updating tree"
362 svn up >&9
363 eend $? "svn update failed!" || die
364
365 new_mtime=$(stat --format=%Y $0)
366 if [ "${my_mtime}" -ne "${new_mtime}" ]
367 then
368 einfo "A new version of $0 is available"
369 einfo "Please restart $0"
370 die
371 fi
372
373 edebug "Detecting settings for tarball based on ebuild name"
374
375 EBUILD_BASE=$(basename ${EBUILD})
376 EBUILD_NAME=${EBUILD_BASE/-[0-9]*/}
377 TB_VER=${EBUILD_BASE/${EBUILD_NAME}-/}
378 TB_VER=${TB_VER/.ebuild/}
379 DATESTAMP=${DATESTAMP:-$(date +%Y%m%d)}
380
381 case ${EBUILD_NAME} in
382 apache)
383 TREE=${TB_VER%.*}
384 TB=gentoo-apache-${TB_VER}-${DATESTAMP}.tar.bz2
385 TB_DIR=gentoo-apache-${TB_VER}
386 ;;
387 gentoo-webroot-default)
388 TREE=gentoo-webroot-default
389 TB=gentoo-webroot-default-${TB_VER}.tar.bz2
390 TB_DIR=gentoo-webroot-default-${TB_VER}
391 MOD_EBUILD=0
392 UPLOAD_MIRROR=1
393 UPLOAD_DEV=0
394 einfo "Have you version-bumped gentoo-webroot-default?"
395 einfo "If not, press Ctrl-C now and do so, specifying the new ebuild"
396 sleep 5
397 ;;
398 *)
399 die "Don't know what to do for ebuild: ${EBUILD_NAME}";;
400 esac
401
402 edebug " TREE: ${TREE}"
403 edebug " TB: ${TB}"
404 edebug " TB_DIR: ${TB_DIR}"
405
406 # simply returns true or false based on whether we are in pretend mod or not
407 pretend() {
408 if [ "${PRETEND}" -eq 1 ]
409 then
410 true
411 return $?
412 else
413 false
414 return $?
415 fi
416 }
417
418
419 # we put all this in a function so that we can simply call it again when
420 # the result of asking is yes.
421 CURTIME=`date -u`
422 build_tarball() {
423
424 pretend && einfo "Actions to be taken:"
425
426 pretend && einfo " Create ${TB} from ${TREE}/"
427 pretend || {
428 ebegin "Creating ${TB} from ${TREE}/"
429 edebug "Copy recursive, hard-link where possible: ${TREE} -> ${TB_DIR}"
430 cp -Rl ${TREE} ${TB_DIR} >&9 || eend $? "Copy failed" || die
431 edebug "Create ${TB_DIR}/DATESTAMP with current time (${CURTIME}), packager (${G_USER}), and script version (${MYVERSION})"
432 echo ${CURTIME} > ${TB_DIR}/DATESTAMP
433 echo "Packaged by ${G_USER}" >> ${TB_DIR}/DATESTAMP
434 echo "$0 v${MYVERSION}" >> ${TB_DIR}/DATESTAMP
435 edebug "Create bzip2-ed tarball ${TB} from ${TB_DIR} excluding .svn"
436 tar --create --bzip2 --verbose --exclude=.svn --exclude=*~ --file ${TB} ${TB_DIR} >&9
437 eend $? "Tarball creation failed" || die
438 edebug "Remove temporary directory"
439 rm -rf ${TB_DIR} || ewarn "Couldn't clean up, manually remove ${TB_DIR}/"
440 }
441
442 if [ -n "${COPYTO}" ]
443 then
444 if [ -d ${COPYTO} -a -w ${COPYTO} ]
445 then
446 pretend && einfo " Copy ${TB} to ${COPYTO}"
447 pretend || {
448 ebegin "Copying ${TB} to ${COPYTO}"
449 cp ${TB} ${COPYTO} >&9
450 eend $?
451 }
452 else
453 ewarn "${COPYTO} is not a directory or not writable, skipping copy"
454 fi
455 else
456 edebug "Copy not enabled"
457 fi
458
459 if [ "${UPLOAD_DEV}" -eq 1 ]
460 then
461 pretend && einfo " Upload ${TB} to"
462 pretend && einfo " http://dev.gentoo.org/~${G_USER}/dist/apache/"
463 pretend || {
464 einfo "Uploading ${TB} to"
465 ebegin " http://dev.gentoo.org/~${G_USER}/dist/apache/"
466 edebug "Making directories on dev.gentoo.org: ~/public_html/dist/apache"
467 ssh ${G_USER}@dev.gentoo.org 'mkdir -pm 0755 ~/public_html/dist/apache/' >&9 || eend $? "Failed to make directories" || die
468
469 edebug "scp ${TB} ${G_USER}@dev.gentoo.org:~/public_html/dist/apache"
470 scp ${TB} ${G_USER}@dev.gentoo.org:~/public_html/dist/apache >&9 || eend $? "Failed to upload" || die
471 edebug "Setting tarball permissions to 0644"
472 ssh ${G_USER}@dev.gentoo.org "chmod 0755 ~/public_html/dist ~/public_html/dist/apache" && ssh ${G_USER}@dev.gentoo.org "chmod 0644 ~/public_html/dist/apache/${TB}"
473 eend $? "Failed to set permissions" || die
474 }
475 else
476 edebug "Upload to devspace not enabled"
477 fi
478
479 if [ "${UPLOAD_MIRROR}" -eq 1 ]
480 then
481 pretend && einfo " Upload ${TB} to mirror://gentoo/"
482 pretend || {
483 ebegin "Uploading ${TB} to mirror://gentoo/"
484 edebug "scp ${TB} ${G_USER}@dev.gentoo.org:/space/distfiles-local"
485 scp ${TB} ${G_USER}@dev.gentoo.org:/space/distfiles-local >&9 || eend $? "Failed to upload" || die
486 edebug "Setting tarball permissions to 0644"
487 ssh ${G_USER}@dev.gentoo.org "chmod 0644 /space/distfiles-local/${TB}"
488 eend $? "Failed to set permissions" || die
489 einfo "Please remember it can take up to 24 hours for full propogation"
490 einfo "Make sure the tarball is available before marking a package stable"
491 }
492 else
493 edebug "Upload to mirrors not enabled"
494 fi
495
496 if [ "${MOD_EBUILD}" -eq 1 ]
497 then
498 if [ -r ${EBUILD} ]
499 then
500 pretend && einfo " Update GENTOO_PATCHSTAMP and GENTOO_DEVELOPER"
501 pretend || {
502 ebegin "Updating GENTOO_PATCHSTAMP and GENTOO_DEVELOPER"
503 sed -i -e "s/GENTOO_PATCHSTAMP=\".*\"/GENTOO_PATCHSTAMP=\"${DATESTAMP}\"/" ${EBUILD} &&
504 sed -i -e "s/GENTOO_DEVELOPER=\".*\"/GENTOO_DEVELOPER=\"${G_USER}\"/" ${EBUILD}
505 eend $? "Failed to modify ebuild" || {
506 einfo "It's highly recommended that you delete the ebuild"
507 einfo "and cvs up and then modify the ebuild manually."
508 die
509 }
510 }
511 else
512 ewarn "Unable to write to ebuild - skipping modification"
513 fi
514 else
515 edebug "Modify ebuild not enabled"
516 fi
517
518 if [ "${DIGEST}" -eq 1 ]
519 then
520 pretend && einfo " Regenerate digests"
521 pretend || {
522 ebegin "Regenerating digests"
523 ebuild --force ${EBUILD} manifest >&9
524 eend $?
525 }
526 else
527 edebug "Regenerate digest not enabled"
528 fi
529
530 pretend && einfo "No actions actually taken"
531 if [ "${ASK}" -eq 1 ]
532 then
533 einfo "Would you like to perform the above actions?"
534 echo -n "Type 'Yes' or 'No'> "
535 read ask_in
536 if [ "${ask_in}" == "Yes" -o "${ask_in}" == "yes" ]
537 then
538 ASK=0
539 PRETEND=0
540 build_tarball
541 fi
542 fi
543
544 }
545
546 build_tarball
547
548 # vim:ai:noet:ts=4:nowrap

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20