[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

X Strike Force SVN commit: rev 516 - trunk/debian



Author: branden
Date: 2003-09-12 13:39:54 -0500 (Fri, 12 Sep 2003)
New Revision: 516

Modified:
   trunk/debian/changelog
   trunk/debian/xserver-common.config.in
   trunk/debian/xserver-common.postinst.in
   trunk/debian/xserver-common.preinst.in
Log:
Robustify xserver-common maintainer scripts.
- debian/xserver-common.{config,preinst,postinst}.in:
  + convert informational messages to debugging messages
  + add debugging messages for tracing of various operations
  + wrap bare db_* commands with safe_debconf()
- debian/xserver-common.config.in:
  + stop using debconf as a registry; attempt to read variable settings
    from /etc/X11/Xwrapper.config back into the debconf database
  + allowed_users_english_to_actual(),allowed_users_actual_to_english():
    new functions to covert from debconf question terminology to config
    file terminology
  + validate_nice_value():
    + renamed from checkval()
    + use return code to indicate validity instead of $VALID
    + if upgrading from xserver-common prior to 4.0.1-6, scan old wrapper                                                                                                     config file /etc/X11/Xserver for a default setting of allowed users
- debian/xserver-common.preinst.in:
  + stop displacing /etc/X11/Xserver on upgrades from << 4.1.0-6


Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2003-09-12 17:43:58 UTC (rev 515)
+++ trunk/debian/changelog	2003-09-12 18:39:54 UTC (rev 516)
@@ -156,6 +156,25 @@
     - debian/xfree86-common.postrm.in:
       + use $THIS_PACKAGE to drive call to update-rc.d
 
+  * Robustify xserver-common maintainer scripts.
+    - debian/xserver-common.{config,preinst,postinst}.in:
+      + convert informational messages to debugging messages
+      + add debugging messages for tracing of various operations
+      + wrap bare db_* commands with safe_debconf()
+    - debian/xserver-common.config.in:
+      + stop using debconf as a registry; attempt to read variable settings
+        from /etc/X11/Xwrapper.config back into the debconf database
+      + allowed_users_english_to_actual(),allowed_users_actual_to_english():
+        new functions to covert from debconf question terminology to config
+        file terminology
+      + validate_nice_value():
+        + renamed from checkval()
+        + use return code to indicate validity instead of $VALID
+        + if upgrading from xserver-common prior to 4.0.1-6, scan old wrapper
+          config file /etc/X11/Xserver for a default setting of allowed users
+    - debian/xserver-common.preinst.in:
+      + stop displacing /etc/X11/Xserver on upgrades from << 4.1.0-6
+
  -- Branden Robinson <branden@debian.org>  Fri, 12 Sep 2003 12:43:00 -0500
 
 xfree86 (4.2.1-11) unstable; urgency=medium

Modified: trunk/debian/xserver-common.config.in
===================================================================
--- trunk/debian/xserver-common.config.in	2003-09-12 17:43:58 UTC (rev 515)
+++ trunk/debian/xserver-common.config.in	2003-09-12 18:39:54 UTC (rev 516)
@@ -16,6 +16,68 @@
 
 #INCLUDE_SHELL_LIB#
 
+XWRAPPER_CONFIG=/etc/X11/Xwrapper.config
+OLD_CONFIG_FILE=/etc/X11/Xserver
+
+allowed_users_english_to_actual () {
+  case "$1" in
+    "Root Only")
+      echo "rootonly"
+      ;;
+    "Console Users Only")
+      echo "console"
+      ;;
+    "Anybody")
+      echo "anybody"
+      ;;
+    *)
+      # garbage input; return default
+      debugmsg "allowed_users_english_to_actual(): unrecognized input \"$1\";" \
+               "using default"
+      echo "console"
+      ;;
+  esac
+}
+
+allowed_users_actual_to_english () {
+  case "$1" in
+    "rootonly")
+      echo "Root Only"
+      ;;
+    "console")
+      echo "Console Users Only"
+      ;;
+    "anybody")
+      echo "Anybody"
+      ;;
+    *)
+      # garbage input; return default
+      debugmsg "allowed_users_actual_to_english(): unrecognized input \"$1\";" \
+               "using default"
+      echo "Console Users Only"
+      ;;
+  esac
+}
+
+validate_nice_value () {
+  local retval
+
+  retval=1
+  # first, try to subtract number from itself to validate numeric input
+  # (expr is noisy, always throw away its output)
+  set +e
+  expr "$1" - "$1" > /dev/null 2>&1
+  if [ $? != 2 ]; then
+    # now check for valid range
+    if expr "$1" ">=" "-20" > /dev/null 2>&1 &&
+       expr "$1" "<=" "19" > /dev/null 2>&1; then
+       retval=0
+    fi
+  fi
+  set -e
+  return $retval
+}
+
 # set the default nice value based on what Linux kernel version is being used;
 # the new process scheduler in 2.5, to be released in 2.6, makes a default of
 # -10 a bad idea; with that scheduler, the X server should run with priority 0
@@ -25,78 +87,92 @@
   LINUX_KERNEL_VERSION=${LINUX_KERNEL_FLAVOR%%-*}
   # it kinda sucks that I have to use dpkg for this
   if dpkg --compare-versions "$LINUX_KERNEL_VERSION" gt "2.5"; then
+    debugmsg "Linux kernel > 2.5 detected; using 0 as default nice value"
     NICE_DEFAULT=0
   fi
 fi
 
-checkval () {
-  set +e
-  VALID=
-  # first, try to subtract number from itself to validate numeric input
-  # (expr is noisy, always throw away its output)
-  expr "$1" - "$1" > /dev/null 2>&1
-  if [ $? != 2 ]; then
-    # now check for valid range
-    if expr "$1" ">=" "-20" > /dev/null 2>&1 && \
-       expr "$1" "<=" "19" > /dev/null 2>&1; then
-      VALID=true
+# debconf is not a registry; use the current contents of the default display
+# manager to pre-answer the question if possible
+CURRENT_ALLOWED_USERS=
+CURRENT_NICE_VALUE=
+
+# scan the X wrapper config file for existing settings, if it exists
+if [ -e "$XWRAPPER_CONFIG" ]; then
+  if MATCHES=$(grep "^allowed_users=.\+" "$XWRAPPER_CONFIG"); then
+    CURRENT_ALLOWED_USERS=$(echo "${MATCHES##*=}" | head -n 1)
+  fi
+  if MATCHES=$(grep "^nice_value=.\+" "$XWRAPPER_CONFIG"); then
+    CURRENT_NICE_VALUE=$(echo "${MATCHES##*=}" | head -n 1)
+  fi
+else
+  # if upgrading from xserver-common prior to 4.0.1-6, scan old wrapper config
+  # file for a default setting of allowed users (nice value support wasn't
+  # implemented back then)
+  if dpkg --compare-versions "$2" lt "4.1.0-6"; then
+    if [ -e "$OLD_CONFIG_FILE" ]; then
+      CURRENT_ALLOWED_USERS=$(sed -n '2p' < "$OLD_CONFIG_FILE" |
+                              tr '[[:upper:]]' '[[:lower:]]')
     fi
   fi
-  set -e;
-}
+fi
 
-# if one were going to parse the on-disk Xwrapper.config file and set the
-# debconf template values to match, one would do so here; but we're not
+if [ -n "$CURRENT_ALLOWED_USERS" ]; then
+  debugmsg "setting xserver-common/xwrapper/allowed_users from configuration" \
+           "file"
+  safe_debconf db_set xserver-common/xwrapper/allowed_users \
+                      $(allowed_users_actual_to_english \
+                      "$CURRENT_ALLOWED_USERS")
+fi
 
-db_input low xserver-common/xwrapper/allowed_users || true
-db_go
+if [ -n "$CURRENT_NICE_VALUE" ]; then
+  debugmsg "setting xserver-common/xwrapper/nice_value from configuration file"
+  if validate_nice_value "$CURRENT_NICE_VALUE"; then
+    safe_debconf db_set xserver-common/xwrapper/nice_value \
+                        "$CURRENT_NICE_VALUE"
+  fi
+fi
 
-db_get xserver-common/xwrapper/allowed_users
-case "$RET" in
-  "Root Only")
-    db_set xserver-common/xwrapper/actual_allowed_users "rootonly"
-    ;;
-  "Console Users Only")
-    db_set xserver-common/xwrapper/actual_allowed_users "console"
-    ;;
-  "Anybody")
-    db_set xserver-common/xwrapper/actual_allowed_users "anybody"
-    ;;
-esac
+safe_debconf db_input low xserver-common/xwrapper/allowed_users
+safe_debconf db_go
 
+safe_debconf db_get xserver-common/xwrapper/allowed_users
+if [ -n "$RET" ]; then
+  safe_debconf db_set xserver-common/xwrapper/actual_allowed_users \
+                      $(allowed_users_english_to_actual "$RET")
+fi
+
 # next question requires input validation
 # save valid value already present (possibly the template default)
-db_get xserver-common/xwrapper/nice_value
+safe_debconf db_get xserver-common/xwrapper/nice_value
 SAFE="$RET"
-VALID=
-# make sure it's really safe
-checkval "$RET"
-if [ -z "$VALID" ]; then
+# make sure it's really safe; if not, use the default
+if ! validate_nice_value "$RET"; then
   SAFE="$NICE_DEFAULT"
-  db_set xserver-common/xwrapper/nice_value "$SAFE"
+  safe_debconf db_set xserver-common/xwrapper/nice_value "$SAFE"
 fi
 set +e
 while :; do
-  db_input low xserver-common/xwrapper/nice_value
+  safe_debconf db_input low xserver-common/xwrapper/nice_value
   # is the question going to be asked?
   if [ $? = 30 ]; then
     break # no; bail out of validation loop
   fi
-  db_go
-  db_get xserver-common/xwrapper/nice_value
+  safe_debconf db_go
+  safe_debconf db_get xserver-common/xwrapper/nice_value
   # string, needs input validation
-  checkval "$RET"
-  if [ -z "$VALID" ]; then
+  if validate_nice_value "$RET"; then
+    # valid input from user
+    break
+  else
     # the input was invalid; restore the known good value in case we are
     # interrupted before the user provides a valid one
-    db_set xserver-common/xwrapper/nice_value "$SAFE"
-    db_fset xserver-common/xwrapper/nice_value seen false
+    safe_debconf db_set xserver-common/xwrapper/nice_value "$SAFE"
+    safe_debconf db_fset xserver-common/xwrapper/nice_value seen false
     # now display the error message
-    db_fset xserver-common/xwrapper/nice_value/error seen false
-    db_input critical xserver-common/xwrapper/nice_value/error
-    db_go
-  else
-    break # valid input from user
+    safe_debconf db_fset xserver-common/xwrapper/nice_value/error seen false
+    safe_debconf db_input critical xserver-common/xwrapper/nice_value/error
+    safe_debconf db_go
   fi
 done
 set -e

Modified: trunk/debian/xserver-common.postinst.in
===================================================================
--- trunk/debian/xserver-common.postinst.in	2003-09-12 17:43:58 UTC (rev 515)
+++ trunk/debian/xserver-common.postinst.in	2003-09-12 18:39:54 UTC (rev 516)
@@ -35,7 +35,6 @@
 # only mess with config files if the configuration file auxiliary directory
 # exists; if it does not, assume that's the way the user wants it
 if [ -d "$CONFIG_AUX_DIR" ]; then
-
   # register this package as a (potential) handler of the X server wrapper
   # config file
   if ! fgrep -qsx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER"; then
@@ -53,32 +52,35 @@
       if [ "$(md5sum "$XWRAPPER_CONFIG")" = \
            "$(cat "$XWRAPPER_CONFIG_CHECKSUM")" ]; then
         # they match; prepare a new version of the config file
-        db_get xserver-common/xwrapper/actual_allowed_users
+        safe_debconf db_get xserver-common/xwrapper/actual_allowed_users
         ALLOWED_USERS="$RET"
-        db_get xserver-common/xwrapper/nice_value
+        safe_debconf db_get xserver-common/xwrapper/nice_value
         NICE_VALUE="$RET"
-        NEW_XWRAPPER_CONFIG=$(tempfile)
-        cat > "$NEW_XWRAPPER_CONFIG" << EOF
+        if [ -n "$ALLOWED_USERS" -a -n "$NICE_VALUE" ]; then
+          NEW_XWRAPPER_CONFIG=$(tempfile)
+          cat > "$NEW_XWRAPPER_CONFIG" << EOF
 allowed_users=$ALLOWED_USERS
 nice_value=$NICE_VALUE
 EOF
-        if ! cmp -s "$XWRAPPER_CONFIG" "$NEW_XWRAPPER_CONFIG"; then
-          cp "$NEW_XWRAPPER_CONFIG" "$XWRAPPER_CONFIG.dpkg-new"
-          mv "$XWRAPPER_CONFIG.dpkg-new" "$XWRAPPER_CONFIG"
-          md5sum "$XWRAPPER_CONFIG" > "$XWRAPPER_CONFIG_CHECKSUM"
+          if ! cmp -s "$XWRAPPER_CONFIG" "$NEW_XWRAPPER_CONFIG"; then
+            cp "$NEW_XWRAPPER_CONFIG" "$XWRAPPER_CONFIG.dpkg-new"
+            mv "$XWRAPPER_CONFIG.dpkg-new" "$XWRAPPER_CONFIG"
+            md5sum "$XWRAPPER_CONFIG" > "$XWRAPPER_CONFIG_CHECKSUM"
+          fi
+          rm -f "$NEW_XWRAPPER_CONFIG"
+        else
+          debugmsg "not updating $XWRAPPER_CONFIG; problems communicating" \
+                   "with debconf database"
         fi
-        rm -f "$NEW_XWRAPPER_CONFIG"
       else
-        message "Note: not updating $XWRAPPER_CONFIG; file has been customized."
+        debugmsg "not updating $XWRAPPER_CONFIG; file has been customized"
       fi
     else
-      message "Note: not updating $XWRAPPER_CONFIG; no stored checksum" \
-              "available."
+      debugmsg "not updating $XWRAPPER_CONFIG; no stored checksum available"
     fi
   else
-    message "Note: not updating $XWRAPPER_CONFIG; file does not exist."
+    debugmsg "not updating $XWRAPPER_CONFIG; file does not exist"
   fi
-
 fi
 
 exit 0

Modified: trunk/debian/xserver-common.preinst.in
===================================================================
--- trunk/debian/xserver-common.preinst.in	2003-09-12 17:43:58 UTC (rev 515)
+++ trunk/debian/xserver-common.preinst.in	2003-09-12 18:39:54 UTC (rev 516)
@@ -24,20 +24,14 @@
 if [ "$1" = "install" -o "$1" = "upgrade" ]; then
   # xserver dir moved to /etc/X11 in 4.x
   if [ -e /usr/X11R6/lib/X11/xserver -a ! -L /usr/X11R6/lib/X11/xserver ]; then
-    message "Note: Removing obsolete /usr/X11R6/lib/X11/xserver directory."
+    debugmsg "removing obsolete /usr/X11R6/lib/X11/xserver directory"
     mv /usr/X11R6/lib/X11/xserver /usr/X11R6/lib/X11/xserver.moved-by-preinst
   fi
   check_symlinks_and_warn /usr/X11R6/lib/X11/xserver
 
-  # /etc/X11/Xserver obsolete as of 4.0.1-6
-  if [ -e /etc/X11/Xserver ]; then
-    message "Note: Moving obsolete file /etc/X11/Xserver to" \
-            "/etc/X11/Xserver.xserver-common-backup."
-    mv /etc/X11/Xserver /etc/X11/Xserver.xserver-common-backup
-  fi
-
   # create the configuration files' auxiliary directory if it doesn't exist
   if [ ! -e "$CONFIG_AUX_DIR" ]; then
+    debugmsg "creating $CONFIG_AUX_DIR"
     mkdir --mode=755 --parents "$CONFIG_AUX_DIR"
   fi
 
@@ -89,8 +83,8 @@
         fi
       fi
       # in other news, unregister the now no-longer-used templates
-      db_unregister xserver-common/manage_config_with_debconf
-      db_unregister xserver-common/move_existing_nondebconf_config
+      safe_debconf db_unregister xserver-common/manage_config_with_debconf
+      safe_debconf db_unregister xserver-common/move_existing_nondebconf_config
     fi
 
   fi



Reply to: