Magellan Linux

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

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

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

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