[debian-edu-commits] debian-edu/ 135/183: What do we do if there are other agents setting up the environment variables that control profiles? Make it configurable.

Alexander Alemayhu ccscanf-guest at moszumanska.debian.org
Wed Jun 11 16:48:40 UTC 2014


This is an automated email from the git hooks/post-receive script.

ccscanf-guest pushed a commit to branch master
in repository desktop-profiles.

commit 9015da3eb9d2469e60940cb9e31ab512bd8a2d2e
Author: Bart Cornelis <cobaco at linux.be>
Date:   Thu Dec 14 22:23:03 2006 +0000

    What do we do if there are other agents setting up the environment variables
    that control profiles? Make it configurable.
    
    The desktop-profiles agent is now an admin controlled shizophrenic with 4
    distinct personalities:
    - autocrat -> ignore contents of the env vars
    - rude     -> our profiles take precedence over the ones in the env vars
    - polite   -> our profiles give precedence over the ones in the env vars
    - sheep    -> just follow allong with wath is already there (this one is just
                  to be complet, MEEEEH!)
---
 20desktop-profiles_activateDesktopProfiles | 235 ++++++++++++++++++++---------
 TODO                                       |   2 +-
 desktop-profiles                           |  14 ++
 update-profile-cache                       |  65 ++++++--
 4 files changed, 228 insertions(+), 88 deletions(-)

diff --git a/20desktop-profiles_activateDesktopProfiles b/20desktop-profiles_activateDesktopProfiles
index 8d65d1e..e778e4d 100644
--- a/20desktop-profiles_activateDesktopProfiles
+++ b/20desktop-profiles_activateDesktopProfiles
@@ -51,7 +51,7 @@ sort_profiles_trap () {
 sort_profiles(){
 
   #make sure we start with empty variables
-  KDEDIRS='';XDG_CONFIG_DIRS='';XDG_DATA_DIRS='';CHOICESPATH='';GNUSTEP_PATHLIST='';UDEDIRS='';PROFILES='';
+  KDEDIRS_NEW='';XDG_CONFIG_DIRS_NEW='';XDG_DATA_DIRS_NEW='';CHOICESPATH_NEW='';GNUSTEP_PATHLIST_NEW='';UDEDIRS_NEW='';PROFILES_NEW='';
  
   # adjust trap to ensure we don't leave any tempfiles behind 
   trap sort_profiles_trap HUP INT TERM;
@@ -78,17 +78,17 @@ sort_profiles(){
   # sort per profile kind
     KIND=`echo "$PROFILE" | cut --fields 2 --delimiter ";"`;
     if (test "$KIND" = "KDE"); then 
-      KDEDIRS="$KDEDIRS $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
+      KDEDIRS_NEW="$KDEDIRS_NEW $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
     elif (test "$KIND" = "XDG_CONFIG"); then 
-      XDG_CONFIG_DIRS="$XDG_CONFIG_DIRS $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
+      XDG_CONFIG_DIRS_NEW="$XDG_CONFIG_DIRS_NEW $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
     elif (test "$KIND" = "XDG_DATA"); then 
-      XDG_DATA_DIRS="$XDG_DATA_DIRS $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
+      XDG_DATA_DIRS_NEW="$XDG_DATA_DIRS_NEW $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
     elif (test "$KIND" = "ROX"); then 
-      CHOICESPATH="$CHOICESPATH $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
+      CHOICESPATH_NEW="$CHOICESPATH_NEW $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
     elif (test "$KIND" = "GNUSTEP"); then 
-      GNUSTEP_PATHLIST="$GNUSTEP_PATHLIST $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
+      GNUSTEP_PATHLIST_NEW="$GNUSTEP_PATHLIST_NEW $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
     elif (test "$KIND" = "UDE"); then 
-      UDEDIRS="$UDEDIRS $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
+      UDEDIRS_NEW="$UDEDIRS_NEW $(echo "$PROFILE" | cut --fields 3 --delimiter ";")";
     elif (test "$KIND" = "GCONF"); then 
       echo "`echo "$PROFILE" | cut --fields 3 --delimiter ";"` " >> $GCONF_FILE;
     fi;	
@@ -104,54 +104,110 @@ sort_profiles(){
 # Functions for activating the different kinds of profile
 ##########################################################
 activate_KDE () {
-  KDEDIRS=`echo "$KDEDIRS" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
-  if (test "$KDEDIRS"x != x) &&
-     (test "$KDEDIRS" != "$(cat $DEFAULT_LISTING | grep "^kde-prefix" | cut --fields 3 --delimiter ";" | sed -e  "s/^ *//" -e "s/ *$//" -e "s/ /:/g")"); then
-    KDEDIRS=$(sh -c "echo $KDEDIRS");# FORCE expansion of variables in KDEDIRS if any
+  KDEDIRS_NEW=`echo "$KDEDIRS_NEW" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  if (test "$KDEDIRS_NEW"x != x) &&
+     (test "$KDEDIRS_NEW" != "$(cat $DEFAULT_LISTING | grep "^kde-prefix" | cut --fields 3 --delimiter ";" | sed -e  "s/^ *//" -e "s/ *$//" -e "s/ /:/g")"); then
+     # set KDEDIRS, handle current value based on active personality
+     if (test "$KDEDIRS"x = x); then
+        KDEDIRS=$(sh -c "echo $KDEDIRS_NEW");# FORCE expansion of variables in KDEDIRS_NEW if any
+     else # we need to check what to do with already set value	
+       case "$PERSONALITY" in
+         autocrat) KDEDIRS=$(sh -c "echo $KDEDIRS_NEW") ;;
+         rude) KDEDIRS=$(sh -c "echo $KDEDIRS_NEW"):$KDEDIRS ;;
+         polite | *) KDEDIRS=$KDEDIRS:$(sh -c "echo $KDEDIRS_NEW") ;;
+       esac;
+     fi;  
     export KDEDIRS;
+  #desktop-profiles is not setting the variable so if we're autcratic enforce that view
+  elif (test "$PERSONALITY" = autocrat); then
+    unset KDEDIRS;
   fi;
 }
 
 activate_XDG_CONFIG () {
-  XDG_CONFIG_DIRS=`echo "$XDG_CONFIG_DIRS" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
-  if (test "$XDG_CONFIG_DIRS"x != x) &&
-     (test "$XDG_CONFIG_DIRS" != "$(cat $DEFAULT_LISTING | grep "^default-xdg_config_dirs" | cut --fields 3 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g")"); then
-    XDG_CONFIG_DIRS=$(sh -c "echo $XDG_CONFIG_DIRS");# FORCE expansion of variables in XDG_CONFIG_DIRS if any
+  XDG_CONFIG_DIRS_NEW=`echo "$XDG_CONFIG_DIRS_NEW" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  if (test "$XDG_CONFIG_DIRS_NEW"x != x) &&
+     (test "$XDG_CONFIG_DIRS_NEW" != "$(cat $DEFAULT_LISTING | grep "^default-xdg_config_dirs" | cut --fields 3 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g")"); then
+     # set XDG_CONFIG_DIRS, handle current value based on active personality
+     if (test "$XDG_CONFIG_DIRS"x = x); then
+       XDG_CONFIG_DIRS=$(sh -c "echo $XDG_CONFIG_DIRS_NEW");# FORCE expansion of variables in XDG_CONFIG_DIRS_NEW if any
+     else
+       case "$PERSONALITY" in
+         autocrat) XDG_CONFIG_DIRS=$(sh -c "echo $XDG_CONFIG_DIRS_NEW") ;;
+         rude) XDG_CONFIG_DIRS=$(sh -c "echo $XDG_CONFIG_DIRS_NEW"):$XDG_CONFIG_DIRS ;;
+         polite | *) XDG_CONFIG_DIRS=$XDG_CONFIG_DIRS:$(sh -c "echo $XDG_CONFIG_DIRS_NEW") ;;
+       esac; 
+     fi;
     export XDG_CONFIG_DIRS;
+  #desktop-profiles is not setting the variable so if we're autcratic enforce that view
+  elif (test "$PERSONALITY" = autocrat); then
+    unset XDG_CONFIG_DIRS;
   fi;
 }
 
 activate_XDG_DATA () {
-  XDG_DATA_DIRS=`echo "$XDG_DATA_DIRS" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
-  if (test "$XDG_DATA_DIRS"x != x) &&
-     (test "$XDG_DATA_DIRS" != "$(cat $DEFAULT_LISTING | grep "^default-xdg_data_dirs" | cut --fields 3 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g")"); then
-    XDG_DATA_DIRS=$(sh -c "echo $XDG_DATA_DIRS");# FORCE expansion of variables in XDG_DATA_DIRS if any
+  XDG_DATA_DIRS_NEW=`echo "$XDG_DATA_DIRS_NEW" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  if (test "$XDG_DATA_DIRS_NEW"x != x) &&
+     (test "$XDG_DATA_DIRS_NEW" != "$(cat $DEFAULT_LISTING | grep "^default-xdg_data_dirs" | cut --fields 3 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g")"); then
+     # set XDG_DATA_DIRS, handle current value based on active personality
+     if (test "$XDG_DATA_DIRS"x = x); then
+       XDG_DATA_DIRS=$(sh -c "echo $XDG_DATA_DIRS_NEW");# FORCE expansion of variables in XDG_DATA_DIRS_NEW if any
+     else
+       case "$PERSONALITY" in
+         autocrat) XDG_DATA_DIRS=$(sh -c "echo $XDG_DATA_DIRS_NEW") ;;
+         rude) XDG_DATA_DIRS=$(sh -c "echo $XDG_DATA_DIRS_NEW"):$XDG_DATA_DIRS ;;
+         polite | *) XDG_DATA_DIRS=$XDG_DATA_DIRS:$(sh -c "echo $XDG_DATA_DIRS_NEW") ;;
+       esac; 
+     fi;
     export XDG_DATA_DIRS;
+  #desktop-profiles is not setting the variable so if we're autcratic enforce that view
+  elif (test "$PERSONALITY" = autocrat); then
+    unset XDG_DATA_DIRS;
   fi;
 }
 
 activate_ROX () {
-  CHOICESPATH=`echo "$CHOICESPATH" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  CHOICESPATH_NEW=`echo "$CHOICESPATH_NEW" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
   DEFAULT_CHOICES=$(cat $DEFAULT_LISTING | grep '^default-rox-system;' | cut --fields 3 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g")
   DEFAULT_CHOICES="$(cat $DEFAULT_LISTING | grep '^default-rox-user;' | cut --fields 3 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"):$DEFAULT_CHOICES"
-  if (test "$CHOICESPATH"x != x) &&
-     (test "$CHOICESPATH" != "$DEFAULT_CHOICES"); then
-    CHOICESPATH=$(sh -c "echo $CHOICESPATH");# FORCE expansion of variables in CHOICESPATH if any
+  if (test "$CHOICESPATH_NEW"x != x) &&
+     (test "$CHOICESPATH_NEW" != "$DEFAULT_CHOICES"); then
+     # set CHOICESPATH, handle current value based on active personality
+     if (test "$CHOICESPATH"x = x); then
+       CHOICESPATH=$(sh -c "echo $CHOICESPATH_NEW");# FORCE expansion of variables in CHOICESPATH_NEW if any
+     else
+       case "$PERSONALITY" in
+         autocrat) CHOICESPATH=$(sh -c "echo $CHOICESPATH_NEW") ;;
+         rude) CHOICESPATH=$(sh -c "echo $CHOICESPATH_NEW"):$CHOICESPATH ;;
+         polite | *) CHOICESPATH=$CHOICESPATH:$(sh -c "echo $CHOICESPATH_NEW") ;;
+       esac; 
+     fi;
     export CHOICESPATH;
+  #desktop-profiles is not setting the variable so if we're autcratic enforce that view
+  elif (test "$PERSONALITY" = autocrat); then
+    unset CHOICESPATH;
   fi;
 }
 
 activate_UDE () {
   # don't s/ /:g/ in next line, UDE doesn't currently support combining profile dirs
-  UDEDIRS=`echo "$UDEDIRS" | sed -e "s/^ *//" -e "s/ *$//"`
-  if (test "$UDEDIRS"x != x) &&
-     (test "$UDEDIRS" != "$(cat $DEFAULT_LISTING | grep "^ude-install-dir" | cut --fields 3 --delimiter ";")"); then
-    # Take first dir and break, as UDE currently only supports one dir
-    for dir in $UDEDIRS; do 
-      UDEdir=$dir;
-      break;
-    done;  
-    export UDEdir=$(sh -c "echo $UDEdir");# FORCE expansion of variables in UDEdir if any
+  UDEDIRS_NEW=`echo "$UDEDIRS_NEW" | sed -e "s/^ *//" -e "s/ *$//"`
+  if (test "$UDEDIRS_NEW"x != x) &&
+     (test "$UDEDIRS_NEW" != "$(cat $DEFAULT_LISTING | grep "^ude-install-dir" | cut --fields 3 --delimiter ";")"); then
+    # UDE currently only supports one dir, so we use the current setting unless
+    # - we're in autocratic or rude mode or
+    # - UDEdir wasn't set up yet and we're in polite mode
+    if ( (test "$PERSONALITY" = autocrat) || (test "$PERSONALITY" = rude) || \
+         ( (test "$PERSONALITY" = polite) && (test "$UDEdir"x = x) ) );then
+      for dir in $UDEDIRS_NEW; do 
+        UDEdir=$dir;
+        break;
+      done;
+      export UDEdir=$(sh -c "echo $UDEdir");# FORCE expansion of variables in UDEdir if any
+    fi;
+  #desktop-profiles is not setting the variable so if we're autcratic enforce that view
+  elif (test "$PERSONALITY" = autocrat); then
+    unset UDEdir;
   fi;
 }
 
@@ -162,8 +218,8 @@ activate_GNUSTEP () {
   export GNUSTEP_NETWORK_ROOT=${GNUSTEP_NETWORK_ROOT:-/usr/local/lib/GNUstep/Network};
   export GNUSTEP_SYSTEM_ROOT=${GNUSTEP_SYSTEM_ROOT:-/usr/lib/GNUstep/System};
 
-  #should be in GNUSTEP_PATHLIST (see /usr/lib/GNUstep/System/Library/Makefiles/GNUstep.sh)
-  GNUSTEP_PATHLIST=`echo "$GNUSTEP_PATHLIST" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  #should be in GNUSTEP_PATHLIST_NEW (see /usr/lib/GNUstep/System/Library/Makefiles/GNUstep.sh)
+  GNUSTEP_PATHLIST_NEW=`echo "$GNUSTEP_PATHLIST_NEW" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
   
   # get default domains
   DEFAULT_DOMAINS=$(cat $DEFAULT_LISTING | grep "^gnustep-user-domain" | cut --fields 3 --delimiter ";" | sed -e  "s/^ *//" -e "s/ *$//" -e "s/ /:/g")
@@ -171,10 +227,23 @@ activate_GNUSTEP () {
   DEFAULT_DOMAINS="$DEFAULT_DOMAINS:$(cat $DEFAULT_LISTING | grep "^gnustep-network-domain" | cut --fields 3 --delimiter ";" | sed -e  "s/^ *//" -e "s/ *$//" -e "s/ /:/g")"
   DEFAULT_DOMAINS="$DEFAULT_DOMAINS:$(cat $DEFAULT_LISTING | grep "^gnustep-system-domain" | cut --fields 3 --delimiter ";" | sed -e  "s/^ *//" -e "s/ *$//" -e "s/ /:/g")"
 
-  if (test "$GNUSTEP_PATHLIST"x != x) &&
-     (test "$GNUSTEP_PATHLIST" != "$DEFAULT_DOMAINS"); then
-    export GNUSTEP_PATHLIST=$(sh -c "echo $GNUSTEP_PATHLIST");# FORCE expansion of variables in GNUSTEP_PATHLIST if any
+  if (test "$GNUSTEP_PATHLIST_NEW"x != x) &&
+     (test "$GNUSTEP_PATHLIST_NEW" != "$DEFAULT_DOMAINS"); then
+     # set GNUSTEP_PATHLIST, handle current value based on active personality
+     if (test "$GNUSTEP_PATHLIST"x = x); then
+       export GNUSTEP_PATHLIST=$(sh -c "echo $GNUSTEP_PATHLIST_NEW");# FORCE expansion of variables in GNUSTEP_PATHLIST_NEW if any
+     else
+       case "$PERSONALITY" in
+         autocrat) export GNUSTEP_PATHLIST=$(sh -c "echo $GNUSTEP_PATHLIST_NEW") ;;
+         rude) export GNUSTEP_PATHLIST=$(sh -c "echo $GNUSTEP_PATHLIST_NEW"):$GNUSTEP_PATHLIST ;;
+         polite | *) export GNUSTEP_PATHLIST=$GNUSTEP_PATHLIST:$(sh -c "echo $GNUSTEP_PATHLIST_NEW") ;;
+       esac; 
+     fi;
   else
+    #desktop-profiles is not setting the variable so if we're autcratic enforce that view
+    if (test "$PERSONALITY" = autocrat); then
+      unset GNUSTEP_PATHLIST;
+    fi;  
     # if we're not setting things, then make sure we've not added to the environment
     if (test "$GNUSTEP_USER_ROOT" = "$(/usr/lib/GNUstep/System/Library/Makefiles/user_home user 2> /dev/null)"); then unset GNUSTEP_USER_ROOT; fi
     if (test "$GNUSTEP_LOCAL_ROOT" = "/usr/local/lib/GNUstep/Local"); then unset GNUSTEP_LOCAL_ROOT; fi
@@ -273,42 +342,66 @@ if (test $INSTALLED = true); then
   if (test -r /etc/default/desktop-profiles); then
     . /etc/default/desktop-profiles;
   fi;  
+  
 
-  #################################################
-  # Make sure the variable we need are initialized
-  #################################################
-  LISTINGS_DIRS=${LISTINGS_DIRS:-'/etc/desktop-profiles'}
-  CACHE_DIR=${CACHE_DIR:-'/var/cache/desktop-profiles'}
-  CACHE_FILE="$CACHE_DIR/activated_profiles"
-  ACTIVE_PROFILE_KINDS=${ACTIVE_PROFILE_KINDS:-''}
-  DEFAULT_LISTING=/etc/desktop-profiles/desktop-profiles.listing
-  PROFILE_PATH_FILES_DIR=${PROFILE_PATH_FILES_DIR:-'/var/cache/desktop-profiles/'}
+  # sheep don't form an opintion, they just follow along
+  # so skip everything if set to be sheep
+  if (test "$PERSONALITY" != sheep); then
 
-  ############################################################
-  # Actual activation of profiles
-  ############################################################
-  if (test -r $CACHE_FILE) &&
-     (test $(ls -t -1 /etc/desktop-profiles/*.listing $CACHE_FILE | head -1) = "$CACHE_FILE"); then
-  # if we have a cache and it's up-to-date -> use it
-    export $(cat $CACHE_FILE);
-  elif (test "$ACTIVE_PROFILE_KINDS"x != "x"); then
-  # else if we have any profile kinds we're interested in, then go 
-  # calculate the profile assignments
-    # add trap to ensure we don't leave any tempfiles behind 
-    trap general_trap HUP INT TERM;
-    # get temp file
-    GCONF_FILE=`tempfile`;
+    #################################################
+    # Make sure the variable we need are initialized
+    #################################################
+    LISTINGS_DIRS=${LISTINGS_DIRS:-'/etc/desktop-profiles'}
+    CACHE_DIR=${CACHE_DIR:-'/var/cache/desktop-profiles'}
+    CACHE_FILE="$CACHE_DIR/activated_profiles"
+    ACTIVE_PROFILE_KINDS=${ACTIVE_PROFILE_KINDS:-''}
+    DEFAULT_LISTING=/etc/desktop-profiles/desktop-profiles.listing
+    PROFILE_PATH_FILES_DIR=${PROFILE_PATH_FILES_DIR:-'/var/cache/desktop-profiles/'}
 
-    # sort the profiles, whose requirements are met into:
-    # - the appropriate environment variables
-    # - $GCONF_FILE
-    sort_profiles; 
+    ############################################################
+    # Actual activation of profiles
+    ############################################################
+    if (test -r "$CACHE_FILE") &&
+       (test $(ls -t -1 /etc/desktop-profiles/*.listing \
+                        /etc/default/desktop-profiles \
+                        "$CACHE_FILE" 2> /dev/null | \
+	       head -1) = "$CACHE_FILE"); then
+    # if we have a cache and it's up-to-date -> use it
+      # save UDEdir contents, as we might need it, then unset that var
+      UDEdir_current=$UDEdir; unset UDEdir;
+  
+      # read the cache, replacing markers with variables contents when present
+      export $(cat "$CACHE_FILE" | sed -e "s|\\\$KDEDIRS|$KDEDIRS|" \
+                            -e "s|\\\$XDG_CONFIG_DIRS|$XDG_CONFIG_DIRS|" \
+                            -e "s|\\\$XDG_DATA_DIRS|$XDG_DATA_DIRS|" \
+                            -e "s|\\\$CHOICESPATH|$CHOICESPATH|" \
+                            -e "s|\\\$GNUSTEP_PATHLIST|$GNUSTEP_PATHLIST|");
+    
+      # set UDEdir based on cache content, personality type and current value
+      case "$PERSONALITY" in 
+        autocrat) ;; #leave as defined in cache 
+        rude) if(test "$UDEdir"x = x);then export UDEdir="$UDEdir_current";fi ;;
+        polite | *) export UDEdir="$UDEdir_current" ;;
+      esac;  
+    elif (test "$ACTIVE_PROFILE_KINDS"x != "x"); then
+    # else if we have any profile kinds we're interested in, then go 
+    # calculate the profile assignments
+      # add trap to ensure we don't leave any tempfiles behind 
+      trap general_trap HUP INT TERM;
+      # get temp file
+      GCONF_FILE=`tempfile`;
+  
+      # sort the profiles, whose requirements are met into:
+      # - the appropriate environment variables
+      # - $GCONF_FILE
+      sort_profiles; 
 
-    # activate the profiles of the active kinds
-    for KIND in $ACTIVE_PROFILE_KINDS; do
-      # || true is to avoid hanging x-startup when trying a non-existing KIND
-      # which can happen e.g. due to typo's in the config file.
-      activate_$KIND || true;
-    done;
-  fi; # end dynamic profile assignment
+      # activate the profiles of the active kinds
+      for KIND in $ACTIVE_PROFILE_KINDS; do
+        # || true is to avoid hanging x-startup when trying a non-existing KIND
+        # which can happen e.g. due to typo's in the config file.
+        activate_$KIND || true;
+      done;
+    fi; # end dynamic profile assignment
+  fi;# end !sheep  
 fi;  
diff --git a/TODO b/TODO
index 0283e98..29923f1 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,3 @@
+- adapt manpage to reflect PERSONALITY setting
 - further improve performance (cache in non-simple case?)
-- option to not ignore already existing values of the various values
 - build usefull (example) profiles and point to them in docu (for accessibility?)
diff --git a/desktop-profiles b/desktop-profiles
index a4d4194..77be19d 100644
--- a/desktop-profiles
+++ b/desktop-profiles
@@ -17,6 +17,20 @@ LISTINGS_DIRS="/etc/desktop-profiles"
 # (cache is only generated when that makes sense)
 CACHE_DIR="/var/cache/desktop-profiles"
 
+# This determines how the desktop-profiles agent script deals with the 
+# situation where the environment are already set by some other agent:
+# - autocrat: assume desktop-profiles is the only actor allowed to touch 
+#             the environment variables and ignore current setting of the
+#             environment variables (this is also known as BOFH mode)
+# - rude    : profiles activated by desktop-profiles take precedence over 
+#             those already set in the environment variables
+# - polite  : profiles activated by desktop-profiles give precedence to those 
+#             already set in the environment variables
+#             (allows user to override desktop-profiles)
+# - sheep   : always follow the set environment variables 
+#             (i.e. don't do anything, essentially deactivates desktop-profiles)            
+PERSONALITY=polite
+
 #################################
 # SETTINGS FOR xsession.d script
 #################################
diff --git a/update-profile-cache b/update-profile-cache
index 72500a4..4e162c0 100755
--- a/update-profile-cache
+++ b/update-profile-cache
@@ -40,44 +40,77 @@
 #######################
 # generate $CACHE_FILE
 #######################
-  if (test $CACHE_TYPE = static); then
+  if (test "$CACHE_TYPE" = static); then
     #if:
     # - cache doesn't exist yet
     # - last modification time of any metadata file is newer then of the cache
-    if !(test -e $CACHE_FILE) ||
-       !(test $(ls -t -1 /etc/desktop-profiles/*.listing $CACHE_FILE | head -1) = "$CACHE_FILE"); then
+    if !(test -e "$CACHE_FILE") ||
+       !(test $(ls -t -1 /etc/desktop-profiles/*.listing \
+                         /etc/default/desktop-profiles \
+			 "$CACHE_FILE" 2> /dev/null | \
+	        head -1) = "$CACHE_FILE"); then
 
       # delete old cache (otherwise activateDesktopProfiles reuses it)
-      rm -f $CACHE_FILE;
+      rm -f "$CACHE_FILE";
 
-      # regenerate the cache
+      # regenerate the cache, making sure we only use the metadata files,
+      # adding contents of set variables is done when using the cache 
+      KDEDIRS='';XDG_CONFIG_DIRS='';XDG_DATA_DIRS='';CHOICESPATH='';
+      GNUSTEP_PATHLIST='';UDEdir='';
       . /etc/X11/Xsession.d/20desktop-profiles_activateDesktopProfiles;
 
       # move generated path files to cache dir, and set env vars accordingly
       if (test -e "$MANDATORY_PATH" ); then
         # sanity check
-        mkdir -p $CACHE_DIR;
+        mkdir -p "$CACHE_DIR";
 	
 	#do it with cat+rm instead of mv to ensure correct permissions
-        cat $MANDATORY_PATH > $CACHE_DIR/mandatory_path;
-	rm $MANDATORY_PATH;
-	MANDATORY_PATH=$CACHE_DIR/mandatory_path;
+        cat "$MANDATORY_PATH" > "$CACHE_DIR/mandatory_path";
+	rm -f "$MANDATORY_PATH";
+	MANDATORY_PATH="$CACHE_DIR/mandatory_path";
       fi;
       if (test -e "$DEFAULTS_PATH" ); then
         #sanity check
-	mkdir -p $CACHE_DIR;
+	mkdir -p "$CACHE_DIR";
 	
 	#do it with cat+rm instead of mv to ensure correct permissions
-        cat $DEFAULTS_PATH > $CACHE_DIR/defaults.path;
-	rm $DEFAULTS_PATH;
-	DEFAULTS_PATH=$CACHE_DIR/defaults.path;
+        cat "$DEFAULTS_PATH" > "$CACHE_DIR/defaults.path";
+	rm -f "$DEFAULTS_PATH";
+	DEFAULTS_PATH="$CACHE_DIR/defaults.path";
       fi;	
 
       # fill $CACHE_FILE
-      mkdir -p $CACHE_DIR;
-      env | grep 'KDEDIRS\|XDG_CONFIG_DIRS\|XDG_DATA_DIRS\|CHOICESPATH\|UDEdir\|GNUSTEP_PATHLIST\|MANDATORY_PATH\|DEFAULTS_PATH' > $CACHE_FILE;
+      mkdir -p "$CACHE_DIR";
+      env | grep 'KDEDIRS\|XDG_CONFIG_DIRS\|XDG_DATA_DIRS\|CHOICESPATH\|UDEdir\|GNUSTEP_PATHLIST\|MANDATORY_PATH\|DEFAULTS_PATH' > "$CACHE_FILE";
+
+      # Add markers for env variables according to personality type
+      case "$PERSONALITY" in 
+	rude) 
+	  sed -i -e 's/^\(KDEDIRS=.*\)$/\1:$KDEDIRS/' \
+	   -e 's/^\(XDG_CONFIG_DIRS=.*\)$/\1:$XDG_CONFIG_DIRS/' \
+	   -e 's/^\(XDG_DATA_DIRS=.*\)$/\1:$XDG_DATA_DIRS/' \
+	   -e 's/^\(CHOICESPATH=.*\)$/\1:$CHOICESPATH/' \
+	   -e 's/^\(GNUSTEP_PATHLIST=.*\)$/\1:$GNUSTEP_PATHLIST/' \
+	   "$CACHE_FILE";
+	  #UDEdir handled in Xsession.d script as this is a single dir instead of a list
+	;;
+
+	sheep | autocrat) 
+          #no markers to add
+	;; 
+
+        polite | *) 
+	  sed -i -e 's/^\(KDEDIRS=\)\(.*\)$/\1$KDEDIRS:\2/' \
+	   -e 's/^\(XDG_CONFIG_DIRS=\)\(.*\)$/\1$XDG_CONFIG_DIRS:\2/' \
+	   -e 's/^\(XDG_DATA_DIRS=\)\(.*\)$/\1$XDG_DATA_DIRS:\2/' \
+	   -e 's/^\(CHOICESPATH=\)\(.*\)$/\1$CHOICESPATH:\2/' \
+	   -e 's/^\(GNUSTEP_PATHLIST=\)\(.*\)$/\1$GNUSTEP_PATHLIST:\2/' \
+	   "$CACHE_FILE";
+	  #UDEdir handled in Xsession.d script as this is a single dir instead of a list
+	;;	
+      esac;	
     fi;  
   else
     # we don't want to use the cache so make sure no old one is left behind  
-    rm -f $CACHE_FILE;
+    rm -f "$CACHE_FILE";
   fi;  

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-edu/pkg-team/desktop-profiles.git



More information about the debian-edu-commits mailing list