1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 # vapier@gentoo.org (and anyone who wants to help)
7 # @BLURB: This eclass provides generic cvs fetching functions
9 # This eclass provides the generic cvs fetching functions. To use this from an
10 # ebuild, set the ECLASS VARIABLES as specified below in your ebuild before
11 # inheriting. Then either leave the default src_unpack or extend over
12 # cvs_src_unpack. If you find that you need to call the cvs_* functions
13 # directly, I'd be interested to hear about it.
15 if [[ -z ${_CVS_ECLASS} ]]; then
22 # Implement more auth types (gserver?, kserver?)
24 # Support additional remote shells with `ext' authentication (does
25 # anyone actually need to use it with anything other than SSH?)
28 # Users shouldn't change these settings! The ebuild/eclass inheriting
29 # this eclass will take care of that. If you want to set the global
30 # KDE cvs ebuilds' settings, see the comments in kde-source.eclass.
32 # @ECLASS-VARIABLE: ECVS_CVS_COMPRESS
34 # Set the default compression level. Has no effect when ECVS_CVS_COMMAND
35 # is defined by ebuild/user.
36 : ${ECVS_CVS_COMPRESS:=-z1}
38 # @ECLASS-VARIABLE: ECVS_CVS_OPTIONS
40 # Additional options to the cvs commands. Has no effect when ECVS_CVS_COMMAND
41 # is defined by ebuild/user.
42 : ${ECVS_CVS_OPTIONS:=-q -f}
44 # @ECLASS-VARIABLE: ECVS_CVS_COMMAND
48 # You can set, for example, "cvs -t" for extensive debug information
49 # on the cvs connection. The default of "cvs -q -f -z4" means to be
50 # quiet, to disregard the ~/.cvsrc config file and to use maximum
52 : ${ECVS_CVS_COMMAND:=cvs ${ECVS_CVS_OPTIONS} ${ECVS_CVS_COMPRESS}}
54 # @ECLASS-VARIABLE: ECVS_UP_OPTS
56 # CVS options given after the cvs update command. Don't remove "-dP" or things
58 : ${ECVS_UP_OPTS:=-dP}
60 # @ECLASS-VARIABLE: ECVS_CO_OPTS
63 # CVS options given after the cvs checkout command.
65 # @ECLASS-VARIABLE: ECVS_OFFLINE
67 # Set this variable to a non-empty value to disable the automatic updating of
68 # a CVS source tree. This is intended to be set outside the cvs source
70 : ${ECVS_OFFLINE:=${EVCS_OFFLINE}}
72 # @ECLASS-VARIABLE: ECVS_LOCAL
75 # If this is set, the CVS module will be fetched non-recursively.
76 # Refer to the information in the CVS man page regarding the -l
77 # command option (not the -l global option).
79 # @ECLASS-VARIABLE: ECVS_LOCALNAME
82 # Local name of checkout directory
84 # This is useful if the module on the server is called something
85 # common like 'driver' or is nested deep in a tree, and you don't like
86 # useless empty directories.
88 # WARNING: Set this only from within ebuilds! If set in your shell or
89 # some such, things will break because the ebuild won't expect it and
90 # have e.g. a wrong $S setting.
92 # @ECLASS-VARIABLE: ECVS_TOP_DIR
94 # The directory under which CVS modules are checked out.
95 : ${ECVS_TOP_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/cvs-src"}
97 # @ECLASS-VARIABLE: ECVS_SERVER
101 # The format is "server:/dir", e.g. "anoncvs.kde.org:/home/kde".
102 # Remove the other parts of the full CVSROOT, which might look like
103 # ":pserver:anonymous@anoncvs.kde.org:/home/kde"; this is generated
104 # using other settings also.
106 # Set this to "offline" to disable fetching (i.e. to assume the module
107 # is already checked out in ECVS_TOP_DIR).
108 : ${ECVS_SERVER:="offline"}
110 # @ECLASS-VARIABLE: ECVS_MODULE
113 # The name of the CVS module to be fetched
115 # This must be set when cvs_src_unpack is called. This can include
116 # several directory levels, i.e. "foo/bar/baz"
117 #[[ -z ${ECVS_MODULE} ]] && die "$ECLASS: error: ECVS_MODULE not set, cannot continue"
119 # @ECLASS-VARIABLE: ECVS_DATE
122 # The date of the checkout. See the -D date_spec option in the cvs
123 # man page for more details.
125 # @ECLASS-VARIABLE: ECVS_BRANCH
128 # The name of the branch/tag to use
130 # The default is "HEAD". The following default _will_ reset your
131 # branch checkout to head if used.
132 #: ${ECVS_BRANCH:="HEAD"}
134 # @ECLASS-VARIABLE: ECVS_AUTH
136 # Authentication method to use
138 # Possible values are "pserver" and "ext". If `ext' authentication is
139 # used, the remote shell to use can be specified in CVS_RSH (SSH is
140 # used by default). Currently, the only supported remote shell for
141 # `ext' authentication is SSH.
143 # Armando Di Cianno <fafhrd@gentoo.org> 2004/09/27
144 # - Added "no" as a server type, which uses no AUTH method, nor
147 # "cvs -danoncvs@savannah.gnu.org:/cvsroot/backbone co System"
148 # ( from gnustep-apps/textedit )
149 : ${ECVS_AUTH:="pserver"}
151 # @ECLASS-VARIABLE: ECVS_USER
153 # Username to use for authentication on the remote server.
154 : ${ECVS_USER:="anonymous"}
156 # @ECLASS-VARIABLE: ECVS_PASS
159 # Password to use for authentication on the remote server
161 # @ECLASS-VARIABLE: ECVS_SSH_HOST_KEY
164 # If SSH is used for `ext' authentication, use this variable to
165 # specify the host key of the remote server. The format of the value
166 # should be the same format that is used for the SSH known hosts file.
168 # WARNING: If a SSH host key is not specified using this variable, the
169 # remote host key will not be verified.
171 # @ECLASS-VARIABLE: ECVS_CLEAN
174 # Set this to get a clean copy when updating (passes the
175 # -C option to cvs update)
177 # @ECLASS-VARIABLE: ECVS_RUNAS
180 # Specifies an alternate (non-root) user to use to run cvs. Currently
181 # b0rked and wouldn't work with portage userpriv anyway without
184 # : ${ECVS_RUNAS:=$(whoami)}
187 # ssh is used for ext auth
188 # sudo is used to run as a specified user
191 [[ -n ${ECVS_RUNAS} ]] && DEPEND+=" app-admin/sudo"
193 if [[ ${ECVS_AUTH} == "ext" ]] ; then
195 [[ -z ${CVS_RSH} ]] && export CVS_RSH="ssh"
196 if [[ ${CVS_RSH} != "ssh" ]] ; then
197 die "Support for ext auth with clients other than ssh has not been implemented yet"
199 DEPEND+=" net-misc/openssh"
202 # called from cvs_src_unpack
204 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
206 # Make these options local variables so that the global values are
207 # not affected by modifications in this function.
209 local ECVS_COMMAND=${ECVS_COMMAND}
210 local ECVS_UP_OPTS=${ECVS_UP_OPTS}
211 local ECVS_CO_OPTS=${ECVS_CO_OPTS}
213 debug-print-function ${FUNCNAME} "$@"
215 # Update variables that are modified by ebuild parameters, which
216 # should be effective every time cvs_fetch is called, and not just
217 # every time cvs.eclass is inherited
219 # Handle parameter for local (non-recursive) fetching
221 if [[ -n ${ECVS_LOCAL} ]] ; then
226 # Handle ECVS_BRANCH option
228 # Because CVS auto-switches branches, we just have to pass the
229 # correct -rBRANCH option when updating.
231 if [[ -n ${ECVS_BRANCH} ]] ; then
232 ECVS_UP_OPTS+=" -r${ECVS_BRANCH}"
233 ECVS_CO_OPTS+=" -r${ECVS_BRANCH}"
236 # Handle ECVS_LOCALNAME, which specifies the local directory name
237 # to use. Note that the -d command option is not equivalent to
238 # the global -d option.
240 if [[ ${ECVS_LOCALNAME} != "${ECVS_MODULE}" ]] ; then
241 ECVS_CO_OPTS+=" -d ${ECVS_LOCALNAME}"
244 if [[ -n ${ECVS_CLEAN} ]] ; then
248 if [[ -n ${ECVS_DATE} ]] ; then
249 ECVS_CO_OPTS+=" -D ${ECVS_DATE}"
250 ECVS_UP_OPTS+=" -D ${ECVS_DATE}"
253 # It would be easiest to always be in "run-as mode", logic-wise,
254 # if sudo didn't ask for a password even when sudo'ing to `whoami`.
256 if [[ -z ${ECVS_RUNAS} ]] ; then
259 run="sudo -u ${ECVS_RUNAS}"
262 # Create the top dir if needed
264 if [[ ! -d ${ECVS_TOP_DIR} ]] ; then
265 # Note that the addwrite statements in this block are only
266 # there to allow creating ECVS_TOP_DIR; we allow writing
267 # inside it separately.
269 # This is because it's simpler than trying to find out the
270 # parent path of the directory, which would need to be the
271 # real path and not a symlink for things to work (so we can't
272 # just remove the last path element in the string)
274 debug-print "${FUNCNAME}: checkout mode. creating cvs directory"
277 ${run} mkdir -p "/${ECVS_TOP_DIR}"
278 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
281 # In case ECVS_TOP_DIR is a symlink to a dir, get the real path,
282 # otherwise addwrite() doesn't work.
284 cd -P "${ECVS_TOP_DIR}" >/dev/null
287 # Disable the sandbox for this dir
288 addwrite "${ECVS_TOP_DIR}"
290 # Chown the directory and all of its contents
291 if [[ -n ${ECVS_RUNAS} ]] ; then
292 ${run} chown -R "${ECVS_RUNAS}" "/${ECVS_TOP_DIR}"
295 # Determine the CVS command mode (checkout or update)
296 if [[ ! -d ${ECVS_TOP_DIR}/${ECVS_LOCALNAME}/CVS ]] ; then
302 # Our server string (i.e. CVSROOT) without the password so it can
304 local connection="${ECVS_AUTH}"
305 if [[ ${ECVS_AUTH} == "no" ]] ; then
306 local server="${ECVS_USER}@${ECVS_SERVER}"
308 [[ -n ${ECVS_PROXY} ]] && connection+=";proxy=${ECVS_PROXY}"
309 [[ -n ${ECVS_PROXY_PORT} ]] && connection+=";proxyport=${ECVS_PROXY_PORT}"
310 local server=":${connection}:${ECVS_USER}@${ECVS_SERVER}"
313 # Switch servers automagically if needed
314 if [[ ${mode} == "update" ]] ; then
315 cd "/${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"
316 local oldserver=$(${run} cat CVS/Root)
317 if [[ ${server} != "${oldserver}" ]] ; then
318 einfo "Changing the CVS server from ${oldserver} to ${server}:"
319 debug-print "${FUNCNAME}: Changing the CVS server from ${oldserver} to ${server}:"
321 einfo "Searching for CVS directories ..."
322 local cvsdirs=$(${run} find . -iname CVS -print)
323 debug-print "${FUNCNAME}: CVS directories found:"
324 debug-print "${cvsdirs}"
326 einfo "Modifying CVS directories ..."
328 for x in ${cvsdirs} ; do
329 debug-print "In ${x}"
330 ${run} echo "${server}" > "${x}/Root"
335 # Prepare a cvspass file just for this session, we don't want to
336 # mess with ~/.cvspass
338 export CVS_PASSFILE="${T}/cvspass"
339 if [[ -n ${ECVS_RUNAS} ]] ; then
340 chown "${ECVS_RUNAS}" "${T}/cvspass"
343 # The server string with the password in it, for login (only used for pserver)
344 cvsroot_pass=":${connection}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER}"
346 # Ditto without the password, for checkout/update after login, so
347 # that the CVS/Root files don't contain the password in plaintext
348 if [[ ${ECVS_AUTH} == "no" ]] ; then
349 cvsroot_nopass="${ECVS_USER}@${ECVS_SERVER}"
351 cvsroot_nopass=":${connection}:${ECVS_USER}@${ECVS_SERVER}"
355 cmdlogin="${run} ${ECVS_CVS_COMMAND} -d \"${cvsroot_pass}\" login"
356 cmdupdate="${run} ${ECVS_CVS_COMMAND} -d \"${cvsroot_nopass}\" update ${ECVS_UP_OPTS} ${ECVS_LOCALNAME}"
357 cmdcheckout="${run} ${ECVS_CVS_COMMAND} -d \"${cvsroot_nopass}\" checkout ${ECVS_CO_OPTS} ${ECVS_MODULE}"
362 if [[ ${ECVS_AUTH} == "pserver" ]] ; then
363 einfo "Running ${cmdlogin}"
364 eval ${cmdlogin} || die "cvs login command failed"
365 if [[ ${mode} == "update" ]] ; then
366 einfo "Running ${cmdupdate}"
367 eval ${cmdupdate} || die "cvs update command failed"
368 elif [[ ${mode} == "checkout" ]] ; then
369 einfo "Running ${cmdcheckout}"
370 eval ${cmdcheckout} || die "cvs checkout command failed"
372 elif [[ ${ECVS_AUTH} == "ext" || ${ECVS_AUTH} == "no" ]] ; then
373 # Hack to support SSH password authentication
375 # Backup environment variable values
376 local CVS_ECLASS_ORIG_CVS_RSH="${CVS_RSH}"
378 if [[ ${SSH_ASKPASS+set} == "set" ]] ; then
379 local CVS_ECLASS_ORIG_SSH_ASKPASS="${SSH_ASKPASS}"
381 unset CVS_ECLASS_ORIG_SSH_ASKPASS
384 if [[ ${DISPLAY+set} == "set" ]] ; then
385 local CVS_ECLASS_ORIG_DISPLAY="${DISPLAY}"
387 unset CVS_ECLASS_ORIG_DISPLAY
390 if [[ ${CVS_RSH} == "ssh" ]] ; then
391 # Force SSH to use SSH_ASKPASS by creating python wrapper
393 export CVS_RSH="${T}/cvs_sshwrapper"
394 cat > "${CVS_RSH}"<<EOF
395 #!${EPREFIX}/usr/bin/python
400 fd = os.open('/dev/tty', 2)
403 fcntl.ioctl(fd, TIOCNOTTY)
409 newarglist = sys.argv[:]
412 # disable X11 forwarding which causes .xauth access violations
413 # - 20041205 Armando Di Cianno <fafhrd@gentoo.org>
414 echo "newarglist.insert(1, '-oClearAllForwardings=yes')" \
416 echo "newarglist.insert(1, '-oForwardX11=no')" \
419 # Handle SSH host key checking
421 local CVS_ECLASS_KNOWN_HOSTS="${T}/cvs_ssh_known_hosts"
422 echo "newarglist.insert(1, '-oUserKnownHostsFile=${CVS_ECLASS_KNOWN_HOSTS}')" \
425 if [[ -z ${ECVS_SSH_HOST_KEY} ]] ; then
426 ewarn "Warning: The SSH host key of the remote server will not be verified."
427 einfo "A temporary known hosts list will be used."
428 local CVS_ECLASS_STRICT_HOST_CHECKING="no"
429 touch "${CVS_ECLASS_KNOWN_HOSTS}"
431 local CVS_ECLASS_STRICT_HOST_CHECKING="yes"
432 echo "${ECVS_SSH_HOST_KEY}" > "${CVS_ECLASS_KNOWN_HOSTS}"
435 echo -n "newarglist.insert(1, '-oStrictHostKeyChecking=" \
437 echo "${CVS_ECLASS_STRICT_HOST_CHECKING}')" \
439 echo "os.execv('${EPREFIX}/usr/bin/ssh', newarglist)" \
442 chmod a+x "${CVS_RSH}"
444 # Make sure DISPLAY is set (SSH will not use SSH_ASKPASS
445 # if DISPLAY is not set)
447 : ${DISPLAY:="DISPLAY"}
450 # Create a dummy executable to echo ${ECVS_PASS}
452 export SSH_ASKPASS="${T}/cvs_sshechopass"
453 if [[ ${ECVS_AUTH} != "no" ]] ; then
454 echo -en "#!/bin/bash\necho \"${ECVS_PASS}\"\n" \
457 echo -en "#!/bin/bash\nreturn\n" \
460 chmod a+x "${SSH_ASKPASS}"
463 if [[ ${mode} == "update" ]] ; then
464 einfo "Running ${cmdupdate}"
465 eval ${cmdupdate} || die "cvs update command failed"
466 elif [[ ${mode} == "checkout" ]] ; then
467 einfo "Running ${cmdcheckout}"
468 eval ${cmdcheckout} || die "cvs checkout command failed"
471 # Restore environment variable values
472 export CVS_RSH="${CVS_ECLASS_ORIG_CVS_RSH}"
473 if [[ ${CVS_ECLASS_ORIG_SSH_ASKPASS+set} == "set" ]] ; then
474 export SSH_ASKPASS="${CVS_ECLASS_ORIG_SSH_ASKPASS}"
479 if [[ ${CVS_ECLASS_ORIG_DISPLAY+set} == "set" ]] ; then
480 export DISPLAY="${CVS_ECLASS_ORIG_DISPLAY}"
486 # Restore ownership. Not sure why this is needed, but someone
487 # added it in the orig ECVS_RUNAS stuff.
488 if [[ -n ${ECVS_RUNAS} ]] ; then
489 chown $(whoami) "${T}/cvspass"
494 # @FUNCTION: cvs_src_unpack
496 # The cvs src_unpack function, which will be exported
499 debug-print-function ${FUNCNAME} "$@"
501 debug-print "${FUNCNAME}: init:
502 ECVS_CVS_COMMAND=${ECVS_CVS_COMMAND}
503 ECVS_UP_OPTS=${ECVS_UP_OPTS}
504 ECVS_CO_OPTS=${ECVS_CO_OPTS}
505 ECVS_TOP_DIR=${ECVS_TOP_DIR}
506 ECVS_SERVER=${ECVS_SERVER}
507 ECVS_USER=${ECVS_USER}
508 ECVS_PASS=${ECVS_PASS}
509 ECVS_MODULE=${ECVS_MODULE}
510 ECVS_LOCAL=${ECVS_LOCAL}
511 ECVS_RUNAS=${ECVS_RUNAS}
512 ECVS_LOCALNAME=${ECVS_LOCALNAME}"
514 [[ -z ${ECVS_MODULE} ]] && die "ERROR: CVS module not set, cannot continue."
516 local ECVS_LOCALNAME=${ECVS_LOCALNAME:-${ECVS_MODULE}}
518 local sanitized_pn=$(echo "${PN}" | LC_ALL=C sed -e 's:[^A-Za-z0-9_]:_:g')
519 local offline_pkg_var="ECVS_OFFLINE_${sanitized_pn}"
520 if [[ -n ${!offline_pkg_var}${ECVS_OFFLINE} ]] || [[ ${ECVS_SERVER} == "offline" ]] ; then
521 # We're not required to fetch anything; the module already
522 # exists and shouldn't be updated.
523 if [[ -d ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} ]] ; then
524 debug-print "${FUNCNAME}: offline mode"
526 debug-print "${FUNCNAME}: Offline mode specified but directory ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} not found, exiting with error"
527 die "ERROR: Offline mode specified, but directory ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} not found. Aborting."
529 elif [[ -n ${ECVS_SERVER} ]] ; then # ECVS_SERVER!=offline --> real fetching mode
530 einfo "Fetching CVS module ${ECVS_MODULE} into ${ECVS_TOP_DIR} ..."
532 else # ECVS_SERVER not set
533 die "ERROR: CVS server not specified, cannot continue."
536 einfo "Copying ${ECVS_MODULE} from ${ECVS_TOP_DIR} ..."
537 debug-print "Copying module ${ECVS_MODULE} local_mode=${ECVS_LOCAL} from ${ECVS_TOP_DIR} ..."
539 # This is probably redundant, but best to make sure.
540 mkdir -p "${WORKDIR}/${ECVS_LOCALNAME}"
542 if [[ -n ${ECVS_LOCAL} ]] ; then
543 cp -f "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"/* "${WORKDIR}/${ECVS_LOCALNAME}"
545 cp -Rf "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}" "${WORKDIR}/${ECVS_LOCALNAME}/.."
548 # Not exactly perfect, but should be pretty close #333773
549 export ECVS_VERSION=$(
550 find "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}/" -ipath '*/CVS/Entries' -exec cat {} + | \
556 # If the directory is empty, remove it; empty directories cannot
557 # exist in cvs. This happens when, for example, kde-source
558 # requests module/doc/subdir which doesn't exist. Still create
559 # the empty directory in workdir though.
560 if [[ $(ls -A "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}") == "CVS" ]] ; then
561 debug-print "${FUNCNAME}: removing empty CVS directory ${ECVS_LOCALNAME}"
562 rm -rf "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"
565 # Implement some of base_src_unpack's functionality; note however
566 # that base.eclass may not have been inherited!
567 if [[ -n ${PATCHES} ]] ; then
568 debug-print "${FUNCNAME}: PATCHES=${PATCHES}, S=${S}, autopatching"
571 # Make sure we don't try to apply patches more than once,
572 # since cvs_src_unpack is usually called several times from
573 # e.g. kde-source_src_unpack
577 einfo "CVS module ${ECVS_MODULE} is now in ${WORKDIR}"
580 EXPORT_FUNCTIONS src_unpack