/[smeserver]/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.10 - (show annotations) (download) (as text)
Wed Mar 14 15:24:38 2012 UTC (12 years, 1 month ago) by slords
Branch: MAIN
CVS Tags: e-smith-manager-2_4_0-5_el6_sme, qpsmtpd-0_83-0_9_el4_sme, e-smith-base-5_2_0-68_el5_sme, e-smith-backup-2_2_0-60_el5_sme, e-smith-base-5_2_0-64_el5_sme, e-smith-lib-2_4_0-3_el6_sme, e-smith-email-5_0_0-10_el4_sme, e-smith-dnscache-2_2_0-2_el5_sme, e-smith-pop3-2_2_0-5_el5_sme, ulogd-1_24-13_fc12, e-smith-runit-2_4_0-2_el6_sme, e-smith-ldap-5_4_0-6_el6_sme, qpsmtpd-0_84-3_el5_sme, dar-2_3_8-7_el6_sme, e-smith-base-5_2_0-72_el5_sme, smeserver-qpsmtpd-2_0_0-8_el4_sme, e-smith-ldap-5_2_0-80_el5_sme, e-smith-proxy-5_4_0-2_el6_sme, e-smith-hosts-2_4_0-2_el6_sme, smeserver-qpsmtpd-2_2_0-14_el5_sme, e-smith-samba-2_2_0-50_el5_sme, e-smith-imap-2_4_0-2_el6_sme, e-smith-base-5_4_0-8_el6_sme, e-smith-base-5_4_0-12_el6_sme, smeserver-qpsmtpd-2_0_0-9_el4_sme, mod_perl-2_0_4-10_el6, e-smith-email-5_2_0-18_el5_sme, qpsmtpd-0_83-0_8_el4_sme, e-smith-base-5_0_0-16_el4_sme, initscripts-9_03_31-2_el6_centos_1, e-smith-base-5_4_0-6_el6_sme, e-smith-backup-2_0_0-38_el4_sme, e-smith-radiusd-2_4_0-4_el6_sme, e-smith-qmail-2_4_0-2_el6_sme, e-smith-imap-2_2_0-4_el5_sme, smeserver-qpsmtpd-2_2_0-15_el5_sme, e-smith-email-5_2_0-19_el5_sme, e-smith-base-5_2_0-66_el5_sme, e-smith-apache-2_0_0-7_el4_sme, xlhtml-0_5-11_fc12, e-smith-pop3-2_0_0-2_el4_sme, e-smith-proftpd-2_2_0-4_el5_sme, e-smith-ldap-5_2_0-77_el5_sme, e-smith-ntp-2_4_0-2_el6_sme, perl-Quota-1_6_7-1_rf, e-smith-lib-2_2_0-8_el5_sme, smeserver-yum-2_0_0-14_el4_sme, e-smith-apache-2_4_0-2_el6_sme, e-smith-base-5_2_0-69_el5_sme, e-smith-ldap-5_4_0-3_el6_sme, e-smith-samba-2_4_0-3_el6_sme, mod_perl-2_0_4-10_el6_sme, e-smith-base-5_2_0-65_el5_sme, e-smith-base-5_2_0-70_el5_sme, e-smith-ldap-5_2_0-79_el5_sme, e-smith-base-5_4_0-11_el6_sme, e-smith-samba-2_2_0-51_el5_sme, initscripts-9_03_31-2_el6_sme_2, smeserver-support-2_4_0-4_el6_sme, e-smith-ntp-2_4_0-3_el6_sme, e-smith-pop3-2_2_0-6_el5_sme, smeserver-spamassassin-2_2_0-9_el5_sme, e-smith-proftpd-2_2_0-3_el5_sme, smeserver-yum-2_0_0-13_el4_sme, e-smith-ldap-5_4_0-5_el6_sme, e-smith-pop3-2_2_0-4_el5_sme, hal-0_4_2-8_EL4, mbuffer-20100526-2_fc12, e-smith-base-5_2_0-67_el5_sme, e-smith-lib-2_4_0-2_el6_sme, e-smith-base-5_2_0-71_el5_sme, e-smith-base-5_4_0-2_el6_sme, perl-Test-Harness-Straps-0_30-4_fc12, e-smith-ldap-5_4_0-7_el6_sme, e-smith-packetfilter-2_4_0-2_el6_sme, e-smith-base-5_0_0-17_el4_sme, dietlibc-0_33-0_1600_20110311_el6_sme, e-smith-proftpd-2_2_0-5_el5_sme, e-smith-ldap-5_4_0-2_el6_sme, e-smith-proftpd-2_2_0-6_el5_sme, e-smith-ldap-5_4_0-8_el6_sme, e-smith-base-5_4_0-9_el6_sme, e-smith-ldap-5_4_0-4_el6_sme, e-smith-ldap-5_2_0-78_el5_sme, e-smith-qmail-2_2_0-7_el5_sme, e-smith-backup-2_2_0-61_el5_sme, e-smith-apache-2_2_0-9_el5_sme, e-smith-mysql-2_4_0-2_el6_sme, e-smith-radiusd-2_4_0-5_el6_sme, dar-2_3_8-7_fc16, e-smith-base-5_4_0-14_el6_sme, e-smith-base-5_4_0-13_el6_sme, e-smith-pptpd-2_4_0-2_el6_sme
Changes since 1.9: +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.9 2011/11/03 22:44:53 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