[debian-edu-commits] debian-edu/ 74/183: Renamed conversion script to something more sane Added man page for conversion script, and point to it in the desktop-profiles man page

Alexander Alemayhu ccscanf-guest at moszumanska.debian.org
Wed Jun 11 16:48:35 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 e1297178b1fe9d0b293419ef2f69603d297e3995
Author: Bart Cornelis <cobaco at linux.be>
Date:   Thu Jul 28 12:10:02 2005 +0000

    Renamed conversion script to something more sane
    Added man page for conversion script, and point to
    it in the desktop-profiles man page
---
 desktop-profiles.7 |   2 +-
 path2listing       | 333 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 path2listing.1     |  51 ++++++++
 3 files changed, 385 insertions(+), 1 deletion(-)

diff --git a/desktop-profiles.7 b/desktop-profiles.7
index e2cb4cd..d1fd3a1 100644
--- a/desktop-profiles.7
+++ b/desktop-profiles.7
@@ -159,4 +159,4 @@ Each configuration source is structured like a simple hierarchical file system a
 This manual page was written by Bart Cornelis <cobaco at skolelinux.no>.
 
 .SH SEE ALSO
-list-desktop-profiles(1), profile-manager(1), dh_installlisting(1)
+list-desktop-profiles(1), profile-manager(1), dh_installlisting(1), path2listing(1)
diff --git a/path2listing b/path2listing
new file mode 100644
index 0000000..9b5fb77
--- /dev/null
+++ b/path2listing
@@ -0,0 +1,333 @@
+#! /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 <cobaco AT skolelinux no>
+#########################################################################
+
+ROOT_PATH_FILE=/etc/gconf/2/path
+CUSTOM_LISTINGS=/etc/desktop-profiles/path2listing_generated.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;
+
+print_help () {
+cat <<EOF
+Usage: path2listing [OPTIONS]
+  This script facilitates the conversion from:
+  - managing gconf configuration sources directly through path files,
+  - to managing them with the desktop-profiles package
+  and will thus generaly be run only once directly after installing
+  desktop-profiles
+
+  It will generate the metadata (listing file) needed by desktop-profiles to
+  manage the configuration sources that are activated directly or indirectly
+  (i.e. through included path files) by the path file it is run on. 
+
+  After the generation of the metadata the converted path file will be
+  replaced by one assuming that desktop-profiles manages activation of
+  configuration sources (unless you tell it not to).
+
+Options:
+  -d, --distance   : precedence distance between different configuration
+                     sources (defaults to $SOURCE_DISTANCE), 
+		     The idea is to leave some space between precedences so you
+		     can easily insert other configuration sources later on.
+  -f, --file       : path file to start conversion from 
+                     (defaults to $ROOT_PATH_FILE)
+  -o, --output-file: file to put the generated metadata in (defaults to 
+                     $CUSTOM_LISTINGS)
+  --no-replace-file: don't replace path file from which we start the conversion
+                     with one that manages everything through desktop-profiles
+  -h, --help    : display this helpmessage
+EOF
+}
+
+# $1 is the path file to look at
+# output is the reverse-priority ordered list of configuration sources that $1
+# contains (directly, or indirectly through nested include directives). The 
+# output will ignore the hooks for desktop-profiles if present (as we don't 
+# need to generate any metadata for them).
+#
+# Note: not recursing down includes referring to environment variables as we 
+#       can't be sure they'll resolve the same way when converting, and when
+#       running as $random_user, keep them as includes
+# Note: also don't recurse down includes referring to $(HOME) or $(USER), as
+#       those are likely user-controlled, keeping as includes
+#############################################################################
+list_sources_in_path_file () {
+  # if it's an existing file, process it, otherwise ignore it
+  if (test -r "$1"); then
+    # strip out comments & empty lines, leave only config sources and includes
+    tac "$1" | sed -e "s/^[[:space:]]*//g" -e "s/[[:space:]]*$//g" | \
+    grep -v "^#.*\|^$" | while read CONFIG_SOURCE; do
+      # ignore desktop-profiles hooks (new and old) as they don't need metadata
+      if ( (test "$CONFIG_SOURCE" = 'include $(ENV_MANDATORY_PATH)') ||
+          (test "$CONFIG_SOURCE" = 'include *\$(ENV_DEFAULTS_PATH)') ||
+          (test "$CONFIG_SOURCE" = 'include /var/cache/desktop-profiles/\$(USER)_mandatory.path') ||
+          (test "$CONFIG_SOURCE" = 'include /var/cache/desktop-profiles/\$(USER)_defaults.path') ); then
+	true;  
+      # process nested path files
+      elif (echo "$CONFIG_SOURCE" | grep "^include[[:space:]]*" > /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 
+    declare -i mandatory_number="$(cat "$3" | grep '^mandatory' | wc -l) + 1";
+    declare -i default_number="$(cat "$3" | grep '^default' | wc -l) + 1";
+  else 
+    declare -i mandatory_number=1;
+    declare -i default_number=1;
+  fi;  
+  
+  if (test 0 -lt $2 ); then
+    echo "mandatory_$mandatory_number;GCONF;$1;$2;;" >> "$3";
+  else   
+    echo "default_$default_number;GCONF;$1;$2;;" >> "$3";
+  fi;  
+}
+
+# $1 is the configuration source whose metadata we want to update
+# $2 is the new precedence value
+# $3 is the file where the configuration sources' metadata is to be found
+update_precedence () {
+  if (test -w "$3"); then
+    sed -i "s|\(.*\);GCONF;$1;.*;\(.*\);\(.*\)|\1;GCONF;$1;$2;\2;\3|" "$3";
+  else
+    echo "Don't have sufficient permissions to adapt the precedence of $1 in $3 to $2";
+  fi;  
+}
+
+# $1 is the configuration source of the profile we want to deactivate
+# $2 is the file where the configuration sources' metadata is to be found
+set_inactive () {
+  sed -i "s|\(.*\);GCONF;$1;\(.*\);\(.*\);\(.*\)|\1;GCONF;$1;\2;! \3;\4|" "$2";
+}
+
+# $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;  
+}
+
+# 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;
+
+#####################
+# 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 same as path file we want
+  if (diff $ROOT_PATH_FILE /usr/share/desktop-profiles/path 2>&1 > /dev/null); then
+    #same -> 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);
+
+  # flags indicating wether we've encountered the default sources yet puth in
+  # tempfile, as we need to change them from within a pipe, which means subshell,
+  # which means setting a variable doesn't carry outside of loop
+  export AID_TMP=$(tempfile);
+  echo SEEN_GCONF_MANDATORY="false" >> "$AID_TMP";
+  echo SEEN_GCONF_DEFAULTS="false" >> "$AID_TMP";
+  echo SEEN_GCONF_USER_PATH="false" >> "$AID_TMP";
+  echo SEEN_GCONF_USER="false" >> "$AID_TMP";
+
+  # check if file, we'll be messing with already exists, if so create backup
+  make_backup_of "$CUSTOM_LISTINGS" regenerate
+
+  # iterate over all confguration 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
+    declare -i PRECEDENCE="$(echo "$ITEM" | cut --fields 1) * $SOURCE_DISTANCE - $USER_SOURCE_RANK * $SOURCE_DISTANCE";
+    CONFIG_SOURCE="$(echo "$ITEM" | cut --fields 2)";
+
+    # If one of the default source -> update precedence
+    # else add a profile-metadata entry for this configuration source
+    if (test "$CONFIG_SOURCE" = "xml:readonly:/etc/gconf/gconf.xml.mandatory") ; then
+      echo 'SEEN_GCONF_MANDATORY="true"' >> "$AID_TMP";
+      update_precedence "$CONFIG_SOURCE" "$PRECEDENCE" "$DEFAULT_LISTINGS";
+    elif (test "$CONFIG_SOURCE" = 'include "$(HOME)/.gconf.path"'); then
+      echo 'SEEN_GCONF_USER_PATH="true"' >> "$AID_TMP";
+      update_precedence "$CONFIG_SOURCE" "$PRECEDENCE" "$DEFAULT_LISTINGS";
+    elif (test "$CONFIG_SOURCE" = 'xml:readwrite:$(HOME)/.gconf'); then
+      echo 'SEEN_GCONF_USER="true"' >> "$AID_TMP";
+      update_precedence "$CONFIG_SOURCE" "$PRECEDENCE" "$DEFAULT_LISTINGS";
+    elif (test "$CONFIG_SOURCE" = "xml:readonly:/etc/gconf/gconf.xml.defaults"); then
+      echo 'SEEN_GCONF_DEFAULTS="true"' >> "$AID_TMP";
+      update_precedence "$CONFIG_SOURCE" "$PRECEDENCE" "$DEFAULT_LISTINGS";
+    else  
+      add_as_profile "$CONFIG_SOURCE" "$PRECEDENCE" "$CUSTOM_LISTINGS";
+    fi;  
+  done;
+
+  # Activate/Deactivate default sources as requiered
+  # If and only if, we're processing the global path file
+  if (test "$GLOBAL_PATH_FILE" = true); then
+    # deactivate any of the default configuration sources we didn't encounter
+    . "$AID_TMP";#get seen flags
+    if (test "$SEEN_GCONF_MANDATORY" = false) || (test "$SEEN_GCONF_USER_PATH" = false) ||
+       (test "$SEEN_GCONF_USER" = false) || (test "$SEEN_GCONF_DEFAULTS" = false); then     
+      make_backup_of "$DEFAULT_LISTING" "make changes to"
+    fi;
+
+    if (test "$SEEN_GCONF_MANDATORY" = false); then
+      set_inactive "xml:readonly:/etc/gconf/gconf.xml.mandatory" "$DEFAULT_LISTINGS";
+    fi;
+    if (test "$SEEN_GCONF_USER_PATH" = false); then
+      set_inactive 'include "$(HOME)/.gconf.path"' "$DEFAULT_LISTINGS";
+    fi;
+    if (test "$SEEN_GCONF_USER" = false); then
+      set_inactive 'xml:readwrite:$(HOME)/.gconf' "$DEFAULT_LISTINGS";
+    fi;
+    if (test "$SEEN_GCONF_DEFAULTS" = false); then
+      set_inactive "xml:readonly:/etc/gconf/gconf.xml.defaults" "$DEFAULT_LISTINGS";
+    fi;
+  fi;  
+
+  # cleanup
+  rm "$AID_TMP";
+  unset AID_TMP;
+
+######################################
+# 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;  
diff --git a/path2listing.1 b/path2listing.1
new file mode 100644
index 0000000..37ccb5d
--- /dev/null
+++ b/path2listing.1
@@ -0,0 +1,51 @@
+.TH PATH2LISTING 1 "May 07, 2005" "desktop-profiles"
+
+.SH NAME
+path2listing \- script facilitating the conversion to managing gconf configuration sources with desktop-profiles
+
+.SH SYNOPSIS
+path2listing [options]
+
+.SH DESCRIPTION
+This script will generate the metadata (.listing file) needed by desktop-profiles to manage the configuration sources activated (directly or indirectly through included path files) by the path file it is called on (which is the global one by default). 
+.PP
+In addition to generating the necessary metadata the script 
+will also replace the converted path file by one that assumes
+that desktop-profiles manages the activation of all configuration sources (unless you tell it not to off course).
+.PP
+NOTE: a backup copy will be made of all files that are changed
+
+.SH OPTIONS
+.PP
+-d,--distance
+.IP
+distance between the precedence values of each successive pair of configuration sources (defaults to 50), the idea being that you leave some space to insert future sources.
+.PP
+-f, --file
+.IP
+path file to convert (defaults to /etc/gconf/2/path)
+.PP
+-h, --help
+.IP
+display the help message
+.PP
+-o, --output-file
+.IP
+file to put the generated metadata in (defaults to /etc/desktop-profiles/path2listing_generated.listing). If this file exists a backup copy will be made prior to overwriting it.
+.PP
+--no-replace-file
+.IP
+don't replace the path file we're converted with one assuming desktop-profiles manages activation
+
+.SH FILES
+/etc/gconf/2/path - systemwide gconf path file, default path file to convert
+.PP
+/etc/desktop-profiles/path2listing_generated.listing - default name for the file containing the generated metadata
+
+
+.SH AUTHOR
+This manual page was written by Bart Cornelis <cobaco at skolelinux.no>.
+.PP
+
+.SH SEE ALSO
+desktop-profiles(7)

-- 
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