Magellan Linux

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

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

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

Legend:
Removed from v.78  
changed lines
  Added in v.1272