Magellan Linux

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

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

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

Legend:
Removed from v.33  
changed lines
  Added in v.456