#!/bin/sh # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/env-rebuild.sh,v 1.11 2005-12-01 12:37:47 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 PRELINK_PATH PRELINK_PATH_MASK OMF_DIR" #SPECIALVARS="KDEDIRS PATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CLASSPATH" # 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 # abort if empty [[ -z ${path} ]] && continue # 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 if [[ ${path%%=*} = CONFIG_PROTECT ]] || [[ ${path%%=*} = CONFIG_PROTECT_MASK ]] then # CONFIG_PROTECTS has as delimiter not ':' but ' ' path="${path//\"}" #}" <--- make code readable again :) echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*} unset SPECVAR else # 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 fi 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"