/[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.9 - (show annotations) (download) (as text)
Wed Mar 14 15:25:11 2012 UTC (12 years, 8 months ago) by slords
Branch: MAIN
CVS Tags: smeserver-qmHandle-1_3_5-2_el5_sme, smeserver-isoqlog-2_2_1-1_1_el5_sme, smeserver-durep-1_3_0-1, smeserver-sme8admin-1_3-1_el5_sme, isoqlog-2_2_1-1_1_el5
Changes since 1.8: +2 -2 lines
Content type: application/x-sh
Fix tagging imports

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

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