home *** CD-ROM | disk | FTP | other *** search
- # Copyright 1999-2005 Gentoo Foundation
- # Distributed under the terms of the GNU General Public License v2
- # $Id: env.eselect 248 2005-12-19 00:09:40Z kugelfang $
-
- inherit config multilib
-
- DESCRIPTION="Manage environment variables set in /etc/env.d/"
- MAINTAINER="kugelfang@gentoo.org"
- SVN_DATE='$Date: 2005-12-19 00:09:40 +0000 (Mon, 19 Dec 2005) $'
- VERSION=$(svn_date_to_version "${SVN_DATE}" )
-
- # Classes of env-vars
- SPECIAL_CLASS="KDEDIRS CLASSPATH INFODIR ROOTPATH CONFIG_PROTECT CONFIG_PROTECT_MASK"
- PATH_CLASS="ADA_INCLUDE_PATH ADA_OBJECT_PATH INFOPATH MANPATH PATH PRELINK_PATH
- PRELINK_PATH_MASK PYTHONPATH ROOTPATH"
-
- # Configuration files
- ENVPROFILE="${ROOT}/etc/profile.env"
- LDCONFIG="${ROOT}/etc/ld.so.conf"
- PRELINK="${ROOT}/etc/prelink.conf"
- LDMTIMEDB="${ROOT}/etc/eselect/ld-mtimedb"
-
- # Keep all stored LDPATHS
- LDPATH=""
-
- # create_profile_env()
- # Create profile.env file
- create_profile_env() {
- local envfiles vars store items
- envfiles=( ${ROOT}/etc/env.d/* )
-
- # Output to a new file first!
- ENVPROFILE=${ENVPROFILE}.new
- rm -f ${ENVPROFILE} &> /dev/null
-
- # Parse all files in env.d
- for envfile in ${envfiles[@]} ; do
- # Make sure it is a file and no backup file
- [[ -f ${envfile} ]] || continue
- [[ -n ${envfile##*~} ]] || continue
- [[ ${envfile##*.} != bak ]] || continue
-
- if ! file -i ${envfile} | grep -q text/plain ; then
- echo "Skipping non-text file ${envfile}."
- fi
-
- # Which vars are to be loaded?
- # TODO: Change to bash magic?
- vars=$(sed \
- -e '/^#/d' -e '/^\s*$/d' -e '/^.*=/s/^\(.*\)=.*/\1/' \
- ${envfile})
- [[ -z ${vars} ]] && continue
- for var in ${vars} ; do
- # Colon separated?...
- if has ${var} ${PATH_CLASS} ; then
- store=$(load_config ${ENVPROFILE} ${var})
- if [[ -z ${store} ]] ; then
- store=$(load_config ${envfile} ${var})
- else
- items="$(load_config ${envfile} ${var})"
- items=( ${items//:/ } )
- for item in ${items[@]} ; do
- has ${item} ${store//:/ } && continue
- store="${store}:${item}"
- done
- fi
- store_config ${ENVPROFILE} ${var} "${store#:}"
- continue
- fi
- # ...everything else is space separated!
- if has ${var} ${SPECIAL_CLASS} ; then
- store=( $(load_config ${ENVPROFILE} ${var}) )
- if [[ -z ${store[@]} ]] ; then
- store=( $(load_config ${envfile} ${var}) )
- else
- items=( $(load_config ${envfile} ${var}) )
- for item in ${items[@]} ; do
- has ${item} ${store[@]} && continue
- store=( ${store[@]} ${item} )
- done
- fi
- store_config ${ENVPROFILE} ${var} "${store[@]}"
- continue
- fi
- [[ ${var} == LDPATH ]] && continue
- # Ok, just a non-cummultative var.
- store_config \
- ${ENVPROFILE} \
- ${var} \
- "$(load_config ${envfile} ${var})"
- done
-
- has LDPATH ${vars} || continue
- # Store LDPATH for later processing
- items=$(load_config ${envfile} LDPATH)
- items=( ${items//:/ } )
- for item in ${items[@]} ; do
- has ${item} ${LDPATH[@]} && continue
- LDPATH=( ${LDPATH[@]} ${item} )
- done
- done
-
- # Move new file onto old one
- ENVPROFILE=${ENVPROFILE%%.new}
- mv ${ENVPROFILE}.new ${ENVPROFILE}
- }
-
- # create_ld_so_conf()
- # Create ld.so.conf file based upon gathered LDPATHs
- create_ld_so_conf() {
- [[ -z ${LDPATH[@]} ]] && die -q 'No LDPATHs found in ${ROOT}/etc/env.d/*'
-
- local str
- str="# ld.so.conf autogenerated by eselect\n# Make all changes to /etc/env.d files\n"
- for x in ${LDPATH[@]} ; do
- str="${str}${x}\n"
- done
- echo -e "${str}" > ${LDCONFIG}
- }
-
- # create_prelink_conf()
- # Create prelink.conf file based upon existing profile.env
- create_prelink_conf() {
- [[ -z ${LDPATH[@]} ]] && die -q 'No LDPATHs found in ${ROOT}/etc/env.d/*'
- local str
- str="# prelink.conf autogenerated by eselect\n"
- str="${str}# Make all changes to /etc/env.d files\n"
- # Add default items
- for x in /bin /sbin /usr/bin /usr/sbin ; do
- str="${str}-l ${x}\n"
- done
- for x in $(list_libdirs) ; do
- [[ -e ${ROOT}/${x} ]] && str="${str}-l /${x}\n"
- [[ -e ${ROOT}/usr/${x} ]] && str="${str}-l /usr/${x}\n"
- done
- prelink_mask=$(load_config ${ENVPROFILE} PRELINK_PATH_MASK)
- prelink_mask=( ${prelink_mask//:/ } )
- prelink="$(load_config ${ENVPROFILE} PATH)"
- prelink="${prelink} $(load_config ${ENVPROFILE} PRELINK_PATH)"
- prelink=( ${prelink//:/ } ${LDPATH[@]} )
- for x in ${prelink[@]} ; do
- has ${x} ${prelink_mask} && continue
- [[ -z ${x##*/} ]] || x="${x}/"
- str="${str}-h ${x}\n"
- done
- for x in ${prelink_mask[@]} ; do
- str="${str}-b ${x}\n"
- done
- echo -e "${str}" > ${PRELINK}
- }
-
- # need_links()
- # Returns true if any item of ${LDPATH} has been modified.
- need_links() {
- local ret=1
- for x in ${LDPATH[@]} ; do
- y=${x//\//_}
- y=${y//-/_}
- y=${y//./_}
- y=${y//+/_}
- oldmtime=$(load_config ${LDMTIMEDB} "mtime${y}")
- newmtime=$(stat -c %Y ${x} 2> /dev/null)
- if [[ ${oldmtime} != ${newmtime} ]] ; then
- ret=0
- store_config ${LDMTIMEDB} "mtime${y}" ${newmtime}
- fi
- done
- return ${ret}
- }
-
- # update_ldcache()
- # Update ld.so.cache using ldconfig
- update_ldcache() {
- echo "Regenerating ${ROOT}/etc/ld.so.cache..."
- (
- cd /
- ldconfig ${1} -r ${ROOT:-/}
- )
- }
-
- ### update action
-
- describe_update() {
- echo "Collect environment variables from all scripts in /etc/env.d/"
- }
-
- describe_update_parameters() {
- echo "<makelinks>"
- }
-
- describe_update_options() {
- echo "makelinks : Specify \"makelinks\" to force updating of links"
- }
-
- do_update() {
- [[ -w ${ROOT}/etc/profile.env ]] || die -q "You need to be root!"
-
- # Create configuration files
- create_profile_env
- create_ld_so_conf
- [[ -e ${ROOT}/usr/sbin/prelink ]] && create_prelink_conf
- makelinks=$( ( need_links || [[ ${1} == makelinks ]] ) && echo "-X" )
- update_ldcache ${makelinks}
-
- # fix up ${ENVPROFILE}
- cp ${ENVPROFILE} ${ENVPROFILE/.env/.csh}
- sed -i \
- -e "s/\"/'/g" \
- -e 's/^\(.*=\)/export \1/' \
- ${ENVPROFILE}
- sed -i \
- -e "s/\"/'/g" \
- -e 's/^\(.*=\)/setenv \1/' \
- ${ENVPROFILE/.env/.csh}
- }
-
- # vim: ft=eselect
-