| 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.33 2003/03/19 11:54:21 danarmak 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.27 2002/11/29 13:13:00 danarmak 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 | |
| … | |
… | |
| 47 | [ -z "$ECVS_RUNAS" ] && ECVS_RUNAS="`whoami`" |
49 | [ -z "$ECVS_RUNAS" ] && ECVS_RUNAS="`whoami`" |
| 48 | |
50 | |
| 49 | # Username to use |
51 | # Username to use |
| 50 | [ -z "$ECVS_USER" ] && ECVS_USER="anonymous" |
52 | [ -z "$ECVS_USER" ] && ECVS_USER="anonymous" |
| 51 | |
53 | |
| 52 | # Password to use if anonymous login is off |
54 | # Password to use if anonymous login is off, or if 'anonymous' pserver access |
|
|
55 | # uses a password and ECVS_ANON = yes |
| 53 | [ -z "$ECVS_PASS" ] && ECVS_PASS="" |
56 | [ -z "$ECVS_PASS" ] && ECVS_PASS="" |
| 54 | |
57 | |
| 55 | # Module to be fetched, must be set explicitly - |
58 | # Module to be fetched, must be set explicitly - |
| 56 | # I don't like the former ="$PN" default setting |
59 | # I don't like the former ="$PN" default setting |
| 57 | [ -z "$ECVS_MODULE" ] && debug-print "$ECLASS: error: ECVS_MODULE not set, cannot continue" |
60 | [ -z "$ECVS_MODULE" ] && debug-print "$ECLASS: error: ECVS_MODULE not set, cannot continue" |
| … | |
… | |
| 75 | cvs_fetch() { |
78 | cvs_fetch() { |
| 76 | |
79 | |
| 77 | debug-print-function $FUNCNAME $* |
80 | debug-print-function $FUNCNAME $* |
| 78 | |
81 | |
| 79 | debug-print "$FUNCNAME: init: |
82 | debug-print "$FUNCNAME: init: |
| 80 | ECVS_CVS_COMMAND=$ECVS_CVS_COMMAND |
83 | 9ECVS_CVS_COMMAND=$ECVS_CVS_COMMAND |
| 81 | ECVS_CVS_OPTIONS=$ECVS_CVS_OPTIONS |
84 | ECVS_CVS_OPTIONS=$ECVS_CVS_OPTIONS |
| 82 | ECVS_TOP_DIR=$ECVS_TOP_DIR |
85 | ECVS_TOP_DIR=$ECVS_TOP_DIR |
| 83 | ECVS_SERVER=$ECVS_SERVER |
86 | ECVS_SERVER=$ECVS_SERVER |
| 84 | ECVS_ANON=$ECVS_ANON |
87 | ECVS_ANON=$ECVS_ANON |
| 85 | ECVS_USER=$ECVS_USER |
88 | ECVS_USER=$ECVS_USER |
| … | |
… | |
| 129 | addwrite "$ECVS_TOP_DIR/$ECVS_MODULE" |
132 | addwrite "$ECVS_TOP_DIR/$ECVS_MODULE" |
| 130 | |
133 | |
| 131 | # add option for local (non-recursive) fetching |
134 | # add option for local (non-recursive) fetching |
| 132 | [ -n "$ECVS_LOCAL" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -l" |
135 | [ -n "$ECVS_LOCAL" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -l" |
| 133 | |
136 | |
| 134 | # prepare a cvspass file just for this session so that cvs thinks we're logged |
137 | # prepare a cvspass file just for this session, we don't want to mess with ~/.cvspass |
| 135 | # in at the cvs server. we don't want to mess with ~/.cvspass. |
138 | touch "${T}/cvspass" |
| 136 | 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 | |
| 140 | |
|
|
| 141 | # Note: cvs update and checkout commands are unified. |
142 | # Note: cvs update and checkout commands are unified. |
| 142 | # we make sure a CVS/ dir exists in our module subdir with the right |
143 | # we make sure a CVS/ dir exists in our module subdir with the right |
| 143 | # Root and Repository entries in it and cvs update. |
144 | # Root and Repository entries in it and cvs update. |
| 144 | |
145 | |
| 145 | [ "${ECVS_ANON}" == "yes" ] && \ |
146 | [ "${ECVS_ANON}" == "yes" ] && \ |
| … | |
… | |
| 207 | # cvs auto-switches branches, how nice |
208 | # cvs auto-switches branches, how nice |
| 208 | # warning: if we do it this way we get multiple -rX options - harmless i think |
209 | # 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" |
210 | [ -n "$ECVS_BRANCH" ] && ECVS_CVS_OPTIONS="$ECVS_CVS_OPTIONS -r$ECVS_BRANCH" |
| 210 | |
211 | |
| 211 | # Chowning the directory |
212 | # Chowning the directory |
| 212 | if [ "${ECVS_RUNAS}" != "root" ]; then |
213 | if [ "${ECVS_RUNAS}" != "`whoami`" ]; then |
| 213 | chown -R "$ECVS_RUNAS" "/$DIR" |
214 | chown -R "$ECVS_RUNAS" "/$DIR" |
| 214 | fi |
215 | fi |
| 215 | |
216 | |
| 216 | # finally run the cvs update command |
217 | # finally run the cvs update command |
| 217 | debug-print "$FUNCNAME: is in dir `/bin/pwd`" |
218 | debug-print "$FUNCNAME: is in dir `/bin/pwd`" |
| … | |
… | |
| 233 | |
234 | |
| 234 | mypasswd = "${ECVS_PASS}" |
235 | mypasswd = "${ECVS_PASS}" |
| 235 | myauth = "${ECVS_AUTH}" |
236 | myauth = "${ECVS_AUTH}" |
| 236 | mytimeout = 10 |
237 | mytimeout = 10 |
| 237 | |
238 | |
|
|
239 | if "${ECVS_RUNAS}" == "`whoami`": |
|
|
240 | mycommand = "${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}" |
|
|
241 | else: |
|
|
242 | mycommand = "su ${ECVS_RUNAS} -c \"${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}\"" |
|
|
243 | |
| 238 | if myauth == "ext": |
244 | if myauth == "ext": |
| 239 | mycommand = "su ${ECVS_RUNAS} -c \"${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}\"" |
|
|
| 240 | child = pexpect.spawn(mycommand) |
245 | child = pexpect.spawn(mycommand) |
| 241 | |
246 | |
| 242 | index = child.expect(['continue connecting','word:'], mytimeout) |
247 | index = child.expect(['continue connecting','word:'], mytimeout) |
| 243 | if index == 0: |
248 | if index == 0: |
| 244 | child.sendline('yes') |
249 | child.sendline('yes') |
| … | |
… | |
| 250 | |
255 | |
| 251 | child.sendline(mypasswd) |
256 | child.sendline(mypasswd) |
| 252 | child.expect(pexpect.EOF) |
257 | child.expect(pexpect.EOF) |
| 253 | |
258 | |
| 254 | elif myauth == "pserver": |
259 | elif myauth == "pserver": |
|
|
260 | if "${ECVS_RUNAS}" == "`whoami`": |
|
|
261 | mycommand2 = "cvs login" |
|
|
262 | else: |
| 255 | mycommand = "su ${ECVS_RUNAS} -c \"cvs login\"" |
263 | mycommand2 = "su ${ECVS_RUNAS} -c \"cvs login\"" |
| 256 | child = pexpect.spawn(mycommand) |
264 | child = pexpect.spawn(mycommand2) |
| 257 | child.expect("CVS password:",mytimeout) |
265 | child.expect("CVS password:",mytimeout) |
| 258 | child.sendline(mypasswd) |
266 | child.sendline(mypasswd) |
| 259 | child.expect(pexpect.EOF) |
267 | child.expect(pexpect.EOF) |
| 260 | |
268 | |
| 261 | # Logged in - checking out |
269 | # Logged in - checking out |
| 262 | os.system("su ${ECVS_RUNAS} -c \"${ECVS_CVS_COMMAND} update ${ECVS_CVS_OPTIONS}\" &> /dev/null") |
270 | os.system(mycommand) |
|
|
271 | |
| 263 | EndOfFile |
272 | EndOfFile |
| 264 | ########################### End of inline-python ################################## |
273 | ########################### End of inline-python ################################## |
| 265 | else |
274 | else |
|
|
275 | # is anonymous cvs. |
|
|
276 | # is there a password to use for login with this "anonymous" login |
|
|
277 | if [ -n "$ECVS_PASS" ]; then |
| 266 | debug-print "$FUNCNAME: using anonymous cvs login" |
278 | debug-print "$FUNCNAME: using anonymous cvs login with password" |
|
|
279 | |
|
|
280 | # inline-python # |
|
|
281 | /usr/bin/env python << EndOfFile |
|
|
282 | |
|
|
283 | import pexpect,os |
|
|
284 | |
|
|
285 | myuser = "${ECVS_USER}" |
|
|
286 | mypasswd = "${ECVS_PASS}" |
|
|
287 | |
|
|
288 | mytimeout = 10 |
|
|
289 | |
|
|
290 | # implicitly myauth == "pserver" here. |
|
|
291 | mycommand = "cvs login" |
|
|
292 | child = pexpect.spawn(mycommand) |
|
|
293 | child.expect("CVS password:",mytimeout) |
|
|
294 | child.sendline(mypasswd) |
|
|
295 | child.expect(pexpect.EOF) |
|
|
296 | EndOfFile |
|
|
297 | # End of inline-python # |
|
|
298 | |
|
|
299 | else |
|
|
300 | debug-print "$FUNCNAME: using anonymous cvs login (without password)" |
|
|
301 | # passwordless, truly anonymous login; or login with empty (but existing) |
|
|
302 | # password. |
|
|
303 | # make cvs think we're logged in at the cvs server, |
|
|
304 | # because i don't trust myself to write the right code for the case |
|
|
305 | # where the password is empty but still required (what's the bash test |
|
|
306 | # to see if a variable is defined? -n returns false if it is defined |
|
|
307 | # but empty...) |
|
|
308 | echo ":pserver:${ECVS_SERVER} A" > "${T}/cvspass" |
|
|
309 | # remember we did this so we don't try to run cvs logout later |
|
|
310 | DONT_LOGOUT=yes |
|
|
311 | fi |
|
|
312 | |
|
|
313 | debug-print "$FUNCNAME: running $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS" |
| 267 | $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS || die "died running cvs update" |
314 | $ECVS_CVS_COMMAND update $ECVS_CVS_OPTIONS || die "died running cvs update" |
| 268 | fi |
|
|
| 269 | |
315 | |
|
|
316 | fi |
|
|
317 | |
| 270 | # log out and restore ownership |
318 | # log out and restore ownership as needed |
|
|
319 | if [ -z "$DONT_LOGOUT" ]; then |
|
|
320 | debug-print "$FUNCNAME: cvs logout stuff" |
|
|
321 | if [ "$ECVS_RUNAS" == "`whoami`" ]; then |
|
|
322 | cvs logout &> /dev/null |
|
|
323 | else |
| 271 | su $ECVS_RUNAS -c "cvs logout" &> /dev/null |
324 | su $ECVS_RUNAS -c "cvs logout" &> /dev/null |
|
|
325 | fi |
|
|
326 | fi |
| 272 | chown `whoami` "${T}/cvspass" |
327 | chown `whoami` "${T}/cvspass" |
| 273 | } |
328 | } |
| 274 | |
329 | |
| 275 | cvs_src_unpack() { |
330 | cvs_src_unpack() { |
| 276 | |
331 | |
| … | |
… | |
| 298 | fi |
353 | fi |
| 299 | |
354 | |
| 300 | # if the directory is empty, remove it; empty directories cannot exist in cvs. |
355 | # 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. |
356 | # this happens when fex. kde-source requests module/doc/subdir which doesn't exist. |
| 302 | # still create the empty directory in workdir though. |
357 | # still create the empty directory in workdir though. |
| 303 | if [ "`ls -A $DIR`" == "CVS" ]; then |
358 | if [ "`ls -A \"$DIR\"`" == "CVS" ]; then |
| 304 | debug-print "$FUNCNAME: removing cvs-empty directory $ECVS_MODULE/$ECVS_SUBDIR" |
359 | debug-print "$FUNCNAME: removing cvs-empty directory $ECVS_MODULE/$ECVS_SUBDIR" |
| 305 | rm -rf "$DIR" |
360 | rm -rf "$DIR" |
| 306 | fi |
361 | fi |
| 307 | |
362 | |
| 308 | # implement some of base_src_unpack's functionality; |
363 | # implement some of base_src_unpack's functionality; |