/[smecontribs]/common/cvs-import.sh
ViewVC logotype

Annotation of /common/cvs-import.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (hide annotations) (download) (as text)
Wed Jul 30 18:02:28 2008 UTC (16 years, 3 months ago) by slords
Branch: MAIN
Changes since 1.4: +19 -7 lines
Content type: application/x-sh
Updates

1 slords 1.1 #!/bin/bash
2     #
3     # Import a given src.rpm on a given branch
4     # Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
5     # Copyright (C) 2004-2005 Red Hat, Inc.
6     # Copyright (C) 2005 Fedora Foundation
7     #
8 slords 1.5 # $Id: cvs-import.sh,v 1.7 2008/02/08 18:52:15 slords Exp $
9    
10     shopt -s nocasematch
11 slords 1.1
12     # Initial setup
13     CVSTREE=${CVSTREE:=extras}
14     TOPLEVEL=${TOPLEVEL:=rpms}
15    
16     # Check that we're being run from a good location
17     MYDIR=$(dirname $0)
18     if [ ! -f ${MYDIR}/CVS/Root ] ; then
19     echo "ERROR: You need to run this script from the 'common' checkout" >&2
20     exit 1
21     fi
22    
23     # use the CVSROOT from the checkout
24     CVSROOT=$(cat ${MYDIR}/CVS/Root)
25    
26     # We need a writable directory for temporary checkouts and CVS work
27     WORKDIR="/tmp"
28     if test -w $(pwd) ; then
29     WORKDIR="$(pwd)"
30     fi
31    
32 slords 1.5 [ -f branch ] && BRANCH=$(cat branch)
33    
34 slords 1.1 # short usage help
35     Usage() {
36     cat <<EOF
37     Usage:
38    
39     $0 [-b <branch>] [-m <message>] <package>
40    
41     Imports a package into the cvs repository. Will use the following defaults:
42     CVSROOT = $CVSROOT
43     BRANCH = ${BRANCH:-devel}
44    
45     The package can also be imported on a PRE-EXISTING branch using the
46     "-b BRANCH" flag. This script can not create new branches for you.
47     EOF
48     exit 1
49     }
50    
51     # Parse arguments
52     MESSAGE=
53     while [ -n "$1" ] ; do
54     case "$1" in
55     # import the package on the given branch. If the branch does
56     # not exist, we will branch the HEAD and then we will perform
57     # the import
58     -b | --branch )
59     shift
60     BRANCH="$1"
61     if [ -z "$BRANCH" ] ; then
62     echo "ERROR: --branch requires an argument"
63     Usage
64     exit -1
65     fi
66     # protect against moronisms
67     if [ "$BRANCH" = "HEAD" -o "$BRANCH" = "devel" ] ; then
68     BRANCH=
69     fi
70     ;;
71    
72     -m | --message )
73     shift
74     MESSAGE="$1"
75     ;;
76    
77     # the always helpful help message
78     -h | --help )
79     Usage
80     exit 0
81     ;;
82    
83     * )
84     if [ -n "$PACKAGE" ] ; then
85     echo "ERROR: Only one package at a time, please" >&2
86     echo "Already got request for $PACKAGE" >&2
87     exit -1
88     fi
89     PACKAGE="$1"
90     if [ ! -e "$PACKAGE" ] ; then
91     echo "ERROR: Package $PACKAGE does not exist"
92     Usage
93     exit -2
94     fi
95     NVR=$(rpm -qp --qf "%{NAME}-%{VERSION}-%{RELEASE}" $PACKAGE 2>/dev/null)
96     SRCRPM=$(rpm -qp --qf "%{SOURCERPM}" $PACKAGE 2>/dev/null)
97     if [ -z "$NVR" -o "$SRCRPM" != "(none)" ] ; then
98     echo "ERROR: Package $PACKAGE does not look like a source RPM package"
99     Usage
100     exit -3
101     fi
102     # extract NAME VERSION RELEASE, like a 31337 h@x0r
103     RELEASE=${NVR##*-}
104     NAME=${NVR%%-$RELEASE}
105     VERSION=${NAME##*-}
106     NAME=${NAME%%-$VERSION}
107     ;;
108     esac
109     shift
110     done
111    
112     if [ -z "$PACKAGE" ] ; then
113     echo "RPM source package required for import"
114     Usage
115     exit 0
116     fi
117    
118     # make sure the PACKAGE is an absolute path, as we'll be changing
119     # directories fairly often in this script
120     PACKAGE="$(cd $(dirname $PACKAGE) && pwd)/$(basename $PACKAGE)"
121    
122     # all well
123     export CVSROOT
124     CVS="cvs -d $CVSROOT"
125    
126     # Grab a temp dir
127     TMPDIR=$(mktemp -d $WORKDIR/tmpcvsXXXXXX)
128     trap "rm -rf $TMPDIR" 0 9 15
129    
130     # A cleanup function that can be called from random places
131     CleanUp() {
132     if [ -n "$LOGFILE" ] ; then
133     rm -f $LOGFILE
134     fi
135     cd ${WORKDIR}
136     rm -rf $TMPDIR
137     echo
138     }
139    
140     CreateBranchMakefile() {
141     cat >Makefile <<EOF
142     # Makefile for source rpm: $NAME
143     # \$Id\$
144     NAME := $NAME
145     SPECFILE = \$(firstword \$(wildcard *.spec))
146    
147     define find-makefile-common
148 slords 1.4 for d in common ../common ../../common ; do if [ -f \$\$d/Makefile.common ] ; then if [ -f \$\$d/CVS/Root -a -w \$\$/Makefile.common ] ; then cd \$\$d ; cvs -Q update ; fi ; echo "\$\$d/Makefile.common" ; break ; fi ; done
149 slords 1.1 endef
150    
151     MAKEFILE_COMMON := \$(shell \$(find-makefile-common))
152    
153     ifeq (\$(MAKEFILE_COMMON),)
154     # attept a checkout
155     define checkout-makefile-common
156 slords 1.4 test -f CVS/Root && { cvs -Q -d \$\$(cat CVS/Root) checkout common && echo "common/Makefile.common" ; } || { echo "ERROR: I can't figure out how to checkout the 'common' module." ; exit -1 ; } >&2
157 slords 1.1 endef
158    
159     MAKEFILE_COMMON := \$(shell \$(checkout-makefile-common))
160     endif
161    
162     include \$(MAKEFILE_COMMON)
163     EOF
164     }
165    
166     # Check out the existing module
167     cd $TMPDIR
168     echo "Checking out module: '$NAME'"
169     $CVS -Q checkout $TOPLEVEL/$NAME || { echo "ERROR: \"$NAME\" module does not exist in cvs."; exit 1; }
170    
171     # this is our working directory
172     cd $TOPLEVEL/$NAME
173    
174     [ -d ${BRANCH} ] || { echo "ERROR: \"$NAME/$BRANCH\" does not exist!"; exit 1; }
175    
176     # check if we have imported this entry
177     TAG=$(echo "${NAME##[0-9]}-$VERSION-$RELEASE" | sed -e 's/[$,.:;@]/_/g')
178     LOG_ENTRY="$TAG:${BRANCH:-HEAD}:$(basename $PACKAGE)"
179 slords 1.5 if [ -n "$(grep ""^$LOG_ENTRY"" ./${BRANCH}/import.log 2>/dev/null)" ] ; then
180     echo "ERROR: $PACKAGE was already imported on branch ${BRANCH:-HEAD}"
181     CleanUp
182     exit -2
183     fi
184     # Check here as well because back in the old days we used to write it here
185 slords 1.1 if [ -n "$(grep ""^$LOG_ENTRY"" ./import.log 2>/dev/null)" ] ; then
186     echo "ERROR: $PACKAGE was already imported on branch ${BRANCH:-HEAD}"
187     CleanUp
188     exit -2
189     fi
190    
191     # Now the real import job is starting up
192     BRANCH="${BRANCH:-devel}"
193    
194     # Unpack the src.rpm
195     TMP2=$(mktemp -d tmpXXXXXX)
196     pushd $TMP2 >/dev/null
197     echo "Unpacking source package: $(basename $PACKAGE)..."
198     rpm2cpio $PACKAGE | cpio -id --quiet || {
199     echo "This package appears to be corrupt."
200     echo "Skipping import for: $PACKAGE"
201     CleanUp
202     exit -1
203     } >&2
204     popd >/dev/null
205    
206     # grab a list of files from the src.rpm
207     FILES=$(rpm -qpl $PACKAGE 2>/dev/null)
208    
209     # Remove the files that are no longer present
210     OLDFILES=$(find ${BRANCH} -maxdepth 1 -type f \
211     -not -name branch \
212 slords 1.5 -not -name import.log \
213 slords 1.1 -not -name sources \
214     -not -name Makefile \
215     -not -name .cvsignore \
216     -print )
217     for f in $OLDFILES ; do
218     if [ ! -f "$TMP2/$(basename $f)" ] ; then
219     cvs -Q delete -f $f
220     echo "R $(basename $f)"
221     fi
222     done
223    
224     # Add the new files
225     >${BRANCH}/sources.new
226     >${BRANCH}/.cvsignore.new
227    
228     # Now build a list of what needs to be uploaded
229     UPLOADFILES=
230     for _f in $FILES ; do
231     # just to be sure. Who knows when rpm will start returning
232     # pathnames in src.rpm queries
233     f=$(basename ${_f})
234    
235     add_file="yes"
236     file_md5=$(cd $TMP2 && md5sum $f)
237     file_size=$(stat --format="%s" $TMP2/$f)
238    
239     # if the file exists or it is listed in the sources we don't add it
240     if [ -f ${BRANCH}/$f ] ; then
241     add_file="no"
242     cmp -s $TMP2/$f ${BRANCH}/$f || echo "U $f"
243     elif [ -n "$(grep ""$file_md5"" ${BRANCH}/sources 2>/dev/null)" ] ; then
244     add_file="no"
245     # keep it around...
246     echo "$file_md5" >> ${BRANCH}/sources.new
247     echo "$f" >> ${BRANCH}/.cvsignore.new
248     fi
249     # we catch changed patches this way...
250     mv -f $TMP2/$f ${BRANCH}/$f
251     # we need to add this file
252     pushd ${BRANCH} >/dev/null
253     if [ "$add_file" = "yes" ] ; then
254     case $f in
255 slords 1.5 *.tar | *gz | *.bz2 | *.lzma | *.Z | *.zip | \
256     *.ttf | *.bin | *.tbz | *.tbz2 | *.pdf | *.rpm | \
257     *.jar | *.war | *.db | *.cpio | *.jisp | *.egg | *.gem )
258 slords 1.1 UPLOADFILES="$UPLOADFILES $f"
259     if [ -n "$(grep $f sources 2>/dev/null)" ] ; then
260     # this file existed before with a different md5sum
261     echo "N $f"
262     else
263     echo "L $f"
264     fi
265     ;;
266     *)
267     cvs -Q add -ko $f
268     echo "A $f"
269     ;;
270     esac
271     fi
272     popd >/dev/null
273     done
274     # upload the tarballs
275     pushd ${BRANCH} >/dev/null
276     # Re-add the branch Makefile (during resurrection of dead packages).
277     if [ ! -f Makefile ] ; then
278     CreateBranchMakefile
279     cvs -Q add Makefile
280     fi
281     rm -f sources && mv sources.new sources
282     rm -f .cvsignore && mv .cvsignore.new .cvsignore
283     if [ -n "$UPLOADFILES" ] ; then
284     make upload FILES="$UPLOADFILES" || {
285     echo "ERROR: Uploading the source tarballs failed!"
286     exit 9
287     }
288     fi
289     popd >/dev/null
290    
291     # We no longer need this
292     rm -rf $TMP2
293    
294     # setup finished
295 slords 1.5 [ -f ./${BRANCH}/import.log ] || $(touch ./${BRANCH}/import.log; cvs add ./${BRANCH}/import.log)
296     echo "$LOG_ENTRY:$(date +%s)" >> ./${BRANCH}/import.log
297 slords 1.1
298     echo "======================================================================="
299     cvs -Q diff -u
300     echo "======================================================================="
301     echo "Please check the above cvs diff."
302     echo "If you want to make any changes before committing, please press Ctrl-C."
303     echo "Otherwise press Enter to proceed to commit."
304 slords 1.3 read
305 slords 1.1
306     cvs -Q update && \
307     echo "cvs commit..." && \
308 slords 1.5 cvs -Q commit ${MESSAGE:+-m "$MESSAGE"} && echo "Commit Complete" && \
309     cd ${BRANCH} && make tag && echo "Tagging '${TAG}' complete."
310 slords 1.1
311     # Clean up
312     CleanUp

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed