1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 # vapier@gentoo.org (and anyone who wants to help)
8 # @BLURB: This eclass provides generic cvs fetching functions
10 # This eclass provides the generic cvs fetching functions. To use this from an
11 # ebuild, set the ECLASS VARIABLES as specified below in your ebuild before
12 # inheriting. Then either leave the default src_unpack or extend over
13 # cvs_src_unpack. If you find that you need to call the cvs_* functions
14 # directly, I'd be interested to hear about it.
16 if [[ -z ${_CVS_ECLASS} ]]; then
23 # Implement more auth types (gserver?, kserver?)
25 # Support additional remote shells with `ext' authentication (does
26 # anyone actually need to use it with anything other than SSH?)
29 # Users shouldn't change these settings! The ebuild/eclass inheriting
30 # this eclass will take care of that. If you want to set the global
31 # KDE cvs ebuilds' settings, see the comments in kde-source.eclass.
33 # @ECLASS-VARIABLE: ECVS_CVS_COMPRESS
35 # Set the default compression level. Has no effect when ECVS_CVS_COMMAND
36 # is defined by ebuild/user.
37 : ${ECVS_CVS_COMPRESS:=-z1}
39 # @ECLASS-VARIABLE: ECVS_CVS_OPTIONS
41 # Additional options to the cvs commands. Has no effect when ECVS_CVS_COMMAND
42 # is defined by ebuild/user.
43 : ${ECVS_CVS_OPTIONS:=-q -f}
45 # @ECLASS-VARIABLE: ECVS_CVS_COMMAND
49 # You can set, for example, "cvs -t" for extensive debug information
50 # on the cvs connection. The default of "cvs -q -f -z4" means to be
51 # quiet, to disregard the ~/.cvsrc config file and to use maximum
53 : ${ECVS_CVS_COMMAND:=cvs ${ECVS_CVS_OPTIONS} ${ECVS_CVS_COMPRESS}}
55 # @ECLASS-VARIABLE: ECVS_UP_OPTS
57 # CVS options given after the cvs update command. Don't remove "-dP" or things
59 : ${ECVS_UP_OPTS:=-dP}
61 # @ECLASS-VARIABLE: ECVS_CO_OPTS
64 # CVS options given after the cvs checkout command.
66 # @ECLASS-VARIABLE: ECVS_OFFLINE
68 # Set this variable to a non-empty value to disable the automatic updating of
69 # a CVS source tree. This is intended to be set outside the cvs source
71 : ${ECVS_OFFLINE:=${EVCS_OFFLINE}}
73 # @ECLASS-VARIABLE: ECVS_LOCAL
76 # If this is set, the CVS module will be fetched non-recursively.
77 # Refer to the information in the CVS man page regarding the -l
78 # command option (not the -l global option).
80 # @ECLASS-VARIABLE: ECVS_LOCALNAME
83 # Local name of checkout directory
85 # This is useful if the module on the server is called something
86 # common like 'driver' or is nested deep in a tree, and you don't like
87 # useless empty directories.
89 # WARNING: Set this only from within ebuilds! If set in your shell or
90 # some such, things will break because the ebuild won't expect it and
91 # have e.g. a wrong $S setting.
93 # @ECLASS-VARIABLE: ECVS_TOP_DIR
95 # The directory under which CVS modules are checked out.
96 : ${ECVS_TOP_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/cvs-src"}
98 # @ECLASS-VARIABLE: ECVS_SERVER
102 # The format is "server:/dir", e.g. "anoncvs.kde.org:/home/kde".
103 # Remove the other parts of the full CVSROOT, which might look like
104 # ":pserver:anonymous@anoncvs.kde.org:/home/kde"; this is generated
105 # using other settings also.
107 # Set this to "offline" to disable fetching (i.e. to assume the module
108 # is already checked out in ECVS_TOP_DIR).
109 : ${ECVS_SERVER:="offline"}
111 # @ECLASS-VARIABLE: ECVS_MODULE
114 # The name of the CVS module to be fetched
116 # This must be set when cvs_src_unpack is called. This can include
117 # several directory levels, i.e. "foo/bar/baz"
118 #[[ -z ${ECVS_MODULE} ]] && die "$ECLASS: error: ECVS_MODULE not set, cannot continue"
120 # @ECLASS-VARIABLE: ECVS_DATE
123 # The date of the checkout. See the -D date_spec option in the cvs
124 # man page for more details.
126 # @ECLASS-VARIABLE: ECVS_BRANCH
129 # The name of the branch/tag to use
131 # The default is "HEAD". The following default _will_ reset your
132 # branch checkout to head if used.
133 #: ${ECVS_BRANCH:="HEAD"}
135 # @ECLASS-VARIABLE: ECVS_AUTH
137 # Authentication method to use
139 # Possible values are "pserver" and "ext". If `ext' authentication is
140 # used, the remote shell to use can be specified in CVS_RSH (SSH is
141 # used by default). Currently, the only supported remote shell for
142 # `ext' authentication is SSH.
144 # Armando Di Cianno <fafhrd@gentoo.org> 2004/09/27
145 # - Added "no" as a server type, which uses no AUTH method, nor
148 # "cvs -danoncvs@savannah.gnu.org:/cvsroot/backbone co System"
149 # ( from gnustep-apps/textedit )
150 : ${ECVS_AUTH:="pserver"}
152 # @ECLASS-VARIABLE: ECVS_USER
154 # Username to use for authentication on the remote server.
155 : ${ECVS_USER:="anonymous"}
157 # @ECLASS-VARIABLE: ECVS_PASS
160 # Password to use for authentication on the remote server
162 # @ECLASS-VARIABLE: ECVS_SSH_HOST_KEY
165 # If SSH is used for `ext' authentication, use this variable to
166 # specify the host key of the remote server. The format of the value
167 # should be the same format that is used for the SSH known hosts file.
169 # WARNING: If a SSH host key is not specified using this variable, the
170 # remote host key will not be verified.
172 # @ECLASS-VARIABLE: ECVS_CLEAN
175 # Set this to get a clean copy when updating (passes the
176 # -C option to cvs update)
178 # @ECLASS-VARIABLE: ECVS_RUNAS
181 # Specifies an alternate (non-root) user to use to run cvs. Currently
182 # b0rked and wouldn't work with portage userpriv anyway without
185 # : ${ECVS_RUNAS:=$(whoami)}
188 # ssh is used for ext auth
189 # sudo is used to run as a specified user
192 [[ -n ${ECVS_RUNAS} ]] && DEPEND+=" app-admin/sudo"
194 if [[ ${ECVS_AUTH} == "ext" ]] ; then
196 [[ -z ${CVS_RSH} ]] && export CVS_RSH="ssh"
197 if [[ ${CVS_RSH} != "ssh" ]] ; then
198 die "Support for ext auth with clients other than ssh has not been implemented yet"
200 DEPEND+=" net-misc/openssh"
203 # called from cvs_src_unpack
205 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
207 # Make these options local variables so that the global values are
208 # not affected by modifications in this function.
210 local ECVS_COMMAND=${ECVS_COMMAND}
211 local ECVS_UP_OPTS=${ECVS_UP_OPTS}
212 local ECVS_CO_OPTS=${ECVS_CO_OPTS}
214 debug-print-function ${FUNCNAME} "$@"
216 # Update variables that are modified by ebuild parameters, which
217 # should be effective every time cvs_fetch is called, and not just
218 # every time cvs.eclass is inherited
220 # Handle parameter for local (non-recursive) fetching
222 if [[ -n ${ECVS_LOCAL} ]] ; then
227 # Handle ECVS_BRANCH option
229 # Because CVS auto-switches branches, we just have to pass the
230 # correct -rBRANCH option when updating.
232 if [[ -n ${ECVS_BRANCH} ]] ; then
233 ECVS_UP_OPTS+=" -r${ECVS_BRANCH}"
234 ECVS_CO_OPTS+=" -r${ECVS_BRANCH}"
237 # Handle ECVS_LOCALNAME, which specifies the local directory name
238 # to use. Note that the -d command option is not equivalent to
239 # the global -d option.
241 if [[ ${ECVS_LOCALNAME} != "${ECVS_MODULE}" ]] ; then
242 ECVS_CO_OPTS+=" -d ${ECVS_LOCALNAME}"
245 if [[ -n ${ECVS_CLEAN} ]] ; then
249 if [[ -n ${ECVS_DATE} ]] ; then
250 ECVS_CO_OPTS+=" -D ${ECVS_DATE}"
251 ECVS_UP_OPTS+=" -D ${ECVS_DATE}"
254 # It would be easiest to always be in "run-as mode", logic-wise,
255 # if sudo didn't ask for a password even when sudo'ing to `whoami`.
257 if [[ -z ${ECVS_RUNAS} ]] ; then
260 run="sudo -u ${ECVS_RUNAS}"
263 # Create the top dir if needed
265 if [[ ! -d ${ECVS_TOP_DIR} ]] ; then
266 # Note that the addwrite statements in this block are only
267 # there to allow creating ECVS_TOP_DIR; we allow writing
268 # inside it separately.
270 # This is because it's simpler than trying to find out the
271 # parent path of the directory, which would need to be the
272 # real path and not a symlink for things to work (so we can't
273 # just remove the last path element in the string)
275 debug-print "${FUNCNAME}: checkout mode. creating cvs directory"
278 ${run} mkdir -p "/${ECVS_TOP_DIR}"
279 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
282 # In case ECVS_TOP_DIR is a symlink to a dir, get the real path,
283 # otherwise addwrite() doesn't work.
285 cd -P "${ECVS_TOP_DIR}" >/dev/null
288 # Disable the sandbox for this dir
289 addwrite "${ECVS_TOP_DIR}"
291 # Chown the directory and all of its contents
292 if [[ -n ${ECVS_RUNAS} ]] ; then
293 ${run} chown -R "${ECVS_RUNAS}" "/${ECVS_TOP_DIR}"
296 # Determine the CVS command mode (checkout or update)
297 if [[ ! -d ${ECVS_TOP_DIR}/${ECVS_LOCALNAME}/CVS ]] ; then
303 # Our server string (i.e. CVSROOT) without the password so it can
305 local connection="${ECVS_AUTH}"
306 if [[ ${ECVS_AUTH} == "no" ]] ; then
307 local server="${ECVS_USER}@${ECVS_SERVER}"
309 [[ -n ${ECVS_PROXY} ]] && connection+=";proxy=${ECVS_PROXY}"
310 [[ -n ${ECVS_PROXY_PORT} ]] && connection+=";proxyport=${ECVS_PROXY_PORT}"
311 local server=":${connection}:${ECVS_USER}@${ECVS_SERVER}"
314 # Switch servers automagically if needed
315 if [[ ${mode} == "update" ]] ; then
316 cd "/${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"
317 local oldserver=$(${run} cat CVS/Root)
318 if [[ ${server} != "${oldserver}" ]] ; then
319 einfo "Changing the CVS server from ${oldserver} to ${server}:"
320 debug-print "${FUNCNAME}: Changing the CVS server from ${oldserver} to ${server}:"
322 einfo "Searching for CVS directories ..."
323 local cvsdirs=$(${run} find . -iname CVS -print)
324 debug-print "${FUNCNAME}: CVS directories found:"
325 debug-print "${cvsdirs}"
327 einfo "Modifying CVS directories ..."
329 for x in ${cvsdirs} ; do
330 debug-print "In ${x}"
331 ${run} echo "${server}" > "${x}/Root"
336 # Prepare a cvspass file just for this session, we don't want to
337 # mess with ~/.cvspass
339 export CVS_PASSFILE="${T}/cvspass"
340 if [[ -n ${ECVS_RUNAS} ]] ; then
341 chown "${ECVS_RUNAS}" "${T}/cvspass"
344 # The server string with the password in it, for login (only used for pserver)
345 cvsroot_pass=":${connection}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER}"
347 # Ditto without the password, for checkout/update after login, so
348 # that the CVS/Root files don't contain the password in plaintext
349 if [[ ${ECVS_AUTH} == "no" ]] ; then
350 cvsroot_nopass="${ECVS_USER}@${ECVS_SERVER}"
352 cvsroot_nopass=":${connection}:${ECVS_USER}@${ECVS_SERVER}"
356 cmdlogin="${run} ${ECVS_CVS_COMMAND} -d \"${cvsroot_pass}\" login"
357 cmdupdate="${run} ${ECVS_CVS_COMMAND} -d \"${cvsroot_nopass}\" update ${ECVS_UP_OPTS} ${ECVS_LOCALNAME}"
358 cmdcheckout="${run} ${ECVS_CVS_COMMAND} -d \"${cvsroot_nopass}\" checkout ${ECVS_CO_OPTS} ${ECVS_MODULE}"
363 if [[ ${ECVS_AUTH} == "pserver" ]] ; then
364 einfo "Running ${cmdlogin}"
365 eval ${cmdlogin} || die "cvs login command failed"
366 if [[ ${mode} == "update" ]] ; then
367 einfo "Running ${cmdupdate}"
368 eval ${cmdupdate} || die "cvs update command failed"
369 elif [[ ${mode} == "checkout" ]] ; then
370 einfo "Running ${cmdcheckout}"
371 eval ${cmdcheckout} || die "cvs checkout command failed"
373 elif [[ ${ECVS_AUTH} == "ext" || ${ECVS_AUTH} == "no" ]] ; then
374 # Hack to support SSH password authentication
376 # Backup environment variable values
377 local CVS_ECLASS_ORIG_CVS_RSH="${CVS_RSH}"
379 if [[ ${SSH_ASKPASS+set} == "set" ]] ; then
380 local CVS_ECLASS_ORIG_SSH_ASKPASS="${SSH_ASKPASS}"
382 unset CVS_ECLASS_ORIG_SSH_ASKPASS
385 if [[ ${DISPLAY+set} == "set" ]] ; then
386 local CVS_ECLASS_ORIG_DISPLAY="${DISPLAY}"
388 unset CVS_ECLASS_ORIG_DISPLAY
391 if [[ ${CVS_RSH} == "ssh" ]] ; then
392 # Force SSH to use SSH_ASKPASS by creating python wrapper
394 export CVS_RSH="${T}/cvs_sshwrapper"
395 cat > "${CVS_RSH}"<<EOF
396 #!${EPREFIX}/usr/bin/python
401 fd = os.open('/dev/tty', 2)
404 fcntl.ioctl(fd, TIOCNOTTY)
410 newarglist = sys.argv[:]
413 # disable X11 forwarding which causes .xauth access violations
414 # - 20041205 Armando Di Cianno <fafhrd@gentoo.org>
415 echo "newarglist.insert(1, '-oClearAllForwardings=yes')" \
417 echo "newarglist.insert(1, '-oForwardX11=no')" \
420 # Handle SSH host key checking
422 local CVS_ECLASS_KNOWN_HOSTS="${T}/cvs_ssh_known_hosts"
423 echo "newarglist.insert(1, '-oUserKnownHostsFile=${CVS_ECLASS_KNOWN_HOSTS}')" \
426 if [[ -z ${ECVS_SSH_HOST_KEY} ]] ; then
427 ewarn "Warning: The SSH host key of the remote server will not be verified."
428 einfo "A temporary known hosts list will be used."
429 local CVS_ECLASS_STRICT_HOST_CHECKING="no"
430 touch "${CVS_ECLASS_KNOWN_HOSTS}"
432 local CVS_ECLASS_STRICT_HOST_CHECKING="yes"
433 echo "${ECVS_SSH_HOST_KEY}" > "${CVS_ECLASS_KNOWN_HOSTS}"
436 echo -n "newarglist.insert(1, '-oStrictHostKeyChecking=" \
438 echo "${CVS_ECLASS_STRICT_HOST_CHECKING}')" \
440 echo "os.execv('${EPREFIX}/usr/bin/ssh', newarglist)" \
443 chmod a+x "${CVS_RSH}"
445 # Make sure DISPLAY is set (SSH will not use SSH_ASKPASS
446 # if DISPLAY is not set)
448 : ${DISPLAY:="DISPLAY"}
451 # Create a dummy executable to echo ${ECVS_PASS}
453 export SSH_ASKPASS="${T}/cvs_sshechopass"
454 if [[ ${ECVS_AUTH} != "no" ]] ; then
455 echo -en "#!/bin/bash\necho \"${ECVS_PASS}\"\n" \
458 echo -en "#!/bin/bash\nreturn\n" \
461 chmod a+x "${SSH_ASKPASS}"
464 if [[ ${mode} == "update" ]] ; then
465 einfo "Running ${cmdupdate}"
466 eval ${cmdupdate} || die "cvs update command failed"
467 elif [[ ${mode} == "checkout" ]] ; then
468 einfo "Running ${cmdcheckout}"
469 eval ${cmdcheckout} || die "cvs checkout command failed"
472 # Restore environment variable values
473 export CVS_RSH="${CVS_ECLASS_ORIG_CVS_RSH}"
474 if [[ ${CVS_ECLASS_ORIG_SSH_ASKPASS+set} == "set" ]] ; then
475 export SSH_ASKPASS="${CVS_ECLASS_ORIG_SSH_ASKPASS}"
480 if [[ ${CVS_ECLASS_ORIG_DISPLAY+set} == "set" ]] ; then
481 export DISPLAY="${CVS_ECLASS_ORIG_DISPLAY}"
487 # Restore ownership. Not sure why this is needed, but someone
488 # added it in the orig ECVS_RUNAS stuff.
489 if [[ -n ${ECVS_RUNAS} ]] ; then
490 chown $(whoami) "${T}/cvspass"
495 # @FUNCTION: cvs_src_unpack
497 # The cvs src_unpack function, which will be exported
500 debug-print-function ${FUNCNAME} "$@"
502 debug-print "${FUNCNAME}: init:
503 ECVS_CVS_COMMAND=${ECVS_CVS_COMMAND}
504 ECVS_UP_OPTS=${ECVS_UP_OPTS}
505 ECVS_CO_OPTS=${ECVS_CO_OPTS}
506 ECVS_TOP_DIR=${ECVS_TOP_DIR}
507 ECVS_SERVER=${ECVS_SERVER}
508 ECVS_USER=${ECVS_USER}
509 ECVS_PASS=${ECVS_PASS}
510 ECVS_MODULE=${ECVS_MODULE}
511 ECVS_LOCAL=${ECVS_LOCAL}
512 ECVS_RUNAS=${ECVS_RUNAS}
513 ECVS_LOCALNAME=${ECVS_LOCALNAME}"
515 [[ -z ${ECVS_MODULE} ]] && die "ERROR: CVS module not set, cannot continue."
517 local ECVS_LOCALNAME=${ECVS_LOCALNAME:-${ECVS_MODULE}}
519 local sanitized_pn=$(echo "${PN}" | LC_ALL=C sed -e 's:[^A-Za-z0-9_]:_:g')
520 local offline_pkg_var="ECVS_OFFLINE_${sanitized_pn}"
521 if [[ -n ${!offline_pkg_var}${ECVS_OFFLINE} ]] || [[ ${ECVS_SERVER} == "offline" ]] ; then
522 # We're not required to fetch anything; the module already
523 # exists and shouldn't be updated.
524 if [[ -d ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} ]] ; then
525 debug-print "${FUNCNAME}: offline mode"
527 debug-print "${FUNCNAME}: Offline mode specified but directory ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} not found, exiting with error"
528 die "ERROR: Offline mode specified, but directory ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} not found. Aborting."
530 elif [[ -n ${ECVS_SERVER} ]] ; then # ECVS_SERVER!=offline --> real fetching mode
531 einfo "Fetching CVS module ${ECVS_MODULE} into ${ECVS_TOP_DIR} ..."
533 else # ECVS_SERVER not set
534 die "ERROR: CVS server not specified, cannot continue."
537 einfo "Copying ${ECVS_MODULE} from ${ECVS_TOP_DIR} ..."
538 debug-print "Copying module ${ECVS_MODULE} local_mode=${ECVS_LOCAL} from ${ECVS_TOP_DIR} ..."
540 # This is probably redundant, but best to make sure.
541 mkdir -p "${WORKDIR}/${ECVS_LOCALNAME}"
543 if [[ -n ${ECVS_LOCAL} ]] ; then
544 cp -f "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"/* "${WORKDIR}/${ECVS_LOCALNAME}"
546 cp -Rf "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}" "${WORKDIR}/${ECVS_LOCALNAME}/.."
549 # Not exactly perfect, but should be pretty close #333773
550 export ECVS_VERSION=$(
551 find "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}/" -ipath '*/CVS/Entries' -exec cat {} + | \
557 # If the directory is empty, remove it; empty directories cannot
558 # exist in cvs. This happens when, for example, kde-source
559 # requests module/doc/subdir which doesn't exist. Still create
560 # the empty directory in workdir though.
561 if [[ $(ls -A "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}") == "CVS" ]] ; then
562 debug-print "${FUNCNAME}: removing empty CVS directory ${ECVS_LOCALNAME}"
563 rm -rf "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"
566 # Implement some of base_src_unpack's functionality; note however
567 # that base.eclass may not have been inherited!
568 if [[ -n ${PATCHES} ]] ; then
569 debug-print "${FUNCNAME}: PATCHES=${PATCHES,} S=${S}, autopatching"
572 # Make sure we don't try to apply patches more than once,
573 # since cvs_src_unpack is usually called several times from
574 # e.g. kde-source_src_unpack
578 einfo "CVS module ${ECVS_MODULE} is now in ${WORKDIR}"
581 EXPORT_FUNCTIONS src_unpack