/[smeserver]/rpms/common/cvs-import.sh
ViewVC logotype

Contents of /rpms/common/cvs-import.sh

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


Revision 1.2 - (show annotations) (download) (as text)
Tue Jun 12 14:28:07 2007 UTC (16 years, 11 months ago) by slords
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
Content type: application/x-sh
FILE REMOVED
Wrong directory

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

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