Magellan Linux

Diff of /trunk/mage/usr/lib/mage/env-rebuild.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 40 by niro, Thu Jan 6 23:28:28 2005 UTC revision 1568 by niro, Wed Dec 28 10:16:42 2011 UTC
# Line 1  Line 1 
1  #!/bin/sh  #!/bin/bash
2    # $Id$
 # version: 0.3.6-r10  
3  #  #
4  # rebuilds /etc/{ld.so.conf,profile.env} with given files from /etc/env.d  # rebuilds /etc/{ld.so.conf,profile.env} with given files from /etc/env.d
5  #  #
6    
7  ##  SPECIALVARS="KDEDIRS PATH CLASSPATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH"
8  # exp. /etc/env.d/kde  SPECIALVARS+=" CONFIG_PROTECT CONFIG_PROTECT_MASK CONFIG_PROTECT_IGNORE"
9  #  SPECIALVARS+=" PRELINK_PATH PRELINK_PATH_MASK"
10  # PATH="/opt/kde/bin"  SPECIALVARS+=" OMF_DIR LIBGL_DRIVERS_PATH XDG_CONFIG_DIRS XDG_DATA_DIRS"
 # ROOTPATH="/opt/kde/bin"  
 # LDPATH="/opt/kde/lib"  
 #  
 ##  
11    
12  #sets root path  # secure tmp dir
13  P=""  if [ -x /bin/mktemp ]
 SPECIALVARS="KDEDIRS PATH CLASSPATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CONFIG_PROTECT CONFIG_PROTECT_MASK PRELINK_PATH PRELINK_PATH_MASK"  
 #SPECIALVARS="KDEDIRS PATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CLASSPATH"  
   
 echo -en "\n>>>> Rebuilding environment... "  
   
 #deletes existing conf files  
 if [ -f ${P}/etc/ld.so.conf ]  
14  then  then
15   rm ${P}/etc/ld.so.conf   TMPDIR="$(/bin/mktemp -d -p /var/tmp)"
16    else
17     TMPDIR="/var/tmp/tmp.$$"
18     install -d ${TMPDIR}
19  fi  fi
20    
21  if [ -f ${P}/etc/profile.env ]  echo -en "\n>>>> Rebuilding environment... "
 then  
  rm ${P}/etc/profile.env  
 fi  
22    
23  #gets everything in /etc/env.d  # clean existing conf files
24  for file in ${P}/etc/env.d/*  :> ${MROOT}/etc/ld.so.conf
25    :> ${MROOT}/etc/profile.env
26    
27    # gets everything in /etc/env.d
28    for file in ${MROOT}/etc/env.d/*
29  do  do
30   #reads content of every file   # abort if "empty"
31     [[ ${file} = ${MROOT}/etc/env.d/\* ]] && continue
32    
33     # reads content of every file
34   while read path   while read path
35   do   do
36   if [ -n "$path" ]   # ignore if empty or a comment
37     case "${path}" in
38     \#*|"") continue ;;
39     esac
40    
41     # writes LDPATH to ${P}/etc/ld.so.conf,
42     # anything else to ${P}/etc/profile.env
43     if [[ ${path%%=*} = LDPATH ]]
44   then   then
45   #writes LDPATH to ${P}/etc/ld.so.conf,   #substitudes " from $path if exists
46   #anything else to ${P}/etc/profile.env   path="${path//\"}" #}" <--- make code readable again :)
47   if [ "${path%%=*}" == LDPATH ]   echo "${path##*=}" >> ${MROOT}/etc/ld.so.conf
48     else
49     # checks if var exists in specialvars
50     for i in ${SPECIALVARS}
51     do
52     [[ ${path%%=*} = ${i} ]] && SPECVAR="yes"
53     done
54    
55     if [[ ${SPECVAR} = yes ]]
56   then   then
57   #substitudes " from $path if exists   case ${path%%=*} in
58   path="${path//\"}"   CONFIG_PROTECT*|XDG*)
59   echo "${path##*=}" >> ${P}/etc/ld.so.conf   # CONFIG_PROTECT*|XDG* have as delimiter  not ':'  but ' '
60   else   path="${path//\"}" #}" <--- make code readable again :)
61   #checks if var exists in specialvars   echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*}
  for i in $SPECIALVARS  
  do  
  if [ "${path%%=*}" == "$i" ]  
  then  
  SPECVAR="yes"  
  fi  
  done  
   
  if [ "$SPECVAR" == "yes" ]  
  then  
  if [ "${path%%=*}" == "CONFIG_PROTECT" -o "${path%%=*}" == "CONFIG_PROTECT_MASK" ]  
  then  
  #CONFIG_PROTECTS has as delimiter  not ':'  but ' '  
  path="${path//\"}"  
  echo -n "${path##*=} " >> /var/tmp/${path%%=*}  
62   unset SPECVAR   unset SPECVAR
63   else   ;;
64   #special var are written to tmpfile   *)
65     # special var are written to tmpfile
66   # to substitude them to one variable   # to substitude them to one variable
67   #substitudes " from $path if exists   # substitudes " from $path if exists
68   path="${path//\"}"   path="${path//\"}" #}" <--- make code readable again :)
69   echo -n "${path##*=}:" >> /var/tmp/${path%%=*}   echo -n "${path##*=}:" >> ${TMPDIR}/${path%%=*}
70   unset SPECVAR   unset SPECVAR
71   fi   ;;
72   else   esac
73   #all other vars go directly to /etc/profile.env   else
74   echo "export $path" >> ${P}/etc/profile.env   # all other vars go directly to /etc/profile.env
75   fi   echo "export ${path}" >> ${MROOT}/etc/profile.env
76   fi   fi
77   fi   fi
78   done << EOF   done << EOF
79  $(cat $file)  $(cat ${file})
80  EOF  EOF
81    
82  done  done
83    
84  #reads special vars tmp files and writes them to /etc/profile.env  # reads special vars tmp files and writes them to /etc/profile.env
85  for i in $SPECIALVARS  for i in ${SPECIALVARS}
86  do  do
87   if [ -f /var/tmp/${i} ]   if [ -f ${TMPDIR}/${i} ]
88   then   then
89   echo "export ${i}=\"`cat /var/tmp/${i}`\"" >> ${P}/etc/profile.env   # only OMF_DIR goes to /etc/scrollkeeper.conf
90   rm /var/tmp/${i}   if [[ ${i} = OMF_DIR ]]
91     then
92     echo "${i}=$(cat ${TMPDIR}/${i})" > ${MROOT}/etc/scrollkeeper.conf
93     else
94     echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${MROOT}/etc/profile.env
95     fi
96     rm ${TMPDIR}/${i}
97   fi   fi
98  done  done
99    
100  #rebuilds environment  # rebuilds environment
101  ldconfig  ldconfig -r "${MROOT}" -f /etc/ld.so.conf -C /etc/ld.so.cache
102  source ${P}/etc/profile  [ -f ${MROOT}/etc/profile ] && source ${MROOT}/etc/profile
103    
104    # cleanups
105    [ -d ${TMPDIR} ] && rm -rf ${TMPDIR}
106    
107  echo -e "done.\n"  echo -e "done.\n"

Legend:
Removed from v.40  
changed lines
  Added in v.1568