#!/bin/sh # This script is ment to allow you to setup gconf to manage confiuration # sources through desktop-profiles. # # It will read your a path file (the global gconf one by default) and will: # - generate the necessary metadata to manage all profiles through # desktop-profiles # - adapt the global path file to manage all configuration sources with # desktop-profiles (unless told not to) # # (c) 2005 Bart Cornelis ######################################################################### ROOT_PATH_FILE=/etc/gconf/2/path CUSTOM_LISTINGS=/etc/desktop-profiles/desktop-profiles_path2listing.listing DEFAULT_LISTINGS=/etc/desktop-profiles/desktop-profiles.listing # default distance to leave between 2 successive priority sources # we're leaving some distance to allow the easy insertion of later profiles SOURCE_DISTANCE=50; # we're processing the global path file by default # -> so unless asked not to we'll want to replace it GLOBAL_PATH_FILE=true; REPLACE_PATH_FILE=true; print_help () { cat < /dev/null); then # check if recursing makes sense (don't recurse when user-controlled or # dependend on current environment (which might be influenced by user) if (echo "$CONFIG_SOURCE" | grep -e "\$(HOME)" -e "\$(USER)" -e "\$(ENV_.*)" > /dev/null); then echo "$CONFIG_SOURCE"; else list_sources_in_path_file $(echo "$CONFIG_SOURCE" | sed "s/^include[[:space:]]*//"); fi; # process regular config sources else echo $CONFIG_SOURCE; fi; done; fi; } # $1 is the confiuration source that makes up the new profile # $2 is the precedence value # $3 is the file where it should be added into add_as_profile () { if (test -r "$3"); then mandatory_number="$(expr $(cat "$3" | grep '^mandatory' | wc -l) + 1)"; default_number="$(expr $(cat "$3" | grep '^default' | wc -l) + 1)"; else mandatory_number=1; default_number=1; fi; if (test 0 -lt "$2"); then echo "mandatory_$mandatory_number;GCONF;$1;$2;;" >> "$3"; elif (test 0 -gt "$2");then echo "default_$default_number;GCONF;$1;$2;;" >> "$3"; else echo "gconf-user-settings;GCONF;$1;$2;;Default location of user settings" >> $3; fi; } # $1 is the file to backup # $2 is the reason make_backup_of () { if (test -e "$1"); then # tell user what we're doing echo "$1 already exists, and this script wil $2 it." echo "-> a backup of named $1.$(date --iso-8601=seconds) will be created." echo ; # make backup of current version mv "$1" "$1.$(date --iso-8601=seconds)"; fi; } ##################### # Parse command line ##################### while test $# -ge 1; do case $1 in -d | --distance) # takes positive integer as distance (between configuration sources) if (test $# -lt 2) || !(echo "$2" | grep -E '^[0-9]+$' > /dev/null); then print_help; exit; else # valid distance -> set it SOURCE_DISTANCE="$2"; fi; shift 2; ;; # takes path file to be converted as argument -f | --file) #validate argument, should be a readable path file if (test $# -lt 2) || !(test -r $2); then print_help; exit; else #valid filename -> add to list of files to convert ROOT_PATH_FILE="$2"; if (test "$ROOT_PATH_FILE" != /etc/gconf/2/path) || \ (test "$ROOT_PATH_FILE" != /etc/gconf/1/path); then GLOBAL_PATH_FILE=false; fi; fi; shift 2; ;; # takes name of file that will contain the metada for the # converted configuration sources -o | --output-file) #check for argument if (test $# -lt 2); then print_help; exit; else #Change name of metadata file accordingly CUSTOM_LISTINGS="$2"; fi; shift 2; ;; # takes boolean value --no-replace-file) REPLACE_PATH_FILE=false; shift; ;; -h| --help | *) print_help; exit; ;; esac; done; ###################################### # Check if we need to do anything, # and communicate that with the admin ###################################### # Check if ROOT_PATH_FILE is equal to ideal path file state if (diff $ROOT_PATH_FILE /usr/share/desktop-profiles/path 2>&1 > /dev/null); then #equal -> nothing to do echo "$ROOT_PATH_FILE file is already converted to desktop-profiles:"; echo " -> nothing to do"; echo " -> exiting"; exit; # check for precense of current desktop-profiles hooks # if so warn that the precedence might not be correct # they're different -> so we need to convert elif (grep 'include *\$(ENV_MANDATORY_PATH)' "$ROOT_PATH_FILE" 2>&1 > /dev/null) || (grep 'include *\$(ENV_DEFAULTS_PATH)' "$ROOT_PATH_FILE" 2>&1 > /dev/null); then true;#FIXME; # check for precense of old desktop-profiles hooks # if so warn that the precedence might not be correct # they're different -> so we need to convert elif (grep 'include /var/cache/desktop-profiles/\$(USER)_mandatory.path' "$ROOT_PATH_FILE" 2>&1 > /dev/null) || (grep 'include /var/cache/desktop-profiles/\$(USER)_defaults.path' "$ROOT_PATH_FILE" 2>&1 > /dev/null); then true;#FIXME; else echo "Metadata for all configuration sources contained in $ROOT_PATH_FILE"; echo "(wether contained directly, or indirectly through includes) will be" echo "generated and put in $CUSTOM_LISTINGS." echo; fi; ################################ # Deal with generating metadata ################################ USER_SOURCE_RANK=$(list_sources_in_path_file $ROOT_PATH_FILE | nl | \ grep 'xml:readwrite:\$(HOME)/.gconf' | sed "s/^[[:space:]]*//g" | cut --fields 1); # check if file, we'll be messing with already exists, if so create backup make_backup_of "$CUSTOM_LISTINGS" regenerate # iterate over all configuration sources, listed directly or indirectly by the # $ROOT_PATH_FILE (by default = /etc/gconf/2/path) list_sources_in_path_file $ROOT_PATH_FILE | nl | sed "s/^[[:space:]]*//g" | \ while read ITEM; do # the '- USER_SOURCE_RANK * SOURCE_DISTANCE' at the end is to ensure that # the user-source ends up with precedence 0, yielding all mandatory sources # with a positive precedence, and all default sources with a negative one PRECEDENCE="$(expr $(echo "$ITEM" | cut --fields 1) \* $SOURCE_DISTANCE - $USER_SOURCE_RANK \* $SOURCE_DISTANCE)"; CONFIG_SOURCE="$(echo "$ITEM" | cut --fields 2)"; # add a profile-metadata entry for this configuration source add_as_profile "$CONFIG_SOURCE" "$PRECEDENCE" "$CUSTOM_LISTINGS"; done; ###################################### # Deal with changing global path file ###################################### if (test $REPLACE_PATH_FILE = true); then # make backup-copy of $ROOT_PATH_FILE, before changing it if (test -e "$ROOT_PATH_FILE"); then # tell user what we're doing echo "The global path file will now be replaced with one assuming all " echo "configuration sources are managed by desktop-profiles." echo "-> a backup named $ROOT_PATH_FILE.$(date --iso-8601=seconds) will be created." echo ; # make backup of current version mv "$ROOT_PATH_FILE" "$ROOT_PATH_FILE.$(date --iso-8601=seconds)"; fi; # actually replace global path file cp /usr/share/desktop-profiles/path "$ROOT_PATH_FILE"; fi;