#!/bin/sh # # This script checks whether generating a cache of the wanted profile # assignment makes sense, and if so (re)generate the cache if it's out of date # # Supported CACHE_TYPES: # - static: used when profiles are either activated machine-wide or not at all # - none: used when we either don't want or don't support a cache # TODO: caching in the non-static case ############################################################################### ################# # initialization ################# # get user preferences if (test -r /etc/default/desktop-profiles); then . /etc/default/desktop-profiles; fi; #failsave in case default file is deleted LISTINGS_DIRS=${LISTINGS_DIRS:-'/etc/desktop-profiles'} CACHE_DIR=${CACHE_DIR:-'/var/cache/desktop-profiles'} CACHE_FILE="$CACHE_DIR/activated_profiles" ############################################## # Check wether generating a cache makes sense ############################################## # if is true when there's at least 1 non-deactivated profile with a # group or command requirment # (a group or command requirement means at least 1 character in the # requirement that's neither whitespace nor '!') if( test $(list-desktop-profiles -e '$REQUIREMENTS' -r '[^[:space:]!]' | \ grep -v '^![[:space:]]\|[[:space:]]!$\|[[:space:]]![[:space:]]\|^!$' | \ wc -l) -ne 0); then CACHE_TYPE=none; else CACHE_TYPE=static fi; ########################################### # generate $CACHE_FILE if that makes sense ########################################### if (test "$CACHE_TYPE" = static); then #if: # - cache doesn't exist yet or # - last modification time of any metadata file is newer then the cache 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"; # make sure we only use the metadata files KDEDIRS='';XDG_CONFIG_DIRS='';XDG_DATA_DIRS='';CHOICESPATH=''; GNUSTEP_PATHLIST='';UDEdir=''; # generate profile settings . /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"; #do it with cat+rm instead of mv to ensure correct permissions 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"; #do it with cat+rm instead of mv to ensure correct permissions cat "$DEFAULTS_PATH" > "$CACHE_DIR/defaults.path"; rm -f "$DEFAULTS_PATH"; DEFAULTS_PATH="$CACHE_DIR/defaults.path"; fi; # save profile settings to $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 # markers will be filled in at X-start 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/' \ -e 's/^\(UDEdir=.*\)$/\1:$UDEdir/' \ "$CACHE_FILE"; ;; 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/' \ -e 's/^\(UDEdir=\)\(.*\)$/\1$UDEdir:\2/' \ "$CACHE_FILE"; ;; esac; fi; # end static cache generation else # we don't want to use the cache so make sure no old one is left behind rm -f "$CACHE_FILE"; fi;