#!/bin/sh # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/env-rebuild.sh,v 1.13 2007-07-01 00:35:29 niro Exp $ # # rebuilds /etc/{ld.so.conf,profile.env} with given files from /etc/env.d # ## # exp. /etc/env.d/kde # # PATH="/opt/kde/bin" # ROOTPATH="/opt/kde/bin" # LDPATH="/opt/kde/lib" # ## # sets root path P="${MROOT}" SPECIALVARS="KDEDIRS PATH CLASSPATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CONFIG_PROTECT CONFIG_PROTECT_MASK CONFIG_PROTECT_IGNORE PRELINK_PATH PRELINK_PATH_MASK OMF_DIR LIBGL_DRIVERS_PATH XDG_CONFIG_DIRS XDG_DATA_DIRS" # secure tmp dir if [ -x /bin/mktemp ] then TMPDIR="$(/bin/mktemp -d -p /var/tmp)" else TMPDIR="/var/tmp/tmp.$$" install -d ${TMPDIR} fi echo -en "\n>>>> Rebuilding environment... " # clean existing conf files :> ${P}/etc/ld.so.conf :> ${P}/etc/profile.env # gets everything in /etc/env.d for file in ${P}/etc/env.d/* do # abort if "empty" [[ ${file} = ${P}/etc/env.d/\* ]] && continue # reads content of every file while read path do # ignore if empty or a comment case "${path}" in \#*|"") continue ;; esac # writes LDPATH to ${P}/etc/ld.so.conf, # anything else to ${P}/etc/profile.env if [[ ${path%%=*} = LDPATH ]] then #substitudes " from $path if exists path="${path//\"}" #}" <--- make code readable again :) echo "${path##*=}" >> ${P}/etc/ld.so.conf else # checks if var exists in specialvars for i in ${SPECIALVARS} do [[ ${path%%=*} = ${i} ]] && SPECVAR="yes" done if [[ ${SPECVAR} = yes ]] then case ${path%%=*} in CONFIG_PROTECT*|XDG*) # CONFIG_PROTECT*|XDG* have as delimiter not ':' but ' ' path="${path//\"}" #}" <--- make code readable again :) echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*} unset SPECVAR ;; *) # special var are written to tmpfile # to substitude them to one variable # substitudes " from $path if exists path="${path//\"}" #}" <--- make code readable again :) echo -n "${path##*=}:" >> ${TMPDIR}/${path%%=*} unset SPECVAR ;; esac else # all other vars go directly to /etc/profile.env echo "export ${path}" >> ${P}/etc/profile.env fi fi done << EOF $(cat ${file}) EOF done # reads special vars tmp files and writes them to /etc/profile.env for i in ${SPECIALVARS} do if [ -f ${TMPDIR}/${i} ] then # only OMF_DIR goes to /etc/scrollkeeper.conf if [[ ${i} = OMF_DIR ]] then echo "${i}=$(cat ${TMPDIR}/${i})" > ${P}/etc/scrollkeeper.conf else echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${P}/etc/profile.env fi rm ${TMPDIR}/${i} fi done # rebuilds environment ldconfig -r "${P}" -f /etc/ld.so.conf -C /etc/ld.so.cache [ -f ${P}/etc/profile ] && source ${P}/etc/profile # cleanups [ -d ${TMPDIR} ] && rm -rf ${TMPDIR} echo -e "done.\n"