Magellan Linux

Diff of /branches/mage-next/src/env-rebuild.in

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

trunk/mage/usr/lib/mage/env-rebuild.sh revision 24 by niro, Wed Jan 5 05:08:01 2005 UTC branches/mage-next/src/env-rebuild.in revision 2549 by niro, Wed Jan 29 11:47:55 2014 UTC
# Line 1  Line 1 
1  #!/bin/sh  #!/bin/bash
2    # $Id$
 # version: 0.3.6-r8  
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     value="${line##*=}"
43    
44     # substitudes " or ' from $value if exists
45     value="${value//\"}" #}" <--- make code readable again :)
46     value="${value//\'}"
47    
48     # writes LDPATH to ${MROOT}/etc/ld.so.conf,
49     # anything else to ${MROOT}/etc/profile.env
50     if [[ ${variable} = LDPATH ]]
51   then   then
52   #writes LDPATH to ${P}/etc/ld.so.conf,   echo "${value}" >> ${MROOT}/etc/ld.so.conf
53   #anything else to ${P}/etc/profile.env   else
54   if [ "${path%%=*}" == LDPATH ]   # checks if var exists in specialvars
55     for i in ${SPECIALVARS}
56     do
57     [[ ${variable} = ${i} ]] && SPECVAR="yes"
58     done
59    
60     if [[ ${SPECVAR} = yes ]]
61   then   then
62   #substitudes " from $path if exists   case ${variable} in
63   path="${path//\"}"   CONFIG_PROTECT*)
64   echo "${path##*=}" >> ${P}/etc/ld.so.conf   # CONFIG_PROTECT** have as delimiter  not ':'  but ' '
65   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%%=*}  
66   unset SPECVAR   unset SPECVAR
67   else   ;;
68   #special var are written to tmpfile   *)
69     # special vars are written to tmpfile
70   # to substitude them to one variable   # to substitude them to one variable
71   #substitudes " from $path if exists   echo -n "${value}:" >> ${TMPDIR}/${variable}
  path="${path//\"}"  
  echo -n "${path##*=}:" >> /var/tmp/${path%%=*}  
72   unset SPECVAR   unset SPECVAR
73   fi   ;;
74   else   esac
75   #all other vars go directly to /etc/profile.env   else
76   echo "export $path" >> ${P}/etc/profile.env   # all other vars go directly to /etc/profile.env
77   fi   echo "export ${line}" >> ${MROOT}/etc/profile.env
78   fi   fi
79   fi   fi
80   done << EOF   done << EOF
81  $(cat $file)  $(cat ${file})
82  EOF  EOF
83    
84  done  done
85    
86  #reads special vars tmp files and writes them to /etc/profile.env  # reads special vars tmp files and writes them to /etc/profile.env
87  for i in $SPECIALVARS  for variable in ${SPECIALVARS}
88  do  do
89   if [ -f /var/tmp/${i} ]   if [ -f ${TMPDIR}/${variable} ]
90   then   then
91   echo "export ${i}=\"`cat /var/tmp/${i}`\"" >> ${P}/etc/profile.env   # only OMF_DIR goes to /etc/scrollkeeper.conf
92   rm /var/tmp/${i}   if [[ ${variable} = OMF_DIR ]]
93     then
94     echo "${variable}=$(< ${TMPDIR}/${variable})" > ${MROOT}/etc/scrollkeeper.conf
95     else
96     echo "export ${variable}=\"$(< ${TMPDIR}/${variable})\"" >> ${MROOT}/etc/profile.env
97     fi
98     rm ${TMPDIR}/${variable}
99   fi   fi
100  done  done
101    
102  #rebuilds environment  # rebuilds environment
103  ldconfig  ldconfig -r "${MROOT}" -f /etc/ld.so.conf -C /etc/ld.so.cache
104  source ${P}/etc/profile  [ -f ${MROOT}/etc/profile ] && source ${MROOT}/etc/profile
105    
106    # cleanups
107    [ -d ${TMPDIR} ] && rm -rf ${TMPDIR}
108    
109  echo -e "done.\n"  echo -e "done.\n"

Legend:
Removed from v.24  
changed lines
  Added in v.2549