2 ## update-live-ebuilds - Program to update ebuilds that pull from various portage-type repositories.
3 ## Copyright (C) 2006-2009 Avuton Olrich <avuton@gmail.com>
5 ## This program is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
19 [ ${VERBOSE} -eq ${true} ] && echo "$@"
23 [ ${DEBUG} -eq ${true} ] && echo "$@"
26 function email_details
() {
27 echo "Please email details about this bug to "
28 echo "Avuton Olrich <avuton@gmail.com>, so I "
29 echo "can improve this script."
32 ################################################################################################################################################
33 ## Updates ${ebuild_epoch};
34 ## This is a function since portage has never put the correct epoch time in /var/db/pkg/*/*/COUNTER.
35 ################################################################################################################################################
36 ## Rather than grepping the CONTENTS, I would just use ${dir}/COUNTER, but portage doesn't not use epoch, and I'm not really quite sure
37 ## what it uses for a counter. I know all package managers use epoch in the CONTENTS file.
38 function update_ebuild_epoch
() {
40 if [ ${spec} -eq ${portage} ]; then
41 ebuild_epoch
=`grep obj ${dir}/CONTENTS | tail -n1 | awk '{sub(/^.* /,"")} 1'`
43 ebuild_epoch
=$
(cat ${dir}/COUNTER
)
45 CUREXPORTS
="${CUREXPORTS} ebuild_epoch"
48 ################################################################################################################################################
49 ## SCM success detector;
50 ## This is a convience function used in conjunction with a SCM's return argument to detect success/failure and report appropriately.
53 ## The true if the first argument is true, otherwise false.
56 ## $1: The argument given by the SCM's execution
57 ################################################################################################################################################
58 function update_check
() {
59 [ ${1} -eq ${true} ] && return ${true}
61 echo "Package ${provide} failed to update with error code: ${1}"
62 echo "If it is believed this is a problem with update-live-ebuilds, send me a verbose bug report"
64 UPDATE_FAIL_PACKAGES
="${UPDATE_FAIL_PACKAGES} ${provide}"
68 ################################################################################################################################################
69 ## Write to the ULE database;
70 ## This simply writes any information that will be needed next time to the update-live-ebuilds database in a format that can be sourced
71 ## for easy retreival.
77 ## $1: The ULE "key" or "cookie", basically the unique identifier that ULE uses to detect a difference between the last installed
78 ## repository revision and the current revision.
79 ## $2: The ULE database directory.
80 ################################################################################################################################################
81 function write_to_db
() {
82 [ ! -d "`dirname ${ule_file}`" ] && mkdir
-p "`dirname ${ule_file}`"
83 echo "ULE_COOKIE=\"${1}\"" > "${ule_file}"
86 ################################################################################################################################################
87 ## Extract a variable out of the current ebuild's portage database environment file;
88 ## This function simply automates detecting a variable in the portage database's environment file and extracts it into the current shell
89 ## for use by this script.
92 ## The number of failed variable extractions.
95 ## $@: An unlimited amount of variables to find in the environment file in the portage database.
96 ################################################################################################################################################
97 function extract_env
() {
101 tempvar
=$
(bzip2 -cd "${dir}/environment.bz2" |
grep "^${num}=")
102 if [ $?
-ne ${true} ]; then
103 tempvar
=$
(bzip2 -cd "${dir}/environment.bz2" |
grep "^export ${num}=")
104 if [ $?
-eq ${false} ]; then
105 decho
"Could not find variable ${num} for ${provide}"
109 tempvar
="${tempvar/export /}"
112 decho
"Found variable ${num} for ${provide}"
113 export "${tempvar//\'}"
114 CUREXPORTS
="${CUREXPORTS} ${tempvar//=*}"
120 ################################################################################################################################################
121 ## Convience wrapper for extract_env() to require no failure;
122 ## This wrapper simply executes the input in extract_env() and provides a failure message in the case that a failure occured.
128 ## $@: An unlimited amount of variables to find in the environment file in the portage database.
129 ################################################################################################################################################
130 function secure_env
() {
135 [ ${ret} -ne ${true} ] && vecho "${provide} inherits ${type} but doesn
't have necessary variables; skipping"
139 ################################################################################################################################################
140 ## Local repository directory detection;
141 ## This detects the local directory for repositories, and if it isn't found this will emit an error
147 ## $1: The directory to detect
148 ## $2: The name of the package provide
149 ################################################################################################################################################
150 function check_for_found
() {
154 ## This must be called with something beyond the directory, such as an info file or directory.
155 ## This regexp does a basic 'dirname' without forking a shell
156 if [[ "${dir}" =~
'/.*/' ]] && [ ! -d "${BASH_REMATCH[0]%%\/}" ]; then
157 echo -n "Couldn't find the original directory for ${provide}, "
158 [ ${locbase} -eq ${true} ] && echo 'skipping.' && return 1
161 emerger
${false} ||
return ${false}
162 export locbase
=${true}
165 if [ ! -d "${dir}" ] && [ ! -f "${dir}" ]; then
166 if [ ${ALL} -eq ${false} ] && [ ${BASELINE} -eq ${true} ]; then
167 [ "${BASELINE}" -eq ${true} ] && echo "Cannot find the directory to baseline: ${dir}" && return ${false}
169 [[ "${dir}" =~ '.*/(.*)' ]] ## Basename
171 echo "Couldn
't find the ${BASH_REMATCH[1]} information directory for ${provide}"
172 echo "Please provide details about where this package stores itself."
173 echo "Use -a to OVERRIDE this warning and reemerge"
179 emerger ${false} || return ${false}
180 export locbase=${true}
186 ################################################################################################################################################
187 ## Portage compatible installer execution;
188 ## This is where all portage compatible installation is executed. It is all done here so everywhere emerge is neede will have uniform
195 ## $1: Boolean to baseline the package or not.
196 ################################################################################################################################################
199 [ ${PRETEND} -eq ${true} ] && locopts="${locopts} ${EMERGE_PRETEND[${spec}]}"
201 ## Handle ULE_ASK_FILE
202 if [ -f "${ULE_ASK_FILE}" ]; then
203 grep -Eq "^($pprovide|${provide})$" "${ULE_ASK_FILE}"
204 if [ $? -eq ${true} ]; then
205 vecho "Package (${provide}) found in ULE_ASK, will ask before emerging..."
206 if [ -z "${EMERGE_ASK_OPTS[${spec}]}" ]; then
207 ${EMERGE_BINARY[${spec}]} ${EMERGE_EXT_OPTS[${spec}]} ${EMERGE_PRETEND[${spec}]} ${provide}
211 echo -n "Would you like to install this package? [yes/no] "
214 [ "${tmpopt}" == "no" ] && return ${true}
215 [ "${tmpopt}" == "yes" ] && break
218 locopts="${locopts} ${EMERGE_ASK_OPTS[${spec}]}"
223 ## Since we didn't
continue above
, we emerge now.
224 ${EMERGE_BINARY[${spec}]} ${locopts} ${EMERGE_EXT_OPTS[${spec}]} ${provide}
226 if [ $?
-ne ${true} ]; then
227 echo "It appears emerge of ${provide} failed, try again later..."
228 export FAILED_PACKAGES
="${FAILED_PACKAGES} ${provide}"
232 ## We need to pull the hash again, to ensure we have the correct hash, in case of PEEK
236 if [ ${1} -eq ${true} ] && [ ${PRETEND} -eq ${false} ]; then
237 write_to_db
"${newhash}" "${ULE_LOC}/${provide}"
239 ## Add to the success packages
240 export SUCCESS_PACKAGES
="${SUCCESS_PACKAGES} ${provide}"
246 ################################################################################################################################################
247 ## Hash detection begins;
248 ## This can either go through looking directly at the repository, or we update the local repository to detect updates.
249 ## Of course, local updating is the prefered method, though it is probably more likely to succeed in the objective, as the SCMs command
250 ## line interface may change and this would obviously cause problems, which will cause user notification at the update_check() after the
251 ## case statement completes.
253 ## To developers considering adding another SCM or fixing up an SCM detection, here's a few things to consider.
254 ## 1) Please make a peek mode if the SCM supports it.
255 ## 2) Attempt to use the ebuild's variables as much as possible, as these may change and it would be more accurate to take
256 ## the newer, maintained variables.
257 ## 3) Use ${prescm} and secure_env(), these will find problems before they happen.
258 ## 4) Don't rely on environment variables through sudo or ${prescm}. Sudo by default resets the environment during privelege drop.
259 ## 5) Avoid HASH_PROGRAM use; depend on native 'cookies', if possible.
260 ## 6) newhash needs to be the final calculation so the update_check() at the end of the case statement does it's job.
261 ## 7) When possible, don't use 'cd', use a repository updating argument.
262 ## 8) Be aware secure_env() is a costly function; use it only as necessary.
263 ################################################################################################################################################
264 function get_hash
() {
265 ## No need to check the local repository when ALL is selected, but we do need the newhash.
266 [ ${ALL} -eq ${true} ] && local locbase=${true}
273 secure_env
'ESVN_REPO_URI' ||
continue
274 extract_env
'ESVN_REVISION'
275 ESVN_REPO_URI
="${ESVN_REPO_URI%%/}"
277 ## This is a simple test to test for: svn://svn.blah.org/svn/blah@592 (being the revision)
278 test="${ESVN_REPO_URI##*@}"
279 if [ "${test//[[:digit:]]}" == '' ] && [ -n "${ESVN_REPO_URI}" ]; then
280 newhash
="${ESVN_REPO_URI##*@}"
281 dinfo
"Newhash generated from ESVN_REPO_URI."
285 if [ "${ESVN_REVISION}" == '' ] && [ -n "${ESVN_REVISION}" ]; then
286 newhash
="${ESVN_REVISION}"
287 dinfo
"Newhash generated from ESVN_REVISION."
290 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ] && [ -n ${newhash} ]; then
291 newhash
=$
(svn info
${ESVN_REPO_URI} |
grep 'Last Changed Rev' |
awk '{sub(/^.* /,"")} 1')
294 ## Subversions' binaries are extremely unreliable. Cannot count on svn info to give something useful.
295 if [ -z "${newhash}" ]; then
296 secure_env
'ESVN_STORE_DIR' 'ESVN_PROJECT' 'ESVN_UPDATE_CMD' 'ESVN_OPTIONS' ||
continue
298 found
="${ESVN_STORE_DIR}/${ESVN_PROJECT}/${ESVN_REPO_URI##*/}"
299 check_for_found
"${found}/.svn" "${provide}" ||
continue
301 if [ ${locbase} -eq ${false} ]; then
302 decho
${prescm} ${ESVN_UPDATE_CMD} ${ESVN_OPTIONS} --quiet --config-dir="${ESVN_STORE_DIR}/.subversion" ${found}
303 ${prescm} ${ESVN_UPDATE_CMD} ${ESVN_OPTIONS} --quiet --config-dir="${ESVN_STORE_DIR}/.subversion" ${found}
304 update_check $?
${provide} ||
continue
306 newhash
=$
(svnversion
-c ${found} |
awk '{sub(/.*:/,"")} 1')
308 ## Check the repository for modification, this is usually a sign of trouble.
309 if [ ${newhash} == *M
]; then
310 log
"${found} repository has modifications. This could be a serious problem, as something"
311 log
"has modified the repository in your distfiles directory, which should never happen."
313 ## This removes the trailing M, because 'svnversion' output and svn info output would needlessly differ
315 newhash
="${newhash%M}"
320 secure_env
'EGIT_REPO_URI' ||
continue
322 ## This is actually necessary due to newer eclasses which inherit git.eclass but not the EGIT_BRANCH variable.
323 extract_env
'EGIT_BRANCH' || EGIT_BRANCH
='master'
327 ## GIT only allows git peek-remote to be done on certain protocols, thus listed at the end.
328 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ] && [[ "${EGIT_REPO_URI}" =~ ^(git|ssh|file|ssh+git|git+ssh).* ]]; then
329 newhash=$(git peek-remote ${EGIT_REPO_URI} | grep "heads/${EGIT_BRANCH}$" | awk '{sub(/\t.*$/,"")} 1')
331 secure_env 'EGIT_STORE_DIR' 'EGIT_PROJECT' || continue
333 found="${EGIT_STORE_DIR}/${EGIT_PROJECT}"
334 check_for_found "${found}/info
" "${provide}" || continue
336 if [ ${locbase} -eq ${false} ]; then
337 secure_env 'EGIT_UPDATE_CMD' || continue
339 ${prescm} git --git-dir="${found}" fetch origin ${EGIT_BRANCH}:${EGIT_BRANCH}&>/dev/null
340 update_check $? ${provide} || continue
342 newhash="$
(git
--git-dir="${found}" rev-parse
${EGIT_BRANCH})"
346 ## CVS_RSH gets extracted, but is not used anywhere by design.
347 secure_env 'CVS_PASSFILE' 'CVS_RSH' 'ECVS_AUTH' 'ECVS_CVS_COMMAND' \
348 'ECVS_SERVER' 'ECVS_TOP_DIR' 'ECVS_UP_OPTS' 'ECVS_USER' || continue
350 ## The obvious "optional only
", these don't exist at all in some ebuilds.
351 extract_env 'ECVS_MODULE' 'ECVS_LOCALNAME' 'ECVS_OPTIONS' 'ECVS_COMPRESS' 'ECVS_PASS' 'T'
353 if [ -n "${ECVS_LOCALNAME}" ]; then
354 found="${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"
355 elif [ -n "${ECVS_MODULE}" ]; then
356 found="${ECVS_TOP_DIR}/${ECVS_MODULE}"
358 echo "Couldn
't find the directory for ${provide}, skipping..."
363 [ -z "${T}" ] && T="`dirname ${CVS_PASSFILE}`"
365 check_for_found "${found}/CVS" "${provide}" || continue
368 if [ ${locbase} -eq ${false} ]; then
369 ## From the cvs.eclass
370 [ -d "${T}" ] || mkdir -p "${T}"
371 touch "${CVS_PASSFILE}"
372 chown ${EMERGE_USER[${spec}]} ${CVS_PASSFILE}
374 ## DON'T login as
${prescm}, it causes all sorts of problems when the sudo environment is
reset.
375 decho
-d:${ECVS_AUTH}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER} ${ECVS_CVS_COMMAND} -Q login \
>/dev
/null
376 ${ECVS_CVS_COMMAND} -d:${ECVS_AUTH}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER} -Q login
> /dev
/null
377 [ $?
-ne 0 ] && vecho
"Couldn't login to cvs server for ${provide}" && continue
379 decho
${prescm} ${ECVS_CVS_COMMAND} -d:${ECVS_AUTH}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER} -Q update ${ECVS_UP_OPTS} ${ECVS_LOCALNAME}
380 ${prescm} ${ECVS_CVS_COMMAND} -d:${ECVS_AUTH}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER} -Q update ${ECVS_UP_OPTS} ${ECVS_LOCALNAME}
381 update_check $?
${provide} ||
continue
383 newhash
="$(find ${found} -type f -name Entries -exec cat {} \; | ${HASH_PROGRAM} | sed -e 's/ .*//')"
386 secure_env
'EDARCS_DARCS_CMD' ||
continue
388 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ]; then
389 secure_env
'EDARCS_REPOSITORY' ||
continue
390 newhash
="$(${EDARCS_DARCS_CMD} changes --last 1 --xml-output --repo="${EDARCS_REPOSITORY}" | grep hash | sed "s
/^.
*hash='\(.*\).gz.*$/\1/")"
392 secure_env 'EDARCS_TOP_DIR
' 'EDARCS_LOCALREPO
' 'EDARCS_UPDATE_CMD
' 'EDARCS_OPTIONS
' || continue
394 found="${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
395 check_for_found "${found}/_darcs" "${provide}" || continue
398 if [ ${locbase} -eq ${false} ]; then
399 ${prescm} ${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} -q>/dev/null
400 update_check $? ${provide} || continue
402 newhash="$(${prescm} ${EDARCS_DARCS_CMD} changes --last 1 --xml-output | grep hash | sed "s/^.*hash='\
(.
*\
).gz.
*$
/\
1/")"
406 secure_env
'EHG_STORE_DIR' 'EHG_PROJECT' 'EHG_PULL_CMD' ||
continue
408 found
="${EHG_STORE_DIR}/${EHG_PROJECT}"
410 ## Takes a little more time, but the mercurial eclass is a little less mature than most of the others,
411 ## so we must search inside the STORE_DIR in the case that it's a module inside that.
412 ## ie. EHG_STORE_DIR=/usr/distfiles/hg-src/alsa-drivers , but .hg is in ..alsa-drivers/alsa-kernel
413 found
="`find ${found} -name .hg -type d -printf '%h\n'`"
414 check_for_found
"${found}" "${provide}" ||
continue
416 ## To avoid mercurial warnings prescm is run below.
417 ## Mercurial returns 1 when there is no updates (don't ask me.)
418 if [ ${PEEK} -eq ${true} ]; then
419 ${prescm} hg
-R "${found}" incoming
>/dev
/null
420 if [ $?
-eq 0 ]; then
421 newhash
='0101' ## fake hash
422 elif [ $?
-ne 1 ]; then
423 update_check $?
${provide}
426 if [ ${locbase} -eq ${false} ]; then
427 ${prescm} ${EHG_PULL_CMD} --repository "${found}">/dev/null
428 [ $? -ne 1 ] && update_check $? ${provide}
432 ## This must be run even with peek in the case that the repository is on an NFS mount.
433 if [ -n "${newhash}" ]; then
434 newhash="$
(${prescm} hg
--quiet --repository "${found}" tip
)"
435 [ $? -ne 1 ] && update_check $? ${provide}
439 ## These are the workings; it works, but with permissions it fails. If someone can fix the permissions problems, by
440 ## putting ${prescm} before the TLA commands and before the tla commands; the only way it runs successfully now is to run
441 ## without the prescm commands due to the CACHE_DIR permissions problems. Send patches if you want this fixed.
442 secure_env 'ETLA_TOP_DIR' 'ETLA_TLA_CMD' 'ETLA_UPDATE_CMD' 'ETLA_CACHE_DIR' 'ETLA_VERSION' 'ETLA_ARCHIVES' 'WORKDIR' 'P' || continue
443 found="${ETLA_TOP_DIR}/${ETLA_CACHE_DIR}"
444 check_for_found "${found}" "${provide}" || continue
446 if [ ${locbase} -eq ${false} ]; then
447 ETLA_TLA_CMD="${ETLA_TLA_CMD} --dir "${found}""
449 mkdir -p -m 0700 "${WORKDIR}/${P}"
450 chown ${EMERGE_USER[$spec]} "${WORKDIR}/${P}"
451 ${prescm} cp -Rf "$ETLA_TOP_DIR/$ETLA_CACHE_DIR"/* "${WORKDIR}/${P}"
452 for archive in ${ETLA_ARCHIVES}; do
453 ${prescm} ${ETLA_TLA_CMD} register-archive -f ${archive} || echo "Couldn't register ${archive}" && continue
456 tla_archive
=`${prescm} ${ETLA_TLA_CMD} parse-package-name --arch ${ETLA_VERSION}`
457 tla_version
=`${prescm} ${ETLA_TLA_CMD} parse-package-name --package-version ${ETLA_VERSION}`
458 oldversion
="`${prescm} ${ETLA_TLA_CMD} tree-version`"
459 [ "${tla_archive}/${tla_version}" != "${oldversion}" ] && ${prescm} ${ETLA_TLA_CMD} set-tree-version ${tla_archive}/${tla_version}
461 ${prescm} ${ETLA_TLA_CMD} ${ETLA_UPDATE_CMD} ${ETLA_VERSION}>/dev/null
462 update_check $? ${provide} || continue
465 newhash="$
(${HASH_PROGRAM} "${ETLA_TOP_DIR}/${ETLA_CACHE_DIR}"/\{arch\}/tine-treesqls |
sed -e 's/ .*//g')"
468 secure_env 'EBAZAAR_REPO_URI' || continue
470 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ]; then
471 newhash="$
(bzr version-info
"${EBAZAAR_REPO_URI}" |
grep revision-id |
awk '{sub(/^.* /,"")} 1')"
473 secure_env 'EBAZAAR_REGISTER_CMD' 'EBAZAAR_REGISTER_URI' 'EBAZAAR_STORE_DIR' \
474 'EBAZAAR_REGISTER_CMD' 'EBAZAAR_PROJECT' || continue
475 found="${EBAZAAR_STORE_DIR}/${EBAZAAR_PROJECT}/${EBAZAAR_REPO_URI##*/}"
477 check_for_found "${found} ${provide}" || continue
479 dinfo "${prescm} ${EBAZAAR_REGISTER_CMD} ${EBAZAAR_REGISTER_URI} --dir "${found}">/dev/null"
480 ${prescm} ${EBAZAAR_REGISTER_CMD} ${EBAZAAR_REGISTER_URI} --dir "${found}">/dev/null
481 update_check $? ${provide} || continue
483 dinfo "${prescm} ${EBAZAAR_UPDATE_CMD} --dir "${found}">/dev/null"
484 ${prescm} ${EBAZAAR_UPDATE_CMD} --dir "${found}">/dev/null
485 update_check $? ${provide} || continue
487 newhash="$
(bzr version-info
"${found}" |
grep revision-id |
awk '{sub(/^.* /,"")} 1')"
491 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ]; then
492 secure_env 'EBZR_REPO_URI' 'EBZR_BRANCH' || continue
493 found="${EBZR_REPO_URI}${EBZR_BRANCH}"
495 secure_env 'EBZR_STORE_DIR' 'EBZR_CACHE_DIR' || continue
496 found="${EBZR_STORE_DIR}/${EBZR_CACHE_DIR}"
498 check_for_found "${found}" || continue
500 newhash="`bzr revno ${found} &>/dev/stdout | tail -n1`"
507 ################################################################################################################################################
509 ## This is the actual beginning of update-live-ebuilds, skipping past all the functions. This beginning checks a few prerequisites.
510 ################################################################################################################################################
511 trap 'echo; exit ${USER_INTERRUPT}' TERM INT
512 [ "${BASH_VERSION//.*}" -lt 3 ] && echo "Requires BASH v3 or better
" && exit 5
514 if [ ! -f "/etc
/ule
/ule.conf
" ]; then
515 echo -n "This
script failed a sanity check
, cannot
continue without
"
516 echo "/etc
/ule
/ule.conf
"
519 source /etc/ule/ule.conf
521 if [ "${UID}" -ne 0 ]; then
522 echo "${0}: root access required.
"
526 ## Variables that don't need to be in the conf
541 while getopts "abhpqr
" opt; do
544 b) BASELINE=${true} ;;
546 p) PRETEND=${true} ;;
547 q) VERBOSE=${false} ;;
551 shift $(($OPTIND - 1))
553 if [ ${USAGE} -eq ${true} ]; then
555 Usage: ${0} [OPTION] [PKGSPEC]
556 Example: ${0} -v net-www/gnash
557 Search for live repository ebuilds that need updating, and update them if necessary.
559 -a Reemerge all packages fetched from various repositories
560 -b Baseline the ebuild (write into the database without updating)
562 -p If update is required, only pretend to emerge.
564 -r Report information about packages that are tracked by update-live-ebuilds
566 See man 8 update-live-ebuilds for more information.
567 Report bugs to Avuton Olrich <avuton@gmail.com>
573 if [ ${BASELINE} -eq ${true} ] && [ ${PRETEND} -eq ${true} ]; then
574 echo "Baseline and pretend are not compatible.
"
578 ################################################################################################################################################
579 ## Update only support;
580 ## The purpose of doing things this way is so we update libraries in the order of:
582 ## 2) Everything but libraries and plugins
584 ## This is done like this to make sure libraries are updated first in the case that the packages (#2 & #3) that depend on the
585 ## libraries have the latest and greatest to link to, if necessary. Plugins are done last as they may depend on the
589 ## This is a bit of mumbo jumbo, mostly for the reason that we don't yet track version numbers, only by provide
590 ## A side effect of not being able to track version numbers means we need to glob for the version in the db's directory
591 ## which may grab two seperate directorys with the same name, but one longer like: foo-1.1 and foobar-2.1. It's not
592 ## a great side effect, but in reality shouldn't hit too many people. A more elegant solution is wanted, but complexity
596 ################################################################################################################################################
597 if [ -n "${1}" ]; then
599 [ "${ebuild:0:1}" == '=' ] && ebuild="${ebuild:1}"
601 ebuild="${ebuild//:[[:digit:]]}" # Remove the slot for now
603 for mydir in `[[ ${ebuild} == */* ]] && echo ${DB_LOC}/${ebuild}* || echo ${DB_LOC}/*/${ebuild}*`; do
604 [ ! -d "${mydir}" ] && vecho "Directory doesn
't exist: ${mydir}, continuing..." && continue
605 if [[ "${mydir}" == *libs* ]]; then
606 libs="${libs} ${mydir}"
607 elif [[ "${mydir}" == *plugin* ]]; then
608 plugin="${plugin} ${mydir}"
610 nlibs="${nlibs} ${mydir}"
615 [ -z "${nlibs}" ] && [ -z "${plugin}" ] && [ -z "${libs}" ] && echo "No packages found." && exit 5
617 libs="`find "${DB_LOC}" -mindepth 2 -maxdepth 2 -type d -wholename "*libs*"`"
618 plugin="`find "${DB_LOC}" -mindepth 2 -maxdepth 2 -type d -wholename "*plugin*"`"
619 nlibs="`find "${DB_LOC}" -mindepth 2 -maxdepth 2 -type d -not \( -wholename "*plugin*" -o -wholename "*libs*" \)`"
622 ################################################################################################################################################
623 ## Begin looping for SCM detection and emersion
624 ## Beyond this, each ebuild runs in this for loop. Attempt is made to weed out the non-SCM ebuilds immediately to prevent any unnecessary
625 ## CPU time incurred.
626 ################################################################################################################################################
627 for dir in ${libs} ${nlibs} ${plugin}; do
633 ################################################################################################################################################
635 ## This prevents bugs.
636 ################################################################################################################################################
637 unset ${CUREXPORTS} CUREXPORTS
639 ################################################################################################################################################
640 ## Detect INHERITED location;
641 ## This should always go in the first block; the only reason it wouldn't is
if the user used pkgcore to
install a package
, as pkgcore
642 ## doesn't install an INHERITED file.
643 ################################################################################################################################################
644 if [ -f "${dir}/INHERITED" ]; then
645 INHERITED
="$(cat ${dir}/INHERITED)"
646 elif [ -f "${dir}"/*.ebuild
]; then
647 extract_env
'INHERITED'
649 continue ## This really shouldn't happen unless something is trashing the portage database.
652 ## The inherit line is checked here for the various scms defined in the config, and executed below.
653 for scm
in ${SCM_SUPPORT[@]}; do
654 [[ "${INHERITED}" = *${scm}* ]] && type="${scm}" && break
658 [ "${type}" == ${false} ] && continue
660 if [ ! -f "${dir}/environment.bz2" ]; then
661 echo 'Error: Failed a sanity check.'
662 echo "dir: ${dir} has no environment.bz2 file!"
664 echo 'Correct this condition by manually reemerging.'
665 echo "If you believe this is a script error,"
670 secure_env
'CATEGORY' 'PN' 'SLOT'
671 if [ $?
-ne ${true} ]; then
672 echo "This is an assertion, you probably have a corrupt portage database for dir ${dir}."
678 # if [ "${PN}" == ${ebuild/${ebuild%%:[[:digit:]]}:} ]; then
682 provide
="${CATEGORY}/${PN}:${SLOT}"
683 pprovide
="${CATEGORY}/${PN}"
684 ule_file
="${ULE_LOC}/${provide/:*}/ULE_INFO.${SLOT}"
685 ULE_DB_FILES
="${ULE_DB_FILES} ${ule_file}"
686 decho
"${provide} uses the ${scm} SCM".
688 [ -f "${ULE_LOC}/${provide}/ULE_INFO" ] && mv "${ULE_LOC}/${provide}/ULE_INFO" "${ule_file}"
690 if [ -f "${ule_file}" ]; then
691 decho
'Sourcing ULE_INFO'
695 TOTAL
="${TOTAL} ${provide}"
697 ################################################################################################################################################
698 ## Begin ebuild masking detection;
699 ## This looks for an ebuild on a line in the ULE_MASK_FILE, if it exists, this will simply begin analyzation of the next ebuild in the
700 ## queue, if applicable.
701 ################################################################################################################################################
702 if [ -f "${ULE_MASK_FILE}" ]; then
703 grep -Eq "^(${pprovide}|${provide})$" "${ULE_MASK_FILE}"
705 if [ $?
-eq ${true} ]; then
706 vecho
"Package (${provide}) found in ULE_MASK, skipping..."
711 ################################################################################################################################################
712 ## Portage compatible installer and privelege dropping autodetection;
713 ## This is where autodetection takes place. This will make it not only automatically detect which portage compatible installer to use,
714 ## but it will also use exactly what was used on the package last time, in the case that one of the portage compatible installers cause
715 ## breakage. This is hacky and can break with changes to the package managers, though it will be fixed, I do hope that portage adds
716 ## PKGMANAGER in the future.
717 ################################################################################################################################################
718 spec
="${DEFAULT_EMERGE_PROGRAM}"
719 if [ ${FORCE_DEFAULT_EMERGE_PROGRAM} -eq ${false} ]; then
720 if [ -f "${dir}/PKGMANAGER" ]; then
721 tmp
=$
(cat "${dir}/PKGMANAGER")
722 if [[ "${tmp}" =~
(paludis
)-.
* ]] && [ "${BASH_REMATCH[1]}" == paludis
]; then
724 ## Versions prior to 22 didn't have the ability to be run as non-superuser.
725 [ -n ${PALVER} ] && export PALVER
=`paludis --version | head -n1 | sed -e 's/.* [0-9].\([0-9][0-9]\)..*/\1/g'`
726 if [ ${PALVER} -gt 21 ]; then
727 decho
"Paludis version ${tmp} (greater than version 0.22.0) is the portage compatible installer"
730 decho
"Paludis version ${tmp} (less than version 0.22.0) is the portage compatible installer"
732 elif [[ "${tmp}" =~
(pkgcore
)-.
* ]] && [ "${BASH_REMATCH[1]}" == pkgcore
]; then
733 decho
"Pkgcore is the portage compatible installer"
737 echo "Your portage compatible installer was not recognized, please report this problem"
738 echo "Continuing using default portage compatible installer ${EMERGE_BINARY[${DEFAULT_EMERGE_PROGRAM}]}"
742 decho
"Emerge is the portage compatible installer"
747 ################################################################################################################################################
748 ## Begin date detection;
749 ## This looks for a ebuild/date combination for the current ebuild being analyzed, if it exists, this will detect if it has been updated
750 ## since the date in the ebuild/date combination and if it has, it will not attempt to emerge again until that time has expired.
751 ################################################################################################################################################
752 [ ${REPORT} -eq ${false} ] && [ -f "${ULE_DATE_FILE}" ] &&
753 userdays=`grep -E "^
(\
*\
/\
*\
:${SLOT}|${CATEGORY}\/\*|${pprovide}|${provide}) [0-9]*" "${ULE_DATE_FILE}" | tail -n1`
755 if [ ${ALL} -eq ${false} ] && [ ${BASELINE} -eq ${false} ] && [ -n "${userdays}" ]; then
757 if [[ ${userdays} =~ (\*\/\*\:${SLOT} )(.*) ]] || [[ ${userdays} =~ (${CATEGORY}\
/\
* )(.
*) ]] || \
758 [[ ${userdays} =~ (${pprovide} )(.*) ]] || [[ ${userdays} =~ (${provide} )(.
*) ]]; then
760 [ -n ${ebuild_epoch} ] && update_ebuild_epoch
762 updateepoch
=$
(((86400*${BASH_REMATCH[2]})+${ebuild_epoch}))
763 diffepoch
=$
((${updateepoch} - ${curepoch}))
765 if [ ${diffepoch} -ne 0 ] && [ ${updateepoch} -gt ${curepoch} ]; then
766 if [ ${diffepoch} -gt 86400 ]; then
767 vecho
"$((${diffepoch}/86400)) days until scheduled update attempts resume for ${provide}."
769 vecho
"Less than a day until scheduled update attempts resume for ${provide}"
775 unset updateepoch curepoch userdays
777 if [ ${REPORT} -eq ${true} ]; then
778 if [ -n ${ebuild_epoch} ]; then
784 printf "${provide}\n"
785 printf "\tRevision: ${ULE_COOKIE}\n"
786 printf "\tEmerged on: `date -d \"1970-01-01 UTC ${ebuild_epoch} sec\" \"+${DATE_FORMAT}\"`\n\n"
790 vecho
"Attempting to check if ${provide} needs an update."
792 if [ -f /etc
/make.conf
] && [ ${spec} -eq ${portage} ] || [ ${spec} -eq ${pkgcore} ]; then
793 grep 'userpriv' /etc
/make.conf |
grep -v '.*#.*userpriv.*'&>/dev
/null
794 [ $?
-eq 0 ] && prescm
=${true}
797 if [ ${prescm} -eq ${true} ]; then
798 decho
"Dropping privileges for ${provide}."
799 prescm
="sudo -u ${EMERGE_USER[${spec}]}"
801 decho
"Not dropping privileges for ${provide}."
807 ## As long as 'newhash' was calculated last in the section above, this should be the outcome of it.
808 update_check $?
"${provide}"
810 ################################################################################################################################################
811 ## Where the magic happens;
814 ## We cannot locbase here, because we can't guarantee the repository has only been updated locally, it's basically assurance that
815 ## the cookie that goes into the ule database is the version that's installed.
817 ## In this case ALL is in the case that the user wants to reinstall and reupdate the ule database, reguardless of updates. The
818 ## locbase is also showing that we assume we didn't previously use the emerger().
820 ## This is the case where the ULE_COOKIE matches the newhash (no updates!), we're going to skip the emerge and simply baseline,
821 ## or we've got an empty newhash, which should absolutely, positively never happen. The only reason it would happen is
822 ## if there aren't enough update_check()s sprinkled above. This can also be caused by the SCM command line interface
823 ## throwing the wrong exit code, for example throwing 0 on failure (see Subversion bug 2414).
825 ## Finally, this will be where 90-95% of all emerger() inits go, we cleanup prior to it then set the emerger to emerge with
827 ################################################################################################################################################
828 if [ -z "${ULE_COOKIE}" ] && [ ${locbase} -eq ${false} ]; then
829 vecho "No previous cookie detected
, reemerging
"
830 elif [ ${ALL} -eq ${true} ] && [ ${locbase} -eq ${false} ]; then
831 vecho "Emerging all
, reemerging
"
832 elif [ "${ULE_COOKIE}" == "${newhash}" ] || [ ${locbase} -eq ${true} ] || [ -z "${newhash}" ]; then
833 if [ ${locbase} -eq ${true} ]; then
834 vecho "Baselineing
${provide}"
835 write_to_db "${newhash}" "${ULE_LOC}/${provide}"
837 [ -z "${newhash}" ] && vecho "Newhash empty
, this should never happen unless errors that wern
't caught previously"
838 unset ${CUREXPORTS} CUREXPORTS
842 unset ${CUREXPORTS} CUREXPORTS
846 unset provide newhash type locbase
849 [ ${REPORT} -eq ${true} ] && exit 0
851 [ ${VERBOSE} -eq ${true} ] && echo 'Update complete
'
853 [ -n "${1}" ] && exit 0
855 ## Update-only cannot make it this far; thus this should be fine.
857 ## Cleanup the ULE directory
858 echo "Cleaning ULE database"
859 for file in ${ULE_DB_FILES}; do
860 [ -n "${PACKAGES}" ] && PACKAGES="${PACKAGES} -a"
861 PACKAGES="${PACKAGES} -not -wholename "${file}""
864 ## Find and remove the ULE_INFO files
865 find ${ULE_LOC} -maxdepth 3 -mindepth 3 ${PACKAGES} -exec rm -v {} \;
867 ## Clean out the empty directories
868 find ${ULE_LOC} -depth -empty -type d -exec rmdir -v {} \;
870 if [ -n "${SUCCESS_PACKAGES}" ] && [ "${VERBOSE}" -eq ${true} ]; then
871 echo "The following packages were updated: ${SUCCESS_PACKAGES}"
872 unset SUCCESS_PACKAGES
875 if [ -n "${FAILED_PACKAGES}" ]; then
876 echo "The following programs failed: ${FAILED_PACKAGES}."
877 echo "You could either rerun this program at a later date, or you could do it on an individual"
878 echo "basis by just using the package spec as a argument: i.e. ${0} net-www/gnash"
879 unset FAILED_PACKAGES
882 if [ -n "${UPDATE_FAIL_PACKAGES}" ]; then
883 echo "The following programs failed when trying to be updated by update-live-ebuilds: ${UPDATE_FAIL_PACKAGES}"
884 unset UPDATE_FAIL_PACKAGES