Magellan Linux

Diff of /branches/mage-next/src/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 1570 by niro, Wed Dec 28 10:26:01 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    # read everything from /etc/env.d
28    for file in ${MROOT}/etc/env.d/*
29  do  do
30   #reads content of every file   # abort if "empty"
31   while read path   [[ ${file} = ${MROOT}/etc/env.d/\* ]] && continue
32    
33     # reads content of every file
34     while read line
35   do   do
36   if [ -n "$path" ]   # ignore if empty or a comment
37     case "${line}" in
38     \#*|"") continue ;;
39     esac
40    
41     variable="${line%%=*}"
42     # substitudes " from $line if exists
43     path="${line//\"}" #}" <--- make code readable again :)
44     value="${line##*=}"
45    
46     # writes LDPATH to ${MROOT}/etc/ld.so.conf,
47     # anything else to ${MROOT}/etc/profile.env
48     if [[ ${variable} = LDPATH ]]
49   then   then
50   #writes LDPATH to ${P}/etc/ld.so.conf,   echo "${value}" >> ${MROOT}/etc/ld.so.conf
51   #anything else to ${P}/etc/profile.env   else
52   if [ "${path%%=*}" == LDPATH ]   # checks if var exists in specialvars
53     for i in ${SPECIALVARS}
54     do
55     [[ ${variable} = ${i} ]] && SPECVAR="yes"
56     done
57    
58     if [[ ${SPECVAR} = yes ]]
59   then   then
60   #substitudes " from $path if exists   case ${variable} in
61   path="${path//\"}"   CONFIG_PROTECT*|XDG*)
62   echo "${path##*=}" >> ${P}/etc/ld.so.conf   # CONFIG_PROTECT*|XDG* have as delimiter  not ':'  but ' '
63   else   echo -n "${value} " >> ${TMPDIR}/${variable}
  #checks if var exists in specialvars  
  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%%=*}  
64   unset SPECVAR   unset SPECVAR
65   else   ;;
66   #special var are written to tmpfile   *)
67     # special vars are written to tmpfile
68   # to substitude them to one variable   # to substitude them to one variable
69   #substitudes " from $path if exists   echo -n "${value}:" >> ${TMPDIR}/${variable}
  path="${path//\"}"  
  echo -n "${path##*=}:" >> /var/tmp/${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 ${line}" >> ${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 variable in ${SPECIALVARS}
86  do  do
87   if [ -f /var/tmp/${i} ]   if [ -f ${TMPDIR}/${variable} ]
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 [[ ${variable} = OMF_DIR ]]
91     then
92     echo "${variable}=$(< ${TMPDIR}/${variable})" > ${MROOT}/etc/scrollkeeper.conf
93     else
94     echo "export ${variable}=\"$(< ${TMPDIR}/${variable})\"" >> ${MROOT}/etc/profile.env
95     fi
96     rm ${TMPDIR}/${variable}
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.1570