1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 # vapier@gentoo.org (and anyone who wants to help)
7 # @SUPPORTED_EAPIS: 4 5 6 7
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
21 # Implement more auth types (gserver?, kserver?)
23 # Support additional remote shells with `ext' authentication (does
24 # anyone actually need to use it with anything other than SSH?)
27 # Users shouldn't change these settings! The ebuild/eclass inheriting
28 # this eclass will take care of that. If you want to set the global
29 # KDE cvs ebuilds' settings, see the comments in kde-source.eclass.
31 # @ECLASS-VARIABLE: ECVS_CVS_COMPRESS
33 # Set the default compression level. Has no effect when ECVS_CVS_COMMAND
34 # is defined by ebuild/user.
35 : ${ECVS_CVS_COMPRESS:=-z1}
37 # @ECLASS-VARIABLE: ECVS_CVS_OPTIONS
39 # Additional options to the cvs commands. Has no effect when ECVS_CVS_COMMAND
40 # is defined by ebuild/user.
41 : ${ECVS_CVS_OPTIONS:=-q -f}
43 # @ECLASS-VARIABLE: ECVS_CVS_COMMAND
47 # You can set, for example, "cvs -t" for extensive debug information
48 # on the cvs connection. The default of "cvs -q -f -z4" means to be
49 # quiet, to disregard the ~/.cvsrc config file and to use maximum
51 : ${ECVS_CVS_COMMAND:=cvs ${ECVS_CVS_OPTIONS} ${ECVS_CVS_COMPRESS}}
53 # @ECLASS-VARIABLE: ECVS_UP_OPTS
55 # CVS options given after the cvs update command. Don't remove "-dP" or things
57 : ${ECVS_UP_OPTS:=-dP}
59 # @ECLASS-VARIABLE: ECVS_CO_OPTS
62 # CVS options given after the cvs checkout command.
64 # @ECLASS-VARIABLE: ECVS_OFFLINE
66 # Set this variable to a non-empty value to disable the automatic updating of
67 # a CVS source tree. This is intended to be set outside the cvs source
69 : ${ECVS_OFFLINE:=${EVCS_OFFLINE}}
71 # @ECLASS-VARIABLE: ECVS_LOCAL
74 # If this is set, the CVS module will be fetched non-recursively.
75 # Refer to the information in the CVS man page regarding the -l
76 # command option (not the -l global option).
78 # @ECLASS-VARIABLE: ECVS_LOCALNAME
81 # Local name of checkout directory
83 # This is useful if the module on the server is called something
84 # common like 'driver' or is nested deep in a tree, and you don't like
85 # useless empty directories.
87 # WARNING: Set this only from within ebuilds! If set in your shell or
88 # some such, things will break because the ebuild won't expect it and
89 # have e.g. a wrong $S setting.
91 # @ECLASS-VARIABLE: ECVS_TOP_DIR
93 # The directory under which CVS modules are checked out.
94 : ${ECVS_TOP_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/cvs-src"}
96 # @ECLASS-VARIABLE: ECVS_SERVER
100 # The format is "server:/dir", e.g. "anoncvs.kde.org:/home/kde".
101 # Remove the other parts of the full CVSROOT, which might look like
102 # ":pserver:anonymous@anoncvs.kde.org:/home/kde"; this is generated
103 # using other settings also.
105 # Set this to "offline" to disable fetching (i.e. to assume the module
106 # is already checked out in ECVS_TOP_DIR).
107 : ${ECVS_SERVER:="offline"}
109 # @ECLASS-VARIABLE: ECVS_MODULE
112 # The name of the CVS module to be fetched
114 # This must be set when cvs_src_unpack is called. This can include
115 # several directory levels, i.e. "foo/bar/baz"
116 #[[ -z ${ECVS_MODULE} ]] && die "$ECLASS: error: ECVS_MODULE not set, cannot continue"
118 # @ECLASS-VARIABLE: ECVS_DATE
121 # The date of the checkout. See the -D date_spec option in the cvs
122 # man page for more details.
124 # @ECLASS-VARIABLE: ECVS_BRANCH
127 # The name of the branch/tag to use
129 # The default is "HEAD". The following default _will_ reset your
130 # branch checkout to head if used.
131 #: ${ECVS_BRANCH:="HEAD"}
133 # @ECLASS-VARIABLE: ECVS_AUTH
135 # Authentication method to use
137 # Possible values are "pserver" and "ext". If `ext' authentication is
138 # used, the remote shell to use can be specified in CVS_RSH (SSH is
139 # used by default). Currently, the only supported remote shell for
140 # `ext' authentication is SSH.
142 # Armando Di Cianno <fafhrd@gentoo.org> 2004/09/27
143 # - Added "no" as a server type, which uses no AUTH method, nor
146 # "cvs -danoncvs@savannah.gnu.org:/cvsroot/backbone co System"
147 # ( from gnustep-apps/textedit )
148 : ${ECVS_AUTH:="pserver"}
150 # @ECLASS-VARIABLE: ECVS_USER
152 # Username to use for authentication on the remote server.
153 : ${ECVS_USER:="anonymous"}
155 # @ECLASS-VARIABLE: ECVS_PASS
158 # Password to use for authentication on the remote server
160 # @ECLASS-VARIABLE: ECVS_SSH_HOST_KEY
163 # If SSH is used for `ext' authentication, use this variable to
164 # specify the host key of the remote server. The format of the value
165 # should be the same format that is used for the SSH known hosts file.
167 # WARNING: If a SSH host key is not specified using this variable, the
168 # remote host key will not be verified.
170 # @ECLASS-VARIABLE: ECVS_CLEAN
173 # Set this to get a clean copy when updating (passes the
174 # -C option to cvs update)
179 # ssh is used for ext auth
182 if [[ ${ECVS_AUTH} == "ext" ]] ; then
184 [[ -z ${CVS_RSH} ]] && export CVS_RSH="ssh"
185 if [[ ${CVS_RSH} != "ssh" ]] ; then
186 die "Support for ext auth with clients other than ssh has not been implemented yet"
188 DEPEND+=" net-misc/openssh"
193 7) BDEPEND="${DEPEND}"; DEPEND="" ;;
194 *) die "${ECLASS}: EAPI ${EAPI:-0} is not supported" ;;
197 # called from cvs_src_unpack
199 # Make these options local variables so that the global values are
200 # not affected by modifications in this function.
202 local ECVS_COMMAND=${ECVS_COMMAND}
203 local ECVS_UP_OPTS=${ECVS_UP_OPTS}
204 local ECVS_CO_OPTS=${ECVS_CO_OPTS}
206 debug-print-function ${FUNCNAME} "$@"
208 # Update variables that are modified by ebuild parameters, which
209 # should be effective every time cvs_fetch is called, and not just
210 # every time cvs.eclass is inherited
212 # Handle parameter for local (non-recursive) fetching
214 if [[ -n ${ECVS_LOCAL} ]] ; then
219 # Handle ECVS_BRANCH option
221 # Because CVS auto-switches branches, we just have to pass the
222 # correct -rBRANCH option when updating.
224 if [[ -n ${ECVS_BRANCH} ]] ; then
225 ECVS_UP_OPTS+=" -r${ECVS_BRANCH}"
226 ECVS_CO_OPTS+=" -r${ECVS_BRANCH}"
229 # Handle ECVS_LOCALNAME, which specifies the local directory name
230 # to use. Note that the -d command option is not equivalent to
231 # the global -d option.
233 if [[ ${ECVS_LOCALNAME} != "${ECVS_MODULE}" ]] ; then
234 ECVS_CO_OPTS+=" -d ${ECVS_LOCALNAME}"
237 if [[ -n ${ECVS_CLEAN} ]] ; then
241 if [[ -n ${ECVS_DATE} ]] ; then
242 ECVS_CO_OPTS+=" -D ${ECVS_DATE}"
243 ECVS_UP_OPTS+=" -D ${ECVS_DATE}"
246 # Create the top dir if needed
248 if [[ ! -d ${ECVS_TOP_DIR} ]] ; then
249 # Note that the addwrite statements in this block are only
250 # there to allow creating ECVS_TOP_DIR; we allow writing
251 # inside it separately.
253 # This is because it's simpler than trying to find out the
254 # parent path of the directory, which would need to be the
255 # real path and not a symlink for things to work (so we can't
256 # just remove the last path element in the string)
258 debug-print "${FUNCNAME}: checkout mode. creating cvs directory"
261 mkdir -p "/${ECVS_TOP_DIR}"
262 export SANDBOX_WRITE="${SANDBOX_WRITE//:\/foobar:\/}"
265 # In case ECVS_TOP_DIR is a symlink to a dir, get the real path,
266 # otherwise addwrite() doesn't work.
268 cd -P "${ECVS_TOP_DIR}" >/dev/null
271 # Disable the sandbox for this dir
272 addwrite "${ECVS_TOP_DIR}"
274 # Determine the CVS command mode (checkout or update)
275 if [[ ! -d ${ECVS_TOP_DIR}/${ECVS_LOCALNAME}/CVS ]] ; then
281 # Our server string (i.e. CVSROOT) without the password so it can
283 local connection="${ECVS_AUTH}"
284 if [[ ${ECVS_AUTH} == "no" ]] ; then
285 local server="${ECVS_USER}@${ECVS_SERVER}"
287 [[ -n ${ECVS_PROXY} ]] && connection+=";proxy=${ECVS_PROXY}"
288 [[ -n ${ECVS_PROXY_PORT} ]] && connection+=";proxyport=${ECVS_PROXY_PORT}"
289 local server=":${connection}:${ECVS_USER}@${ECVS_SERVER}"
292 # Switch servers automagically if needed
293 if [[ ${mode} == "update" ]] ; then
294 cd "/${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"
295 local oldserver=$(cat CVS/Root)
296 if [[ ${server} != "${oldserver}" ]] ; then
297 einfo "Changing the CVS server from ${oldserver} to ${server}:"
298 debug-print "${FUNCNAME}: Changing the CVS server from ${oldserver} to ${server}:"
300 einfo "Searching for CVS directories ..."
301 local cvsdirs=$(find . -iname CVS -print)
302 debug-print "${FUNCNAME}: CVS directories found:"
303 debug-print "${cvsdirs}"
305 einfo "Modifying CVS directories ..."
307 for x in ${cvsdirs} ; do
308 debug-print "In ${x}"
309 echo "${server}" > "${x}/Root"
314 # Prepare a cvspass file just for this session, we don't want to
315 # mess with ~/.cvspass
317 export CVS_PASSFILE="${T}/cvspass"
319 # The server string with the password in it, for login (only used for pserver)
320 cvsroot_pass=":${connection}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER}"
322 # Ditto without the password, for checkout/update after login, so
323 # that the CVS/Root files don't contain the password in plaintext
324 if [[ ${ECVS_AUTH} == "no" ]] ; then
325 cvsroot_nopass="${ECVS_USER}@${ECVS_SERVER}"
327 cvsroot_nopass=":${connection}:${ECVS_USER}@${ECVS_SERVER}"
331 cmdlogin=( ${ECVS_CVS_COMMAND} -d "${cvsroot_pass}" login )
332 cmdupdate=( ${ECVS_CVS_COMMAND} -d "${cvsroot_nopass}" update ${ECVS_UP_OPTS} ${ECVS_LOCALNAME} )
333 cmdcheckout=( ${ECVS_CVS_COMMAND} -d "${cvsroot_nopass}" checkout ${ECVS_CO_OPTS} ${ECVS_MODULE} )
338 if [[ ${ECVS_AUTH} == "pserver" ]] ; then
339 einfo "Running ${cmdlogin[*]}"
340 "${cmdlogin[@]}" || die "cvs login command failed"
341 if [[ ${mode} == "update" ]] ; then
342 einfo "Running ${cmdupdate[*]}"
343 "${cmdupdate[@]}" || die "cvs update command failed"
344 elif [[ ${mode} == "checkout" ]] ; then
345 einfo "Running ${cmdcheckout[*]}"
346 "${cmdcheckout[@]}" || die "cvs checkout command failed"
348 elif [[ ${ECVS_AUTH} == "ext" || ${ECVS_AUTH} == "no" ]] ; then
349 # Hack to support SSH password authentication
351 # Backup environment variable values
352 local CVS_ECLASS_ORIG_CVS_RSH="${CVS_RSH}"
354 if [[ ${SSH_ASKPASS+set} == "set" ]] ; then
355 local CVS_ECLASS_ORIG_SSH_ASKPASS="${SSH_ASKPASS}"
357 unset CVS_ECLASS_ORIG_SSH_ASKPASS
360 if [[ ${DISPLAY+set} == "set" ]] ; then
361 local CVS_ECLASS_ORIG_DISPLAY="${DISPLAY}"
363 unset CVS_ECLASS_ORIG_DISPLAY
366 if [[ ${CVS_RSH} == "ssh" ]] ; then
367 # Force SSH to use SSH_ASKPASS by creating python wrapper
369 export CVS_RSH="${T}/cvs_sshwrapper"
370 cat > "${CVS_RSH}"<<EOF
371 #!${EPREFIX}/usr/bin/python
376 fd = os.open('/dev/tty', 2)
379 fcntl.ioctl(fd, TIOCNOTTY)
385 newarglist = sys.argv[:]
388 # disable X11 forwarding which causes .xauth access violations
389 # - 20041205 Armando Di Cianno <fafhrd@gentoo.org>
390 echo "newarglist.insert(1, '-oClearAllForwardings=yes')" \
392 echo "newarglist.insert(1, '-oForwardX11=no')" \
395 # Handle SSH host key checking
397 local CVS_ECLASS_KNOWN_HOSTS="${T}/cvs_ssh_known_hosts"
398 echo "newarglist.insert(1, '-oUserKnownHostsFile=${CVS_ECLASS_KNOWN_HOSTS}')" \
401 if [[ -z ${ECVS_SSH_HOST_KEY} ]] ; then
402 ewarn "Warning: The SSH host key of the remote server will not be verified."
403 einfo "A temporary known hosts list will be used."
404 local CVS_ECLASS_STRICT_HOST_CHECKING="no"
405 touch "${CVS_ECLASS_KNOWN_HOSTS}"
407 local CVS_ECLASS_STRICT_HOST_CHECKING="yes"
408 echo "${ECVS_SSH_HOST_KEY}" > "${CVS_ECLASS_KNOWN_HOSTS}"
411 echo -n "newarglist.insert(1, '-oStrictHostKeyChecking=" \
413 echo "${CVS_ECLASS_STRICT_HOST_CHECKING}')" \
415 echo "os.execv('${EPREFIX}/usr/bin/ssh', newarglist)" \
418 chmod a+x "${CVS_RSH}"
420 # Make sure DISPLAY is set (SSH will not use SSH_ASKPASS
421 # if DISPLAY is not set)
423 : ${DISPLAY:="DISPLAY"}
426 # Create a dummy executable to echo ${ECVS_PASS}
428 export SSH_ASKPASS="${T}/cvs_sshechopass"
429 if [[ ${ECVS_AUTH} != "no" ]] ; then
430 echo -en "#!/bin/bash\necho \"${ECVS_PASS}\"\n" \
433 echo -en "#!/bin/bash\nreturn\n" \
436 chmod a+x "${SSH_ASKPASS}"
439 if [[ ${mode} == "update" ]] ; then
440 einfo "Running ${cmdupdate[*]}"
441 "${cmdupdate[@]}" || die "cvs update command failed"
442 elif [[ ${mode} == "checkout" ]] ; then
443 einfo "Running ${cmdcheckout[*]}"
444 "${cmdcheckout[@]}" || die "cvs checkout command failed"
447 # Restore environment variable values
448 export CVS_RSH="${CVS_ECLASS_ORIG_CVS_RSH}"
449 if [[ ${CVS_ECLASS_ORIG_SSH_ASKPASS+set} == "set" ]] ; then
450 export SSH_ASKPASS="${CVS_ECLASS_ORIG_SSH_ASKPASS}"
455 if [[ ${CVS_ECLASS_ORIG_DISPLAY+set} == "set" ]] ; then
456 export DISPLAY="${CVS_ECLASS_ORIG_DISPLAY}"
463 # @FUNCTION: cvs_src_unpack
465 # The cvs src_unpack function, which will be exported
468 debug-print-function ${FUNCNAME} "$@"
470 debug-print "${FUNCNAME}: init:
471 ECVS_CVS_COMMAND=${ECVS_CVS_COMMAND}
472 ECVS_UP_OPTS=${ECVS_UP_OPTS}
473 ECVS_CO_OPTS=${ECVS_CO_OPTS}
474 ECVS_TOP_DIR=${ECVS_TOP_DIR}
475 ECVS_SERVER=${ECVS_SERVER}
476 ECVS_USER=${ECVS_USER}
477 ECVS_PASS=${ECVS_PASS}
478 ECVS_MODULE=${ECVS_MODULE}
479 ECVS_LOCAL=${ECVS_LOCAL}
480 ECVS_LOCALNAME=${ECVS_LOCALNAME}"
482 [[ -z ${ECVS_MODULE} ]] && die "ERROR: CVS module not set, cannot continue."
484 local ECVS_LOCALNAME=${ECVS_LOCALNAME:-${ECVS_MODULE}}
486 local sanitized_pn=$(echo "${PN}" | LC_ALL=C sed -e 's:[^A-Za-z0-9_]:_:g')
487 local offline_pkg_var="ECVS_OFFLINE_${sanitized_pn}"
488 if [[ -n ${!offline_pkg_var}${ECVS_OFFLINE} ]] || [[ ${ECVS_SERVER} == "offline" ]] ; then
489 # We're not required to fetch anything; the module already
490 # exists and shouldn't be updated.
491 if [[ -d ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} ]] ; then
492 debug-print "${FUNCNAME}: offline mode"
494 debug-print "${FUNCNAME}: Offline mode specified but directory ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} not found, exiting with error"
495 die "ERROR: Offline mode specified, but directory ${ECVS_TOP_DIR}/${ECVS_LOCALNAME} not found. Aborting."
497 elif [[ -n ${ECVS_SERVER} ]] ; then # ECVS_SERVER!=offline --> real fetching mode
498 einfo "Fetching CVS module ${ECVS_MODULE} into ${ECVS_TOP_DIR} ..."
500 else # ECVS_SERVER not set
501 die "ERROR: CVS server not specified, cannot continue."
504 einfo "Copying ${ECVS_MODULE} from ${ECVS_TOP_DIR} ..."
505 debug-print "Copying module ${ECVS_MODULE} local_mode=${ECVS_LOCAL} from ${ECVS_TOP_DIR} ..."
507 # This is probably redundant, but best to make sure.
508 mkdir -p "${WORKDIR}/${ECVS_LOCALNAME}"
510 if [[ -n ${ECVS_LOCAL} ]] ; then
511 cp -f "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"/* "${WORKDIR}/${ECVS_LOCALNAME}"
513 cp -Rf "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}" "${WORKDIR}/${ECVS_LOCALNAME}/.."
516 # Not exactly perfect, but should be pretty close #333773
517 export ECVS_VERSION=$(
518 find "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}/" -ipath '*/CVS/Entries' -exec cat {} + | \
524 # If the directory is empty, remove it; empty directories cannot
525 # exist in cvs. This happens when, for example, kde-source
526 # requests module/doc/subdir which doesn't exist. Still create
527 # the empty directory in workdir though.
528 if [[ $(ls -A "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}") == "CVS" ]] ; then
529 debug-print "${FUNCNAME}: removing empty CVS directory ${ECVS_LOCALNAME}"
530 rm -rf "${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"
533 einfo "CVS module ${ECVS_MODULE} is now in ${WORKDIR}"
536 EXPORT_FUNCTIONS src_unpack