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.
264 ## TODO: When sudo-1.6.9+ hits, environment variables will work correctly with sudo with the '-E' argument. Remove workarounds and
265 ## use environment variables at that point.
266 ################################################################################################################################################
267 function get_hash
() {
273 secure_env
'ESVN_REPO_URI' ||
continue
274 ESVN_REPO_URI
="${ESVN_REPO_URI%%/}"
276 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ]; then
277 newhash
=$
(svn info
${ESVN_REPO_URI} |
grep 'Last Changed Rev' |
awk '{sub(/^.* /,"")} 1')
280 ## Subversions' binaries are extremely unreliable. Cannot count on svn info to give something useful.
281 if [ -z "${newhash}" ]; then
282 secure_env
'ESVN_STORE_DIR' 'ESVN_PROJECT' 'ESVN_UPDATE_CMD' 'ESVN_OPTIONS' ||
continue
284 found
="${ESVN_STORE_DIR}/${ESVN_PROJECT}/${ESVN_REPO_URI##*/}"
285 check_for_found
"${found}/.svn" "${provide}" ||
continue
287 if [ ${locbase} -eq ${false} ]; then
288 decho
${prescm} ${ESVN_UPDATE_CMD} ${ESVN_OPTIONS} --quiet --config-dir="${ESVN_STORE_DIR}/.subversion" ${found}
289 ${prescm} ${ESVN_UPDATE_CMD} ${ESVN_OPTIONS} --quiet --config-dir="${ESVN_STORE_DIR}/.subversion" ${found}
290 update_check $?
${provide} ||
continue
292 newhash
=$
(svnversion
-c ${found} |
awk '{sub(/.*:/,"")} 1')
294 ## Check the repository for modification, this is usually a sign of trouble.
295 if [ ${newhash} == *M
]; then
296 log
"${found} repository has modifications. This could be a serious problem, as something"
297 log
"has modified the repository in your distfiles directory, which should never happen."
299 ## This removes the trailing M, because 'svnversion' output and svn info output would needlessly differ
301 newhash
="${newhash%M}"
306 secure_env
'EGIT_REPO_URI' ||
continue
308 ## This is actually necessary due to newer eclasses which inherit git.eclass but not the EGIT_BRANCH variable.
309 extract_env
'EGIT_BRANCH' || EGIT_BRANCH
='master'
313 ## GIT only allows git peek-remote to be done on certain protocols, thus listed at the end.
314 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ] && [[ "${EGIT_REPO_URI}" =~ ^(git|ssh|file|ssh+git|git+ssh).* ]]; then
315 newhash=$(git peek-remote ${EGIT_REPO_URI} | grep "heads/${EGIT_BRANCH}$" | awk '{sub(/\t.*$/,"")} 1')
317 secure_env 'EGIT_STORE_DIR' 'EGIT_PROJECT' || continue
319 found="${EGIT_STORE_DIR}/${EGIT_PROJECT}"
320 check_for_found "${found}/info
" "${provide}" || continue
322 if [ ${locbase} -eq ${false} ]; then
323 secure_env 'EGIT_UPDATE_CMD' || continue
325 ${prescm} git --git-dir="${found}" fetch origin ${EGIT_BRANCH}:${EGIT_BRANCH}&>/dev/null
326 update_check $? ${provide} || continue
328 newhash="$
(git
--git-dir="${found}" rev-parse
${EGIT_BRANCH})"
332 ## CVS_RSH gets extracted, but is not used anywhere by design.
333 secure_env 'CVS_PASSFILE' 'CVS_RSH' 'ECVS_AUTH' 'ECVS_CVS_COMMAND' \
334 'ECVS_SERVER' 'ECVS_TOP_DIR' 'ECVS_UP_OPTS' 'ECVS_USER' || continue
336 ## The obvious "optional only
", these don't exist at all in some ebuilds.
337 extract_env 'ECVS_MODULE' 'ECVS_LOCALNAME' 'ECVS_OPTIONS' 'ECVS_COMPRESS' 'ECVS_PASS' 'T'
339 if [ -n "${ECVS_LOCALNAME}" ]; then
340 found="${ECVS_TOP_DIR}/${ECVS_LOCALNAME}"
341 elif [ -n "${ECVS_MODULE}" ]; then
342 found="${ECVS_TOP_DIR}/${ECVS_MODULE}"
344 echo "Couldn
't find the directory for ${provide}, skipping..."
349 [ -z "${T}" ] && T="`dirname ${CVS_PASSFILE}`"
351 check_for_found "${found}/CVS" "${provide}" || continue
354 if [ ${locbase} -eq ${false} ]; then
355 ## From the cvs.eclass
356 [ -d "${T}" ] || mkdir -p "${T}"
357 touch "${CVS_PASSFILE}"
358 chown ${EMERGE_USER[${spec}]} ${CVS_PASSFILE}
360 ## DON'T login as
${prescm}, it causes all sorts of problems when the sudo environment is
reset.
361 decho
-d:${ECVS_AUTH}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER} ${ECVS_CVS_COMMAND} -Q login \
>/dev
/null
362 ${ECVS_CVS_COMMAND} -d:${ECVS_AUTH}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER} -Q login
> /dev
/null
363 [ $?
-ne 0 ] && vecho
"Couldn't login to cvs server for ${provide}" && continue
365 decho
${prescm} ${ECVS_CVS_COMMAND} -d:${ECVS_AUTH}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER} -Q update ${ECVS_UP_OPTS} ${ECVS_LOCALNAME}
366 ${prescm} ${ECVS_CVS_COMMAND} -d:${ECVS_AUTH}:${ECVS_USER}:${ECVS_PASS}@${ECVS_SERVER} -Q update ${ECVS_UP_OPTS} ${ECVS_LOCALNAME}
367 update_check $?
${provide} ||
continue
369 newhash
="$(find ${found} -type f -name Entries -exec cat {} \; | ${HASH_PROGRAM} | sed -e 's/ .*//')"
372 secure_env
'EDARCS_DARCS_CMD' ||
continue
374 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ]; then
375 secure_env
'EDARCS_REPOSITORY' ||
continue
376 newhash
="$(${EDARCS_DARCS_CMD} changes --last 1 --xml-output --repo="${EDARCS_REPOSITORY}" | grep hash | sed "s
/^.
*hash='\(.*\).gz.*$/\1/")"
378 secure_env 'EDARCS_TOP_DIR
' 'EDARCS_LOCALREPO
' 'EDARCS_UPDATE_CMD
' 'EDARCS_OPTIONS
' || continue
380 found="${EDARCS_TOP_DIR}/${EDARCS_LOCALREPO}"
381 check_for_found "${found}/_darcs" "${provide}" || continue
384 if [ ${locbase} -eq ${false} ]; then
385 ${prescm} ${EDARCS_DARCS_CMD} ${EDARCS_UPDATE_CMD} --all ${EDARCS_OPTIONS} -q>/dev/null
386 update_check $? ${provide} || continue
388 newhash="$(${prescm} ${EDARCS_DARCS_CMD} changes --last 1 --xml-output | grep hash | sed "s/^.*hash='\
(.
*\
).gz.
*$
/\
1/")"
392 secure_env
'EHG_STORE_DIR' 'EHG_PROJECT' 'EHG_PULL_CMD' ||
continue
394 found
="${EHG_STORE_DIR}/${EHG_PROJECT}"
396 ## Takes a little more time, but the mercurial eclass is a little less mature than most of the others,
397 ## so we must search inside the STORE_DIR in the case that it's a module inside that.
398 ## ie. EHG_STORE_DIR=/usr/distfiles/hg-src/alsa-drivers , but .hg is in ..alsa-drivers/alsa-kernel
399 found
="`find ${found} -name .hg -type d -printf '%h\n'`"
400 check_for_found
"${found}" "${provide}" ||
continue
402 ## To avoid mercurial warnings prescm is run below.
403 ## Mercurial returns 1 when there is no updates (don't ask me.)
404 if [ ${PEEK} -eq ${true} ]; then
405 ${prescm} hg
-R "${found}" incoming
>/dev
/null
406 if [ $?
-eq 0 ]; then
407 newhash
='0101' ## fake hash
408 elif [ $?
-ne 1 ]; then
409 update_check $?
${provide}
412 if [ ${locbase} -eq ${false} ]; then
413 ${prescm} ${EHG_PULL_CMD} --repository "${found}">/dev/null
414 [ $? -ne 1 ] && update_check $? ${provide}
418 ## This must be run even with peek in the case that the repository is on an NFS mount.
419 if [ -n "${newhash}" ]; then
420 newhash="$
(${prescm} hg
--quiet --repository "${found}" tip
)"
421 [ $? -ne 1 ] && update_check $? ${provide}
425 ## These are the workings; it works, but with permissions it fails. If someone can fix the permissions problems, by
426 ## putting ${prescm} before the TLA commands and before the tla commands; the only way it runs successfully now is to run
427 ## without the prescm commands due to the CACHE_DIR permissions problems. Send patches if you want this fixed.
428 secure_env 'ETLA_TOP_DIR' 'ETLA_TLA_CMD' 'ETLA_UPDATE_CMD' 'ETLA_CACHE_DIR' 'ETLA_VERSION' 'ETLA_ARCHIVES' 'WORKDIR' 'P' || continue
429 found="${ETLA_TOP_DIR}/${ETLA_CACHE_DIR}"
430 check_for_found "${found}" "${provide}" || continue
432 if [ ${locbase} -eq ${false} ]; then
433 ETLA_TLA_CMD="${ETLA_TLA_CMD} --dir "${found}""
435 mkdir -p -m 0700 "${WORKDIR}/${P}"
436 chown ${EMERGE_USER[$spec]} "${WORKDIR}/${P}"
437 ${prescm} cp -Rf "$ETLA_TOP_DIR/$ETLA_CACHE_DIR"/* "${WORKDIR}/${P}"
438 for archive in ${ETLA_ARCHIVES}; do
439 ${prescm} ${ETLA_TLA_CMD} register-archive -f ${archive} || echo "Couldn't register ${archive}" && continue
442 tla_archive
=`${prescm} ${ETLA_TLA_CMD} parse-package-name --arch ${ETLA_VERSION}`
443 tla_version
=`${prescm} ${ETLA_TLA_CMD} parse-package-name --package-version ${ETLA_VERSION}`
444 oldversion
="`${prescm} ${ETLA_TLA_CMD} tree-version`"
445 [ "${tla_archive}/${tla_version}" != "${oldversion}" ] && ${prescm} ${ETLA_TLA_CMD} set-tree-version ${tla_archive}/${tla_version}
447 ${prescm} ${ETLA_TLA_CMD} ${ETLA_UPDATE_CMD} ${ETLA_VERSION}>/dev/null
448 update_check $? ${provide} || continue
451 newhash="$
(${HASH_PROGRAM} "${ETLA_TOP_DIR}/${ETLA_CACHE_DIR}"/\{arch\}/tine-treesqls |
sed -e 's/ .*//g')"
454 secure_env 'EBAZAAR_REPO_URI' || continue
456 if [ ${PEEK} -eq ${true} ] && [ ${locbase} -eq ${false} ]; then
457 newhash="$
(bzr version-info
"${EBAZAAR_REPO_URI}" |
grep revision-id |
awk '{sub(/^.* /,"")} 1')"
459 secure_env 'EBAZAAR_REGISTER_CMD' 'EBAZAAR_REGISTER_URI' 'EBAZAAR_STORE_DIR' \
460 'EBAZAAR_REGISTER_CMD' 'EBAZAAR_PROJECT' || continue
461 found="${EBAZAAR_STORE_DIR}/${EBAZAAR_PROJECT}/${EBAZAAR_REPO_URI##*/}"
463 check_for_found "${found} ${provide}" || continue
465 dinfo "${prescm} ${EBAZAAR_REGISTER_CMD} ${EBAZAAR_REGISTER_URI} --dir "${found}">/dev/null"
466 ${prescm} ${EBAZAAR_REGISTER_CMD} ${EBAZAAR_REGISTER_URI} --dir "${found}">/dev/null
467 update_check $? ${provide} || continue
469 dinfo "${prescm} ${EBAZAAR_UPDATE_CMD} --dir "${found}">/dev/null"
470 ${prescm} ${EBAZAAR_UPDATE_CMD} --dir "${found}">/dev/null
471 update_check $? ${provide} || continue
473 newhash="$
(bzr version-info
"${found}" |
grep revision-id |
awk '{sub(/^.* /,"")} 1')"
481 ################################################################################################################################################
483 ## This is the actual beginning of update-live-ebuilds, skipping past all the functions. This beginning checks a few prerequisites.
484 ################################################################################################################################################
485 trap 'echo; exit ${USER_INTERRUPT}' TERM INT
486 [ "${BASH_VERSION//.*}" -lt 3 ] && echo "Requires BASH v3 or better
" && exit 5
488 if [ ! -f "/etc
/ule
/ule.conf
" ]; then
489 echo -n "This
script failed a sanity check
, cannot
continue without
"
490 echo "/etc
/ule
/ule.conf
"
493 source /etc/ule/ule.conf
495 if [ "${UID}" -ne 0 ]; then
496 echo "${0}: root access required.
"
500 ## Variables that don't need to be in the conf
515 while getopts "abhpqr
" opt; do
518 b) BASELINE=${true} ;;
520 p) PRETEND=${true} ;;
521 q) VERBOSE=${false} ;;
525 shift $(($OPTIND - 1))
527 if [ ${USAGE} -eq ${true} ]; then
529 Usage: ${0} [OPTION] [PKGSPEC]
530 Example: ${0} -v net-www/gnash
531 Search for live repository ebuilds that need updating, and update them if necessary.
533 -a Reemerge all packages fetched from various repositories
534 -b Baseline the ebuild (write into the database without updating)
536 -p If update is required, only pretend to emerge.
538 -r Report information about packages that are tracked by update-live-ebuilds
540 See man 8 update-live-ebuilds for more information.
541 Report bugs to Avuton Olrich <avuton@gmail.com>
547 if [ ${BASELINE} -eq ${true} ] && [ ${PRETEND} -eq ${true} ]; then
548 echo "Baseline and pretend are not compatible.
"
552 ################################################################################################################################################
553 ## Update only support;
554 ## The purpose of doing things this way is so we update libraries in the order of:
556 ## 2) Everything but libraries and plugins
558 ## This is done like this to make sure libraries are updated first in the case that the packages (#2 & #3) that depend on the
559 ## libraries have the latest and greatest to link to, if necessary. Plugins are done last as they may depend on the
563 ## This is a bit of mumbo jumbo, mostly for the reason that we don't yet track version numbers, only by provide
564 ## A side effect of not being able to track version numbers means we need to glob for the version in the db's directory
565 ## which may grab two seperate directorys with the same name, but one longer like: foo-1.1 and foobar-2.1. It's not
566 ## a great side effect, but in reality shouldn't hit too many people. A more elegant solution is wanted, but complexity
570 ################################################################################################################################################
571 if [ -n "${1}" ]; then
573 [ "${ebuild:0:1}" == '=' ] && ebuild="${ebuild:1}"
575 ebuild="${ebuild//:[[:digit:]]}" # Remove the slot for now
577 for mydir in `[[ ${ebuild} == */* ]] && echo ${DB_LOC}/${ebuild}* || echo ${DB_LOC}/*/${ebuild}*`; do
578 [ ! -d "${mydir}" ] && vecho "Directory doesn
't exist: ${mydir}, continuing..." && continue
579 if [[ "${mydir}" == *libs* ]]; then
580 libs="${libs} ${mydir}"
581 elif [[ "${mydir}" == *plugin* ]]; then
582 plugin="${plugin} ${mydir}"
584 nlibs="${nlibs} ${mydir}"
589 [ -z "${nlibs}" ] && [ -z "${plugin}" ] && [ -z "${libs}" ] && echo "No packages found." && exit 5
591 libs="`find "${DB_LOC}" -mindepth 2 -maxdepth 2 -type d -wholename "*libs*"`"
592 plugin="`find "${DB_LOC}" -mindepth 2 -maxdepth 2 -type d -wholename "*plugin*"`"
593 nlibs="`find "${DB_LOC}" -mindepth 2 -maxdepth 2 -type d -not \( -wholename "*plugin*" -o -wholename "*libs*" \)`"
596 ################################################################################################################################################
597 ## Begin looping for SCM detection and emersion
598 ## Beyond this, each ebuild runs in this for loop. Attempt is made to weed out the non-SCM ebuilds immediately to prevent any unnecessary
599 ## CPU time incurred.
600 ################################################################################################################################################
601 for dir in ${libs} ${nlibs} ${plugin}; do
607 ################################################################################################################################################
609 ## This prevents bugs.
610 ################################################################################################################################################
611 unset ${CUREXPORTS} CUREXPORTS
613 ################################################################################################################################################
614 ## Detect INHERITED location;
615 ## 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
616 ## doesn't install an INHERITED file.
617 ################################################################################################################################################
618 if [ -f "${dir}/INHERITED" ]; then
619 INHERITED
="$(cat ${dir}/INHERITED)"
620 elif [ -f "${dir}"/*.ebuild
]; then
621 extract_env
'INHERITED'
623 continue ## This really shouldn't happen unless something is trashing the portage database.
626 ## The inherit line is checked here for the various scms defined in the config, and executed below.
627 for scm
in ${SCM_SUPPORT[@]}; do
628 [[ "${INHERITED}" = *${scm}* ]] && type="${scm}" && break
632 [ "${type}" == ${false} ] && continue
634 if [ ! -f "${dir}/environment.bz2" ]; then
635 echo 'Error: Failed a sanity check.'
636 echo "dir: ${dir} has no environment.bz2 file!"
638 echo 'Correct this condition by manually reemerging.'
639 echo "If you believe this is a script error,"
644 secure_env
'CATEGORY' 'PN' 'SLOT'
645 if [ $?
-ne ${true} ]; then
646 echo "This is an assertion, you probably have a corrupt portage database for dir ${dir}."
652 # if [ "${PN}" == ${ebuild/${ebuild%%:[[:digit:]]}:} ]; then
656 provide
="${CATEGORY}/${PN}:${SLOT}"
657 pprovide
="${CATEGORY}/${PN}"
658 ule_file
="${ULE_LOC}/${provide/:*}/ULE_INFO.${SLOT}"
659 ULE_DB_FILES
="${ULE_DB_FILES} ${ule_file}"
660 decho
"${provide} uses the ${scm} SCM".
662 [ -f "${ULE_LOC}/${provide}/ULE_INFO" ] && mv "${ULE_LOC}/${provide}/ULE_INFO" "${ule_file}"
664 if [ -f "${ule_file}" ]; then
665 decho
'Sourcing ULE_INFO'
669 TOTAL
="${TOTAL} ${provide}"
671 ################################################################################################################################################
672 ## Begin ebuild masking detection;
673 ## 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
674 ## queue, if applicable.
675 ################################################################################################################################################
676 if [ -f "${ULE_MASK_FILE}" ]; then
677 grep -Eq "^(${pprovide}|${provide})$" "${ULE_MASK_FILE}"
679 if [ $?
-eq ${true} ]; then
680 vecho
"Package (${provide}) found in ULE_MASK, skipping..."
685 ################################################################################################################################################
686 ## Portage compatible installer and privelege dropping autodetection;
687 ## This is where autodetection takes place. This will make it not only automatically detect which portage compatible installer to use,
688 ## 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
689 ## breakage. This is hacky and can break with changes to the package managers, though it will be fixed, I do hope that portage adds
690 ## PKGMANAGER in the future.
691 ################################################################################################################################################
692 spec
="${DEFAULT_EMERGE_PROGRAM}"
693 if [ ${FORCE_DEFAULT_EMERGE_PROGRAM} -eq ${false} ]; then
694 if [ -f "${dir}/PKGMANAGER" ]; then
695 tmp
=$
(cat "${dir}/PKGMANAGER")
696 if [[ "${tmp}" =~
(paludis
)-.
* ]] && [ "${BASH_REMATCH[1]}" == paludis
]; then
698 ## Versions prior to 22 didn't have the ability to be run as non-superuser.
699 [ -n ${PALVER} ] && export PALVER
=`paludis --version | head -n1 | sed -e 's/.* [0-9].\([0-9][0-9]\)..*/\1/g'`
700 if [ ${PALVER} -gt 21 ]; then
701 decho
"Paludis version ${tmp} (greater than version 0.22.0) is the portage compatible installer"
704 decho
"Paludis version ${tmp} (less than version 0.22.0) is the portage compatible installer"
706 elif [[ "${tmp}" =~
(pkgcore
)-.
* ]] && [ "${BASH_REMATCH[1]}" == pkgcore
]; then
707 decho
"Pkgcore is the portage compatible installer"
711 echo "Your portage compatible installer was not recognized, please report this problem"
712 echo "Continuing using default portage compatible installer ${EMERGE_BINARY[${DEFAULT_EMERGE_PROGRAM}]}"
716 decho
"Emerge is the portage compatible installer"
721 ################################################################################################################################################
722 ## Begin date detection;
723 ## This looks for a ebuild/date combination for the current ebuild being analyzed, if it exists, this will detect if it has been updated
724 ## since the date in the ebuild/date combination and if it has, it will not attempt to emerge again until that time has expired.
725 ################################################################################################################################################
726 [ ${REPORT} -eq ${false} ] && [ -f "${ULE_DATE_FILE}" ] &&
727 userdays=`grep -E "^
(\
*\
/\
*\
:${SLOT}|${CATEGORY}\/\*|${pprovide}|${provide}) [0-9]*" "${ULE_DATE_FILE}" | tail -n1`
729 if [ ${ALL} -eq ${false} ] && [ ${BASELINE} -eq ${false} ] && [ -n "${userdays}" ]; then
731 if [[ ${userdays} =~ (\*\/\*\:${SLOT} )(.*) ]] || [[ ${userdays} =~ (${CATEGORY}\
/\
* )(.
*) ]] || \
732 [[ ${userdays} =~ (${pprovide} )(.*) ]] || [[ ${userdays} =~ (${provide} )(.
*) ]]; then
734 [ -n ${ebuild_epoch} ] && update_ebuild_epoch
736 updateepoch
=$
(((86400*${BASH_REMATCH[2]})+${ebuild_epoch}))
737 diffepoch
=$
((${updateepoch} - ${curepoch}))
739 if [ ${diffepoch} -ne 0 ] && [ ${updateepoch} -gt ${curepoch} ]; then
740 if [ ${diffepoch} -gt 86400 ]; then
741 vecho
"$((${diffepoch}/86400)) days until scheduled update attempts resume for ${provide}."
743 vecho
"Less than a day until scheduled update attempts resume for ${provide}"
749 unset updateepoch curepoch userdays
751 if [ ${REPORT} -eq ${true} ]; then
752 if [ -n ${ebuild_epoch} ]; then
759 printf "${provide}\n"
760 printf "\tRevision: ${ULE_COOKIE}\n"
761 printf "\tEmerged on: `date -d \"1970-01-01 UTC ${ebuild_epoch} sec\" \"+${DATE_FORMAT}\"`\n\n"
765 vecho
"Attempting to check if ${provide} needs an update."
767 if [ -f /etc
/make.conf
] && [ ${spec} -eq ${portage} ] || [ ${spec} -eq ${pkgcore} ]; then
768 grep 'userpriv' /etc
/make.conf |
grep -v '.*#.*userpriv.*'&>/dev
/null
769 [ $?
-eq 0 ] && prescm
=${true}
772 if [ ${prescm} -eq ${true} ]; then
773 decho
"Dropping privileges for ${provide}."
774 prescm
="sudo -u ${EMERGE_USER[${spec}]}"
776 decho
"Not dropping privileges for ${provide}."
782 ## As long as 'newhash' was calculated last in the section above, this should be the outcome of it.
783 update_check $?
"${provide}"
785 ################################################################################################################################################
786 ## Where the magic happens;
789 ## We cannot locbase here, because we can't guarantee the repository has only been updated locally, it's basically assurance that
790 ## the cookie that goes into the ule database is the version that's installed.
792 ## In this case ALL is in the case that the user wants to reinstall and reupdate the ule database, reguardless of updates. The
793 ## locbase is also showing that we assume we didn't previously use the emerger().
795 ## This is the case where the ULE_COOKIE matches the newhash (no updates!), we're going to skip the emerge and simply baseline,
796 ## or we've got an empty newhash, which should absolutely, positively never happen. The only reason it would happen is
797 ## if there aren't enough update_check()s sprinkled above. This can also be caused by the SCM command line interface
798 ## throwing the wrong exit code, for example throwing 0 on failure (see Subversion bug 2414).
800 ## Finally, this will be where 90-95% of all emerger() inits go, we cleanup prior to it then set the emerger to emerge with
802 ################################################################################################################################################
803 if [ -z "${ULE_COOKIE}" ] && [ ${locbase} -eq ${false} ]; then
804 vecho "No previous cookie detected
, reemerging
"
805 elif [ ${ALL} -eq ${true} ] && [ ${locbase} -eq ${false} ]; then
806 vecho "Emerging all
, reemerging
"
807 elif [ "${ULE_COOKIE}" == "${newhash}" ] || [ ${locbase} -eq ${true} ] || [ -z "${newhash}" ]; then
808 if [ ${locbase} -eq ${true} ]; then
809 vecho "Baselineing
${provide}"
810 write_to_db "${newhash}" "${ULE_LOC}/${provide}"
812 [ -z "${newhash}" ] && vecho "Newhash empty
, this should never happen unless errors that wern
't caught previously"
813 unset ${CUREXPORTS} CUREXPORTS
817 unset ${CUREXPORTS} CUREXPORTS
821 unset provide newhash type locbase
824 [ ${REPORT} -eq ${true} ] && exit 0
826 [ ${VERBOSE} -eq ${true} ] && echo 'Update complete
'
828 [ -n "${1}" ] && exit 0
830 ## Update-only cannot make it this far; thus this should be fine.
832 ## Cleanup the ULE directory
833 echo "Cleaning ULE database"
834 for file in ${ULE_DB_FILES}; do
835 [ -n "${PACKAGES}" ] && PACKAGES="${PACKAGES} -a"
836 PACKAGES="${PACKAGES} -not -wholename "${file}""
839 ## Find and remove the ULE_INFO files
840 find ${ULE_LOC} -maxdepth 3 -mindepth 3 ${PACKAGES} -exec rm -v {} \;
842 ## Clean out the empty directories
843 find ${ULE_LOC} -depth -empty -type d -exec rmdir -v {} \;
845 if [ -n "${SUCCESS_PACKAGES}" ] && [ "${VERBOSE}" -eq ${true} ]; then
846 echo "The following packages were updated: ${SUCCESS_PACKAGES}"
847 unset SUCCESS_PACKAGES
850 if [ -n "${FAILED_PACKAGES}" ]; then
851 echo "The following programs failed: ${FAILED_PACKAGES}."
852 echo "You could either rerun this program at a later date, or you could do it on an individual"
853 echo "basis by just using the package spec as a argument: i.e. ${0} net-www/gnash"
854 unset FAILED_PACKAGES
857 if [ -n "${UPDATE_FAIL_PACKAGES}" ]; then
858 echo "The following programs failed when trying to be updated by update-live-ebuilds: ${UPDATE_FAIL_PACKAGES}"
859 unset UPDATE_FAIL_PACKAGES