Magellan Linux

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

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

revision 223 by niro, Fri Sep 9 16:34:35 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$
 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/env-rebuild.sh,v 1.8 2005-09-09 16:30:25 niro Exp $  
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    
 ##  
 # exp. /etc/env.d/kde  
 #  
 # PATH="/opt/kde/bin"  
 # ROOTPATH="/opt/kde/bin"  
 # LDPATH="/opt/kde/lib"  
 #  
 ##  
   
7  # sets root path  # sets root path
8  P="${MROOT}"  P="${MROOT}"
9  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"  
10    
11  echo -en "\n>>>> Rebuilding environment... "  # secure tmp dir
12    if [ -x /bin/mktemp ]
 # 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... "
21  then  
22   rm ${P}/etc/profile.env  # clean existing conf files
23  fi  :> ${P}/etc/ld.so.conf
24    :> ${P}/etc/profile.env
25    
26  # gets everything in /etc/env.d  # 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     # abort if "empty"
30     [[ ${file} = ${P}/etc/env.d/\* ]] && continue
31    
32   # reads content of every file   # 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//\"}" #}" <--- make code readable again :)   CONFIG_PROTECT*|XDG*)
58   echo "${path##*=}" >> ${P}/etc/ld.so.conf   # CONFIG_PROTECT*|XDG* have as delimiter  not ':'  but ' '
  else  
  # 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 ]] || [[ ${path%%=*} = CONFIG_PROTECT_MASK ]]  
  then  
  # CONFIG_PROTECTS has as delimiter  not ':'  but ' '  
59   path="${path//\"}" #}" <--- make code readable again :)   path="${path//\"}" #}" <--- make code readable again :)
60   echo -n "${path##*=} " >> /var/tmp/${path%%=*}   echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*}
61   unset SPECVAR   unset SPECVAR
62   else   ;;
63     *)
64   # special var are written to tmpfile   # 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//\"}" #}" <--- make code readable again :)   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
# Line 88  done Line 83  done
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   # only OMF_DIR goes to /etc/scrollkeeper.conf   # only OMF_DIR goes to /etc/scrollkeeper.conf
89   if [[ ${i} = OMF_DIR ]]   if [[ ${i} = OMF_DIR ]]
90   then   then
91   echo "${i}=`cat /var/tmp/${i}`" > ${P}/etc/scrollkeeper.conf   echo "${i}=$(cat ${TMPDIR}/${i})" > ${P}/etc/scrollkeeper.conf
92   else   else
93   echo "export ${i}=\"`cat /var/tmp/${i}`\"" >> ${P}/etc/profile.env   echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${P}/etc/profile.env
94   fi   fi
95   rm /var/tmp/${i}   rm ${TMPDIR}/${i}
96   fi   fi
97  done  done
98    
99  # rebuilds environment  # rebuilds environment
100  ldconfig -r "${P}" -f /etc/ld.so.conf -C /etc/ld.so.cache  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.223  
changed lines
  Added in v.1566