#!/bin/bash # $Id$ # # rebuilds /etc/{ld.so.conf,profile.env} with given files from /etc/env.d # SPECIALVARS="KDEDIRS PATH CLASSPATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH" SPECIALVARS+=" CONFIG_PROTECT CONFIG_PROTECT_MASK CONFIG_PROTECT_IGNORE" SPECIALVARS+=" PRELINK_PATH PRELINK_PATH_MASK" SPECIALVARS+=" 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 :> ${MROOT}/etc/ld.so.conf :> ${MROOT}/etc/profile.env # read everything from /etc/env.d for file in ${MROOT}/etc/env.d/* do # abort if "empty" [[ ${file} = ${MROOT}/etc/env.d/\* ]] && continue # reads content of every file while read line do # ignore if empty or a comment case "${line}" in \#*|"") continue ;; esac variable="${line%%=*}" value="${line##*=}" # substitudes " or ' from $value if exists value="${value//\"}" #}" <--- make code readable again :) value="${value//\'}" # writes LDPATH to ${MROOT}/etc/ld.so.conf, # anything else to ${MROOT}/etc/profile.env if [[ ${variable} = LDPATH ]] then echo "${value}" >> ${MROOT}/etc/ld.so.conf else # checks if var exists in specialvars for i in ${SPECIALVARS} do [[ ${variable} = ${i} ]] && SPECVAR="yes" done if [[ ${SPECVAR} = yes ]] then case ${variable} in CONFIG_PROTECT*) # CONFIG_PROTECT** have as delimiter not ':' but ' ' echo -n "${value} " >> ${TMPDIR}/${variable} unset SPECVAR ;; *) # special vars are written to tmpfile # to substitude them to one variable echo -n "${value}:" >> ${TMPDIR}/${variable} unset SPECVAR ;; esac else # all other vars go directly to /etc/profile.env echo "export ${line}" >> ${MROOT}/etc/profile.env fi fi done << EOF $(cat ${file}) EOF done # reads special vars tmp files and writes them to /etc/profile.env for variable in ${SPECIALVARS} do if [ -f ${TMPDIR}/${variable} ] then # only OMF_DIR goes to /etc/scrollkeeper.conf if [[ ${variable} = OMF_DIR ]] then echo "${variable}=$(< ${TMPDIR}/${variable})" > ${MROOT}/etc/scrollkeeper.conf else echo "export ${variable}=\"$(< ${TMPDIR}/${variable})\"" >> ${MROOT}/etc/profile.env fi rm ${TMPDIR}/${variable} fi done # rebuilds environment ldconfig -r "${MROOT}" -f /etc/ld.so.conf -C /etc/ld.so.cache [ -f ${MROOT}/etc/profile ] && source ${MROOT}/etc/profile # cleanups [ -d ${TMPDIR} ] && rm -rf ${TMPDIR} echo -e "done.\n"