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

Contents of /common/cvs-import.sh

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


Revision 1.4 - (show annotations) (download) (as text)
Wed Feb 6 21:03:30 2008 UTC (16 years, 8 months ago) by slords
Branch: MAIN
Changes since 1.3: +3 -3 lines
Content type: application/x-sh
Fixup support files

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

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