| 1 | # Copyright 1999-2000 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
|
|
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/cvs.eclass,v 1.31 2003/02/16 04:26:21 vapier Exp $ |
|
|
4 | # |
| 3 | # Author Dan Armak <danarmak@gentoo.org> |
5 | # Author Dan Armak <danarmak@gentoo.org> |
| 4 | # $Header: /var/cvsroot/gentoo-x86/eclass/cvs.eclass,v 1.25 2002/11/22 13:35:29 cretin Exp $ |
6 | # |
| 5 | # This eclass provides the generic cvs fetching functions. |
7 | # This eclass provides the generic cvs fetching functions. |
| 6 | |
8 | |
| 7 | ECLASS=cvs |
9 | ECLASS=cvs |
| 8 | INHERITED="$INHERITED $ECLASS" |
10 | INHERITED="$INHERITED $ECLASS" |
| 9 | |
11 | |
| … | |
… | |
| 109 | if [ ! -d "$DIR" ]; then |
111 | if [ ! -d "$DIR" ]; then |
| 110 | debug-print "$FUNCNAME: creating cvs directory $DIR" |
112 | debug-print "$FUNCNAME: creating cvs directory $DIR" |
| 111 | #export SANDBOX_WRITE="$SANDBOX_WRITE:/foobar:/" |
113 | #export SANDBOX_WRITE="$SANDBOX_WRITE:/foobar:/" |
| 112 | addwrite /foobar |
114 | addwrite /foobar |
| 113 | addwrite / |
115 | addwrite / |
| 114 | mkdir -p /$DIR |
116 | mkdir -p "/$DIR" |
| 115 | export SANDBOX_WRITE=${SANDBOX_WRITE//:\/foobar:\/} |
117 | export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}" |
| 116 | fi |
118 | fi |
| 117 | |
119 | |
| 118 | # in case ECVS_TOP_DIR is a symlink to a dir, get the real dir's path, |
120 | # in case ECVS_TOP_DIR is a symlink to a dir, get the real dir's path, |
| 119 | # otherwise addwrite() doesn't work. |
121 | # otherwise addwrite() doesn't work. |
| 120 | cd -P $ECVS_TOP_DIR > /dev/null |
122 | cd -P "$ECVS_TOP_DIR" > /dev/null |
| 121 | ECVS_TOP_DIR="`/bin/pwd`" |
123 | ECVS_TOP_DIR="`/bin/pwd`" |
| 122 | DIR="${ECVS_TOP_DIR}/${ECVS_MODULE}/${ECVS_SUBDIR}" |
124 | DIR="${ECVS_TOP_DIR}/${ECVS_MODULE}/${ECVS_SUBDIR}" |
| 123 | cd $OLDPWD |
125 | cd "$OLDPWD" |
| 124 | |
126 | |
| 125 | debug-print "$FUNCNAME: now DIR=$DIR" |
127 | debug-print "$FUNCNAME: now DIR=$DIR" |
| 126 | |
128 | |
| 127 | # disable the sandbox for this dir |
129 | # disable the sandbox for this dir |
| 128 | # not just $DIR because we want to create moduletopdir/CVS too |
130 | # not just $DIR because we want to create moduletopdir/CVS too |
| 129 | addwrite $ECVS_TOP_DIR/$ECVS_MODULE |
131 | addwrite "$ECVS_TOP_DIR/$ECVS_MODULE" |
| 130 | |
132 | |
| 131 | # add option for local (non-recursive) fetching |
133 | # add option for local (non-recursive) fetching |
| 132 | [ -n "$ECVS_LOCAL" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -l" |
134 | [ -n "$ECVS_LOCAL" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -l" |
| 133 | |
135 | |
| 134 | # prepare a cvspass file just for this session so that cvs thinks we're logged |
136 | # prepare a cvspass file just for this session so that cvs thinks we're logged |
| 135 | # in at the cvs server. we don't want to mess with ~/.cvspass. |
137 | # in at the cvs server. we don't want to mess with ~/.cvspass. |
| 136 | echo ":pserver:${ECVS_SERVER} A" > ${T}/cvspass |
138 | echo ":pserver:${ECVS_SERVER} A" > "${T}/cvspass" |
| 137 | export CVS_PASSFILE="${T}/cvspass" |
139 | export CVS_PASSFILE="${T}/cvspass" |
| 138 | chown $ECVS_RUNAS "${T}/cvspass" |
140 | chown $ECVS_RUNAS "${T}/cvspass" |
| 139 | #export CVSROOT=:pserver:${ECVS_USER}@${ECVS_SERVER} |
141 | #export CVSROOT=:pserver:${ECVS_USER}@${ECVS_SERVER} |
| 140 | |
142 | |
| 141 | # Note: cvs update and checkout commands are unified. |
143 | # Note: cvs update and checkout commands are unified. |
| … | |
… | |
| 154 | repository="${ECVS_MODULE}" |
156 | repository="${ECVS_MODULE}" |
| 155 | fi |
157 | fi |
| 156 | |
158 | |
| 157 | debug-print "$FUNCNAME: Root<-$newserver, Repository<-$repository" |
159 | debug-print "$FUNCNAME: Root<-$newserver, Repository<-$repository" |
| 158 | debug-print "$FUNCNAME: entering directory $DIR" |
160 | debug-print "$FUNCNAME: entering directory $DIR" |
| 159 | cd /$DIR |
161 | cd "/$DIR" |
| 160 | |
162 | |
| 161 | if [ ! -d "CVS" ]; then |
163 | if [ ! -d "CVS" ]; then |
| 162 | # create a new CVS/ directory (checkout) |
164 | # create a new CVS/ directory (checkout) |
| 163 | debug-print "$FUNCNAME: creating new cvs directory" |
165 | debug-print "$FUNCNAME: creating new cvs directory" |
| 164 | |
166 | |
| … | |
… | |
| 170 | # if we're checking out a subdirectory only, create a CVS/ dir |
172 | # if we're checking out a subdirectory only, create a CVS/ dir |
| 171 | # in the module's top dir so that the user (and we) can cvs update |
173 | # in the module's top dir so that the user (and we) can cvs update |
| 172 | # from there to get the full module. |
174 | # from there to get the full module. |
| 173 | if [ ! -d "$ECVS_TOP_DIR/$ECVS_MODULE/CVS" ]; then |
175 | if [ ! -d "$ECVS_TOP_DIR/$ECVS_MODULE/CVS" ]; then |
| 174 | debug-print "$FUNCNAME: Copying CVS/ directory to module top-level dir" |
176 | debug-print "$FUNCNAME: Copying CVS/ directory to module top-level dir" |
| 175 | cp -r CVS $ECVS_TOP_DIR/$ECVS_MODULE/ |
177 | cp -r CVS "$ECVS_TOP_DIR/$ECVS_MODULE/" |
| 176 | echo $ECVS_MODULE > $ECVS_TOP_DIR/$ECVS_MODULE/CVS/Repository |
178 | echo $ECVS_MODULE > "$ECVS_TOP_DIR/$ECVS_MODULE/CVS/Repository" |
| 177 | fi |
179 | fi |
| 178 | |
180 | |
| 179 | else |
181 | else |
| 180 | #update existing module |
182 | #update existing module |
| 181 | debug-print "$FUNCNAME: updating existing module/subdir" |
183 | debug-print "$FUNCNAME: updating existing module/subdir" |
| … | |
… | |
| 195 | debug-print "$cvsdirs" |
197 | debug-print "$cvsdirs" |
| 196 | |
198 | |
| 197 | einfo "Modifying CVS dirs..." |
199 | einfo "Modifying CVS dirs..." |
| 198 | for x in $cvsdirs; do |
200 | for x in $cvsdirs; do |
| 199 | debug-print "In $x" |
201 | debug-print "In $x" |
| 200 | echo $newserver > $x/Root |
202 | echo $newserver > "$x/Root" |
| 201 | done |
203 | done |
| 202 | |
204 | |
| 203 | fi |
205 | fi |
| 204 | |
206 | |
| 205 | fi |
207 | fi |
| … | |
… | |
| 207 | # cvs auto-switches branches, how nice |
209 | # cvs auto-switches branches, how nice |
| 208 | # warning: if we do it this way we get multiple -rX options - harmless i think |
210 | # warning: if we do it this way we get multiple -rX options - harmless i think |
| 209 | [ -n "$ECVS_BRANCH" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -r$ECVS_BRANCH" |
211 | [ -n "$ECVS_BRANCH" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -r$ECVS_BRANCH" |
| 210 | |
212 | |
| 211 | # Chowning the directory |
213 | # Chowning the directory |
| 212 | if [ "${ECVS_RUNAS}" != "root" ]; then |
214 | if [ "${ECVS_RUNAS}" != "`whoami`" ]; then |
| 213 | chown -R "$ECVS_RUNAS" /$DIR |
215 | chown -R "$ECVS_RUNAS" "/$DIR" |
| 214 | fi |
216 | fi |
| 215 | |
217 | |
| 216 | # finally run the cvs update command |
218 | # finally run the cvs update command |
| 217 | debug-print "$FUNCNAME: is in dir `/bin/pwd`" |
219 | debug-print "$FUNCNAME: is in dir `/bin/pwd`" |
| 218 | debug-print "$FUNCNAME: running $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS with $ECVS_SERVER for module $ECVS_MODULE subdir $ECVS_SUBDIR" |
220 | debug-print "$FUNCNAME: running $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS with $ECVS_SERVER for module $ECVS_MODULE subdir $ECVS_SUBDIR" |
| … | |
… | |
| 233 | |
235 | |
| 234 | mypasswd = "${ECVS_PASS}" |
236 | mypasswd = "${ECVS_PASS}" |
| 235 | myauth = "${ECVS_AUTH}" |
237 | myauth = "${ECVS_AUTH}" |
| 236 | mytimeout = 10 |
238 | mytimeout = 10 |
| 237 | |
239 | |
|
|
240 | if "${ECVS_RUNAS}" == "`whoami`": |
|
|
241 | mycommand = "${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}" |
|
|
242 | else: |
|
|
243 | mycommand = "su ${ECVS_RUNAS} -c \"${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}\"" |
|
|
244 | |
| 238 | if myauth == "ext": |
245 | if myauth == "ext": |
| 239 | mycommand = "su ${ECVS_RUNAS} -c \"${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}\"" |
|
|
| 240 | child = pexpect.spawn(mycommand) |
246 | child = pexpect.spawn(mycommand) |
| 241 | |
247 | |
| 242 | index = child.expect(['continue connecting','word:'], mytimeout) |
248 | index = child.expect(['continue connecting','word:'], mytimeout) |
| 243 | if index == 0: |
249 | if index == 0: |
| 244 | child.sendline('yes') |
250 | child.sendline('yes') |
| … | |
… | |
| 250 | |
256 | |
| 251 | child.sendline(mypasswd) |
257 | child.sendline(mypasswd) |
| 252 | child.expect(pexpect.EOF) |
258 | child.expect(pexpect.EOF) |
| 253 | |
259 | |
| 254 | elif myauth == "pserver": |
260 | elif myauth == "pserver": |
|
|
261 | if "${ECVS_RUNAS}" == "`whoami`": |
|
|
262 | mycommand2 = "cvs login" |
|
|
263 | else: |
| 255 | mycommand = "su ${ECVS_RUNAS} -c \"cvs login\"" |
264 | mycommand2 = "su ${ECVS_RUNAS} -c \"cvs login\"" |
| 256 | child = pexpect.spawn(mycommand) |
265 | child = pexpect.spawn(mycommand2) |
| 257 | child.expect("CVS password:",mytimeout) |
266 | child.expect("CVS password:",mytimeout) |
| 258 | child.sendline(mypasswd) |
267 | child.sendline(mypasswd) |
| 259 | child.expect(pexpect.EOF) |
268 | child.expect(pexpect.EOF) |
| 260 | |
269 | |
| 261 | # Logged in - checking out |
270 | # Logged in - checking out |
| 262 | os.system("su ${ECVS_RUNAS} -c \"${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}\" &> /dev/null") |
271 | os.system(mycommand) |
|
|
272 | |
| 263 | EndOfFile |
273 | EndOfFile |
| 264 | ########################### End of inline-python ################################## |
274 | ########################### End of inline-python ################################## |
| 265 | else |
275 | else |
| 266 | debug-print "$FUNCNAME: using anonymous cvs login" |
276 | debug-print "$FUNCNAME: using anonymous cvs login" |
| 267 | $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS || die "died running cvs update" |
277 | $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS || die "died running cvs update" |
| 268 | fi |
278 | fi |
| 269 | |
279 | |
| 270 | # log out and restore ownership |
280 | # log out and restore ownership |
|
|
281 | if [ "$ECVS_RUNAS" == "`whoami`" ]; then |
|
|
282 | cvs logout &> /dev/null |
|
|
283 | else |
| 271 | su $ECVS_RUNAS -c "cvs logout" &> /dev/null |
284 | su $ECVS_RUNAS -c "cvs logout" &> /dev/null |
|
|
285 | fi |
| 272 | chown `whoami` ${T}/cvspass |
286 | chown `whoami` "${T}/cvspass" |
| 273 | } |
287 | } |
| 274 | |
288 | |
| 275 | cvs_src_unpack() { |
289 | cvs_src_unpack() { |
| 276 | |
290 | |
| 277 | debug-print-function $FUNCNAME $* |
291 | debug-print-function $FUNCNAME $* |
| … | |
… | |
| 279 | |
293 | |
| 280 | einfo "Copying $ECVS_MODULE/$ECVS_SUBDIR from $ECVS_TOP_DIR..." |
294 | einfo "Copying $ECVS_MODULE/$ECVS_SUBDIR from $ECVS_TOP_DIR..." |
| 281 | debug-print "Copying module $ECVS_MODULE subdir $ECVS_SUBDIR local_mode=$ECVS_LOCAL from $ECVS_TOP_DIR..." |
295 | debug-print "Copying module $ECVS_MODULE subdir $ECVS_SUBDIR local_mode=$ECVS_LOCAL from $ECVS_TOP_DIR..." |
| 282 | |
296 | |
| 283 | # probably redundant, but best to make sure |
297 | # probably redundant, but best to make sure |
| 284 | mkdir -p $WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR |
298 | mkdir -p "$WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR" |
| 285 | |
299 | |
| 286 | if [ -n "$ECVS_SUBDIR" ]; then |
300 | if [ -n "$ECVS_SUBDIR" ]; then |
| 287 | if [ -n "$ECVS_LOCAL" ]; then |
301 | if [ -n "$ECVS_LOCAL" ]; then |
| 288 | cp -f $ECVS_TOP_DIR/$ECVS_MODULE/$ECVS_SUBDIR/* $WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR |
302 | cp -f "$ECVS_TOP_DIR/$ECVS_MODULE/$ECVS_SUBDIR"/* "$WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR" |
| 289 | else |
303 | else |
| 290 | cp -Rf $ECVS_TOP_DIR/$ECVS_MODULE/$ECVS_SUBDIR $WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR/.. |
304 | cp -Rf "$ECVS_TOP_DIR/$ECVS_MODULE/$ECVS_SUBDIR" "$WORKDIR/$ECVS_MODULE/$ECVS_SUBDIR/.." |
| 291 | fi |
305 | fi |
| 292 | else |
306 | else |
| 293 | if [ -n "$ECVS_LOCAL" ]; then |
307 | if [ -n "$ECVS_LOCAL" ]; then |
| 294 | cp -f $ECVS_TOP_DIR/$ECVS_MODULE/* $WORKDIR/$ECVS_MODULE |
308 | cp -f "$ECVS_TOP_DIR/$ECVS_MODULE"/* $WORKDIR/$ECVS_MODULE |
| 295 | else |
309 | else |
| 296 | cp -Rf $ECVS_TOP_DIR/$ECVS_MODULE $WORKDIR |
310 | cp -Rf "$ECVS_TOP_DIR/$ECVS_MODULE" "$WORKDIR" |
| 297 | fi |
311 | fi |
| 298 | fi |
312 | fi |
| 299 | |
313 | |
| 300 | # if the directory is empty, remove it; empty directories cannot exist in cvs. |
314 | # if the directory is empty, remove it; empty directories cannot exist in cvs. |
| 301 | # this happens when fex. kde-source requests module/doc/subdir which doesn't exist. |
315 | # this happens when fex. kde-source requests module/doc/subdir which doesn't exist. |
| 302 | # still create the empty directory in workdir though. |
316 | # still create the empty directory in workdir though. |
| 303 | if [ "`ls -A $DIR`" == "CVS" ]; then |
317 | if [ "`ls -A \"$DIR\"`" == "CVS" ]; then |
| 304 | debug-print "$FUNCNAME: removing cvs-empty directory $ECVS_MODULE/$ECVS_SUBDIR" |
318 | debug-print "$FUNCNAME: removing cvs-empty directory $ECVS_MODULE/$ECVS_SUBDIR" |
| 305 | rm -rf $DIR |
319 | rm -rf "$DIR" |
| 306 | fi |
320 | fi |
| 307 | |
321 | |
| 308 | # implement some of base_src_unpack's functionality; |
322 | # implement some of base_src_unpack's functionality; |
| 309 | # note however that base.eclass may not have been inherited! |
323 | # note however that base.eclass may not have been inherited! |
| 310 | if [ -n "$PATCHES" ]; then |
324 | if [ -n "$PATCHES" ]; then |
| 311 | debug-print "$FUNCNAME: PATCHES=$PATCHES, S=$S, autopatching" |
325 | debug-print "$FUNCNAME: PATCHES=$PATCHES, S=$S, autopatching" |
| 312 | cd $S |
326 | cd "$S" |
| 313 | for x in $PATCHES; do |
327 | for x in $PATCHES; do |
| 314 | debug-print "patching from $x" |
328 | debug-print "patching from $x" |
| 315 | patch -p0 < $x |
329 | patch -p0 < "$x" |
| 316 | done |
330 | done |
| 317 | # make sure we don't try to apply patches more than once, since |
331 | # make sure we don't try to apply patches more than once, since |
| 318 | # cvs_src_unpack is usually called several times from e.g. kde-source_src_unpack |
332 | # cvs_src_unpack is usually called several times from e.g. kde-source_src_unpack |
| 319 | export PATCHES="" |
333 | export PATCHES="" |
| 320 | fi |
334 | fi |