3 ###########################################################################
5 ## This is a /etc/profile.d script to set user environment and aliases
6 ## based on Elektra keys under 'user/env'.
8 ## Bellow user/env there must be three priorities for environment
15 ## You should distribute your environment variables according to their
16 ## dependencies. For example, if we want to
17 ## set PATH as $JAVA_HOME/bin:$PATH, we'll have to set
19 ## user/env/env1/JAVA_HOME
22 ## This way it is guaranteed that the variables under user/env/env1 are
23 ## set before those under user/env/env2, and before those under
26 ## The folder user/env/alias contains keys to define shell aliases.
27 ## For instance user/env/alias/ls may contain 'ls -Fh', to set an alias
28 ## to the 'ls' command.
30 ## Avi Alkalay <avi at unix dot sh>
35 ###########################################################################
38 if [ -z "$KDB" ]; then
42 FILE="`mktemp -t elektraenv.XXXXXXXXX`"
50 for stage in 1 2 3; do
52 $KDB ls $1/env$stage 2>/dev/null | while read key; do
53 if [ -z $keysAvailable ]; then
55 echo "echo Setting environment from the Elektra key database under '$1'"
57 # This stuff is so complicated, with sed etc, because
58 # we need to superescape a '\$' for envs like PS1
60 $KDB get -s $key | sed -e 's/\([^\\]\)\\\$/\1\\\\\$/g;'
66 $KDB ls $1/alias 2>/dev/null | while read key; do
67 echo alias `$KDB get -s $key`
73 ########################
80 readEnvTree system/env > $FILE
81 (echo; echo; echo) >> $FILE
82 readEnvTree user:$USER/env >> $FILE
85 [ -f $FILE ] && . $FILE
88 [ -f $FILE ] && rm -f $FILE
90 # Clean temporary environment