source: lliurex-rpi-packages/trunk/fuentes/ldm/ltsp/ltsp_config @ 2328

Last change on this file since 2328 was 2328, checked in by kbut, 3 years ago

add new package

File size: 3.9 KB
Line 
1#
2#  Copyright (c) 2005 Canonical LTD
3#
4#  Author: Matt Zimmerman <mdz@canonical.com>
5#
6#  2006, Oliver Grawert <ogra@canonical.com>
7#        Vagrant Cascadian <vagrant@freegeek.org>
8#  2007, Scott Balneaves <sbalneav@ltsp.org>
9#        Oliver Grawert <ogra@canonical.com>
10#  2008, Vagrant Cascadian <vagrant@freegeek.org>
11#        Oliver Grawert <ogra@canonical.com>
12#        Warren Togami <wtogami@redhat.com>
13#        Gideon Romm <ltsp@symbio-technologies.com>
14#  2011, Gideon Romm <ltsp@symbio-technologies.com>
15#
16#  This program is free software; you can redistribute it and/or
17#  modify it under the terms of the GNU General Public License as
18#  published by the Free Software Foundation; either version 2 of the
19#  License, or (at your option) any later version.
20#
21#  This program is distributed in the hope that it will be useful,
22#  but WITHOUT ANY WARRANTY; without even the implied warranty of
23#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24#  GNU General Public License for more details.
25#
26#  You should have received a copy of the GNU General Public License
27#  along with this program.  If not, you can find it on the World Wide
28#  Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
29#  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
30#  MA 02110-1301, USA.
31#
32
33#
34# ltsp_config: This should be sourced by most scripts within an ltsp
35# environment.  Ensures that LTSP5 defaults are set up
36#
37#
38
39# Source ltsp-client-functions if we have not already (needed in some functions)
40# We set PATH to empty string here (in the subshell), because shell will look
41# for boolean_is_true in PATH if it doesn't find it as a built-in function
42# That search is a waste of time and so, we avoid it by not giving a PATH.
43#
44# Also, let's call this at the very beginning to make absolutely sure that
45# anything that calls ltsp_config will have ltsp-client-functions sourced
46(PATH="" boolean_is_true True 2>/dev/null) || . /usr/share/ltsp/ltsp-client-functions || true
47
48# Once lts.conf params are processed, they should all be stored
49# in a quickly source-able file: /var/cache/ltsp/ltsp_config_env
50# If this file does not exist, it means we need to process lts.conf
51# If it does exist, we can either just source it, OR if we are asked
52# to process lts.conf again, we should read in all the environemnt
53# variables that were set last time and unset them before processing the
54# lts.conf again
55ltsp_config_env=/var/cache/ltsp/ltsp_config_env
56
57# Make sure cache dir exists
58mkdir -p /var/cache/ltsp
59
60# This function will set the lts.conf var and will be used by ltsp_config.d/
61# scripts
62set_lts_var() {
63    var=$1
64    val=$2
65    [ -z "$var" ] && return
66    sed -i -e "/$var=/d" ${ltsp_config_env}
67    if [ -n "$val" ]; then
68        export "$var"="$val"
69        echo "$var=\"$val\"" >> ${ltsp_config_env}
70    else
71        unset $var
72    fi   
73}
74
75# This function will reset the lts.conf params that were previously set
76reset_lts_env() {
77    [ -r "${ltsp_config_env}" ] || return
78    oldifs="${IFS-not set}"
79    IFS='='
80    while read var val; do
81        unset $var
82        export $var
83    done < ${ltsp_config_env}
84    test "$oldifs" = "not set" && unset IFS || IFS="$oldifs"
85    rm -f ${ltsp_config_env} 2>/dev/null
86    return 0
87}
88
89# This function sets all vars from cache
90set_lts_from_cache() {
91    [ -r "${ltsp_config_env}" ] || return
92    # Make all vars we are about to set exported
93    set -a
94    . ${ltsp_config_env}
95    set +a
96}
97
98# This function will process the lts.conf params
99process_lts_conf() {
100    set -f
101    if [ -d /usr/share/ltsp/ltsp_config.d ]; then
102        for script in $(run_parts_list /usr/share/ltsp/ltsp_config.d) ; do
103            . $script       
104        done
105    fi
106    set +f
107}
108
109if [ ! -r "${ltsp_config_env}" ]; then
110    process_lts_conf
111else
112    if boolean_is_true "${PROCESS_LTS_CONF}"; then
113        reset_lts_env
114        process_lts_conf
115    else
116        set_lts_from_cache
117    fi
118fi
Note: See TracBrowser for help on using the repository browser.