Author: branden
Date: 2004-08-21 01:09:33 -0500 (Sat, 21 Aug 2004)
New Revision: 1740

Added:
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.config.in
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.templates
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.config.in
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.templates
Modified:
   branches/app-defaults-and-xkb-dir-migration-fix/debian/TODO
   branches/app-defaults-and-xkb-dir-migration-fix/debian/changelog
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.postinst.in
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.postrm.in
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.preinst.in
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.postinst.in
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.postrm.in
   branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.preinst.in
   branches/app-defaults-and-xkb-dir-migration-fix/debian/shell-lib.sh
Log:
Rewrite migration of app-defaults (in libxt6) and xkb (in libx11-6)
directories.
+ Enhance the shell libary with new functions:
  - Implement check_symlink() and change check_symlinks_and_warn() and
    check_symlinks_and_bomb() to use it.
  - Implement make_symlink_sane().  Ensure that the specified symbolic
    link symlink exists, and points to the specified target.  If symlink
    does not exist, create it and point it at target.  If symlink exists
    but is not a symbolic link, back it up.  If symlink exists, is a
    symbolic link, but points to the wrong location, fix it.  If symlink
    exists, is a symbolic link, and already points to target, do nothing.
    This function wouldn't be needed if ln had an -I, --idempotent option.
  - Implement migrate_dir_to_symlink().  Per Debian Policy section 6.5.4,
    "A directory will never be replaced by a symbolic link to a directory
    or vice versa; instead, the existing state (symlink or not) will be
    left alone and dpkg will follow the symlink if there is one."  We have
    to do it ourselves.  This function moves the contents of old_location,
    a directory, into new_location, a directory, then makes old_location a
    symbolic link to new_location.  old_location need not exist, but if it
    does, it must be a directory (or a symlink to a directory).  If it is
    not, it is backed up.  If new_location exists already and is not a
    directory, it is backed up.
+ Add config scripts for libx11-6 and libxt6, which detect if
  /usr/X11R6/lib/X11/{app-defaults,xkb} is a directory but not a symlink,
  and use debconf to prompt the user (at low priority) whether the
  directories should be moved.  If the user says no, abort the script.  If
  the user says yes (default), start the migration with
  migrate_dir_to_symlink().
+ Update preinst scripts to use debconf as the configs script do; this is
  unusual but necessary because if we're going to do the migration we need
  to start before any other packages (which may use the old directories)
  are unpacked.
+ In the preinst scripts, call check_symlink(), and if that fails, call
  make_symlink_sane().  Stop calling check_symlinks_and_warn().
+ Update postinst scripts to indicate that migration is completed.
+ Update postrm scripts to run migration in reverse if it had been started
  and the package installation or upgrade is aborted.
+ We keep shipping /etc/X11/{app-defaults,xkb} symlinks as part of the
  package payloads, because manipulating them in the preinst isn't enough
  -- dpkg will remove "disappearing" files from the system *after* the
  preinst runs but before the postinst does, leaving a window for packages
  using the legacy paths to unpack to the old location with no symlink to
  redirect them, which is precisely what we don't want (see section 6.5 of
  the Debian Policy Manual).

Convert occurrences of test -[ao] to the shell's && and || operators.

Update Vim modelines.


Modified: branches/app-defaults-and-xkb-dir-migration-fix/debian/TODO
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/TODO 2004-08-20 
23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/TODO 2004-08-21 
06:09:33 UTC (rev 1740)
@@ -18,21 +18,6 @@
 --------------
 
 * Add FAQ entry describing what has become of the XFree86 3.x packages.
-* Re-do migration of /usr/X11R6/lib/X11/{app-defaults,xkb}:
-  + stop shipping symlink
-  + In {libxt6,xlibs}.preinst:
-    - if existing stuff in /usr/X11R6/lib/X11/$DIR:
-      + debconf boolean explaining situation and permitting abort
-      + if user doesn't abort:
-        - mv existing directory contents to /etc/X11/$DIR
-        - create /usr/X11R6/lib/X11/$DIR symlink
-        - touch $DIR migration file in /var/run
-  + In {libxt6,xlibs}.postinst:
-    - remove $DIR migration file from /var/run
-  + In {libxt6,xlibs}.postrm:
-    - If /var/run/$DIR migration file exists:
-      + remove /usr/X11R6/lib/X11/$DIR symlink
-      + mv /etc/X11/$DIR back to /usr/X11R6/lib/X11/$DIR
 * Rewrite xserver-xfree86 debconfage.  Joey Hess, Eduard Bloch, and David
   Nusinow have provided good input.
   + udev users will have "/dev/input/mousen" -- configure that as only mouse

Modified: branches/app-defaults-and-xkb-dir-migration-fix/debian/changelog
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/changelog    
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/changelog    
2004-08-21 06:09:33 UTC (rev 1740)
@@ -287,6 +287,51 @@
     + Circumvent unresolved symbol complaints by explicitly loading the "glx"
       module when DRI is used.  (Closes: #254601)
 
+  * Rewrite migration of app-defaults (in libxt6) and xkb (in libx11-6)
+    directories.
+    + Enhance the shell libary with new functions:
+      - Implement check_symlink() and change check_symlinks_and_warn() and
+        check_symlinks_and_bomb() to use it.
+      - Implement make_symlink_sane().  Ensure that the specified symbolic
+        link symlink exists, and points to the specified target.  If symlink
+        does not exist, create it and point it at target.  If symlink exists
+        but is not a symbolic link, back it up.  If symlink exists, is a
+        symbolic link, but points to the wrong location, fix it.  If symlink
+        exists, is a symbolic link, and already points to target, do nothing.
+        This function wouldn't be needed if ln had an -I, --idempotent option.
+      - Implement migrate_dir_to_symlink().  Per Debian Policy section 6.5.4,
+        "A directory will never be replaced by a symbolic link to a directory
+        or vice versa; instead, the existing state (symlink or not) will be
+        left alone and dpkg will follow the symlink if there is one."  We have
+        to do it ourselves.  This function moves the contents of old_location,
+        a directory, into new_location, a directory, then makes old_location a
+        symbolic link to new_location.  old_location need not exist, but if it
+        does, it must be a directory (or a symlink to a directory).  If it is
+        not, it is backed up.  If new_location exists already and is not a
+        directory, it is backed up.
+    + Add config scripts for libx11-6 and libxt6, which detect if
+      /usr/X11R6/lib/X11/{app-defaults,xkb} is a directory but not a symlink,
+      and use debconf to prompt the user (at low priority) whether the
+      directories should be moved.  If the user says no, abort the script.  If
+      the user says yes (default), start the migration with
+      migrate_dir_to_symlink().
+    + Update preinst scripts to use debconf as the configs script do; this is
+      unusual but necessary because if we're going to do the migration we need
+      to start before any other packages (which may use the old directories)
+      are unpacked.
+    + In the preinst scripts, call check_symlink(), and if that fails, call
+      make_symlink_sane().  Stop calling check_symlinks_and_warn().
+    + Update postinst scripts to indicate that migration is completed.
+    + Update postrm scripts to run migration in reverse if it had been started
+      and the package installation or upgrade is aborted.
+    + We keep shipping /etc/X11/{app-defaults,xkb} symlinks as part of the
+      package payloads, because manipulating them in the preinst isn't enough
+      -- dpkg will remove "disappearing" files from the system *after* the
+      preinst runs but before the postinst does, leaving a window for packages
+      using the legacy paths to unpack to the old location with no symlink to
+      redirect them, which is precisely what we don't want (see section 6.5 of
+      the Debian Policy Manual).
+
   Changes by Fabio M. Di Nitto and Branden Robinson:
 
   * Support building only the parts of the source tree needed by
@@ -328,7 +373,7 @@
     autodetection would cause the script to think it had detected one X server
     or XFree86 video driver instead ($(echo "" | wc -l) is "1", not "0").
 
- -- Branden Robinson <[EMAIL PROTECTED]>  Fri, 20 Aug 2004 15:59:21 -0500
+ -- Branden Robinson <[EMAIL PROTECTED]>  Fri, 20 Aug 2004 23:02:28 -0500
 
 xfree86 (4.3.0.dfsg.1-6) unstable; urgency=low
 

Added: branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.config.in
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.config.in   
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.config.in   
2004-08-21 06:09:33 UTC (rev 1740)
@@ -0,0 +1,28 @@
+#!/bin/sh
+# Debian libx11-6 package configuration script
+# Copyright 2004 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+# $Id$
+
+set -e
+
+# source debconf library
+. /usr/share/debconf/confmodule
+
+THIS_PACKAGE=libx11-6
+THIS_SCRIPT=config
+
+#INCLUDE_SHELL_LIB#
+
+# The xkb directory moved in the xfree86 4.0 packages.
+DIR=/usr/X11R6/lib/X11/xkb
+if [ -d "$DIR" ] && [ ! -L "$DIR" ]; then
+  run db_input low libx11-6/migrate_xkb_dir
+  run db_go
+fi
+
+exit 0
+
+# vim:set ai et sts=2 sw=2 tw=80:


Property changes on: 
branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.config.in
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.postinst.in
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.postinst.in 
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.postinst.in 
2004-08-21 06:09:33 UTC (rev 1740)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Debian libx11-6 package post-installation script
-# Copyright 2003 Branden Robinson.
+# Copyright 2003, 2004 Branden Robinson.
 # Licensed under the GNU General Public License, version 2.  See the file
 # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
 # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
@@ -14,12 +14,14 @@
 
 #INCLUDE_SHELL_LIB#
 
-# finish migration started in preinst
+# Finish migration started in preinst.
+MIGRATION_FILE=/var/run/libx11-6.xkb.migration
 DIR=/usr/X11R6/lib/X11/xkb
-if [ -d "$DIR.dpkg-tmp" -a -L "$DIR" ]; then
-  observe "committing removal of obsolete directory $DIR"
-  rm -r "$DIR"
+
+if [ -e "$MIGRATION_FILE" ]; then
+  rm "$MIGRATION_FILE"
 fi
+
 check_symlinks_and_bomb "$DIR"
 
 register_x_lib_dir_with_ld_so
@@ -29,4 +31,4 @@
 
 exit 0
 
-# vim:set ai et sts=2 sw=2 tw=0:
+# vim:set ai et sts=2 sw=2 tw=80:

Modified: 
branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.postrm.in
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.postrm.in   
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.postrm.in   
2004-08-21 06:09:33 UTC (rev 1740)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Debian libx11-6 package post-removal script
-# Copyright 2003 Branden Robinson.
+# Copyright 2003, 2004 Branden Robinson.
 # Licensed under the GNU General Public License, version 2.  See the file
 # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
 # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
@@ -14,12 +14,17 @@
 
 #INCLUDE_SHELL_LIB#
 
-if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ]; then
-  # roll back migration started in preinst
-  DIR=/usr/X11R6/lib/X11/xkb
-  if [ -d "$DIR.dpkg-tmp" ]; then
-    observe "rolling back removal of obsolete directory $DIR"
-    mv "$DIR.dpkg-tmp" "$DIR"
+MIGRATION_FILE=/var/run/libx11-6.xkb.migration
+DIR=/usr/X11R6/lib/X11/xkb
+
+# If we were migrating the xkb directory but have aborted the install or
+# upgrade, we need to undo it.
+if [ "$1" = "abort-install" ] || [ "$1" = "abort-upgrade" ]; then
+  if [ -e "$MIGRATION_FILE" ]; then
+    warn "reverting migration of $DIR to $(maplink "$DIR")"
+    if ! migrate_dir_to_symlink "$(maplink "$DIR")" "$DIR"; then
+      die "failed to migrate $(maplink "$DIR") back to $DIR"
+    fi
   fi
 fi
 
@@ -32,4 +37,4 @@
 
 exit 0
 
-# vim:set ai et sts=2 sw=2 tw=0:
+# vim:set ai et sts=2 sw=2 tw=80:

Modified: 
branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.preinst.in
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.preinst.in  
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.preinst.in  
2004-08-21 06:09:33 UTC (rev 1740)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Debian libx11-6 package pre-installation script
-# Copyright 2003 Branden Robinson.
+# Copyright 2003, 2004 Branden Robinson.
 # Licensed under the GNU General Public License, version 2.  See the file
 # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
 # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
@@ -9,23 +9,51 @@
 
 set -e
 
+# source debconf library
+. /usr/share/debconf/confmodule
+
 THIS_PACKAGE=libx11-6
 THIS_SCRIPT=preinst
 
 #INCLUDE_SHELL_LIB#
 
-if [ "$1" = "install" -o "$1" = "upgrade" ]; then
+if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then
   # xkb directory moved in 4.0
+  MIGRATION_FILE=/var/run/libx11-6.xkb.migration
   DIR=/usr/X11R6/lib/X11/xkb
-  if [ -d "$DIR" -a ! -L "$DIR" ]; then
-    observe "preparing obsolete directory $DIR for removal"
-    mv "$DIR" "$DIR.dpkg-tmp"
+  if [ -d "$DIR" ] && [ ! -L "$DIR" ]; then
+    # We do this debconf stuff in the preinst, not the postinst, because the
+    # migration needs to happen *before* other packages are unpacked.
+    # The question may not have been seen yet if this package wasn't
+    # pre-configured.  If not, we must ask now.
+    run db_metaget libx11-6/migrate_xkb_dir seen
+    if [ "$RET" != "true" ]; then
+      run db_input low libx11-6/migrate_xkb_dir
+      run db_go
+    fi
+    if db_get libx11-6/migrate_xkb_dir; then
+      if [ "$RET" = "true" ]; then
+        if migrate_dir_to_symlink "$DIR" "$(maplink "$DIR")"; then
+          >"$MIGRATION_FILE"
+        else
+          die "failed to migrate $DIR to $(maplink "$DIR")"
+        fi
+      else
+        die "aborting at user request"
+      fi
+    else
+      internal_error "failure using db_get to retrieve" \
+        "libx11-6/migrate_xkb_dir"
+    fi
   fi
-  check_symlinks_and_warn "$DIR"
+  # Ensure the app-defaults directory is in the correct place.
+  if ! check_symlink "$DIR"; then
+    make_symlink_sane "$DIR" "$(maplink "$DIR")"
+  fi
 fi
 
 #DEBHELPER#
 
 exit 0
 
-# vim:set ai et sts=2 sw=2 tw=0:
+# vim:set ai et sts=2 sw=2 tw=80:

Added: branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.templates
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.templates   
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libx11-6.templates   
2004-08-21 06:09:33 UTC (rev 1740)
@@ -0,0 +1,15 @@
+Template: libx11-6/migrate_xkb_dir
+Type: boolean
+_Description: Migrate XKB configuration directory?
+ The directory where configuration information (including keyboard data) for
+ the X KEYBOARD Extension (XKB) is stored has been changed from
+ /usr/X11R6/lib/X11/xkb to /etc/X11/xkb.
+ .
+ Your system is using the old location, and some programs, such as those from
+ old or unofficial Debian packages, may continue to install files there.
+ .
+ Would you like the XKB configuration files on the system to be automatically
+ migrated from the old location to the new one?  Any existing files in the new
+ location that have the same name will be backed up and replaced by the files
+ from the old location.  A symbolic link from the old location to the new one
+ will be created to prevent legacy applications from breaking.

Added: branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.config.in
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.config.in     
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.config.in     
2004-08-21 06:09:33 UTC (rev 1740)
@@ -0,0 +1,28 @@
+#!/bin/sh
+# Debian libxt6 package configuration script
+# Copyright 2004 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+# $Id$
+
+set -e
+
+# source debconf library
+. /usr/share/debconf/confmodule
+
+THIS_PACKAGE=libxt6
+THIS_SCRIPT=config
+
+#INCLUDE_SHELL_LIB#
+
+# The app-defaults directory moved in the xfree86 4.0 packages.
+DIR=/usr/X11R6/lib/X11/app-defaults
+if [ -d "$DIR" ] && [ ! -L "$DIR" ]; then
+  run db_input low libxt6/migrate_app_defaults_dir
+  run db_go
+fi
+
+exit 0
+
+# vim:set ai et sts=2 sw=2 tw=80:


Property changes on: 
branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.config.in
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.postinst.in
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.postinst.in   
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.postinst.in   
2004-08-21 06:09:33 UTC (rev 1740)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Debian libxt6 package post-installation script
-# Copyright 2003 Branden Robinson.
+# Copyright 2003, 2004 Branden Robinson.
 # Licensed under the GNU General Public License, version 2.  See the file
 # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
 # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
@@ -14,12 +14,14 @@
 
 #INCLUDE_SHELL_LIB#
 
-# finish migration started in preinst
+# Finish migration started in preinst.
+MIGRATION_FILE=/var/run/libxt6.app-defaults.migration
 DIR=/usr/X11R6/lib/X11/app-defaults
-if [ -d "$DIR.dpkg-tmp" -a -L "$DIR" ]; then
-  observe "committing removal of obsolete directory $DIR"
-  rm -r "$DIR"
+
+if [ -e "$MIGRATION_FILE" ]; then
+  rm "$MIGRATION_FILE"
 fi
+
 check_symlinks_and_bomb "$DIR"
 
 register_x_lib_dir_with_ld_so
@@ -29,4 +31,4 @@
 
 exit 0
 
-# vim:set ai et sts=2 sw=2 tw=0:
+# vim:set ai et sts=2 sw=2 tw=80:

Modified: 
branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.postrm.in
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.postrm.in     
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.postrm.in     
2004-08-21 06:09:33 UTC (rev 1740)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Debian libxt6 package post-removal script
-# Copyright 2003 Branden Robinson.
+# Copyright 2003, 2004 Branden Robinson.
 # Licensed under the GNU General Public License, version 2.  See the file
 # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
 # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
@@ -14,12 +14,17 @@
 
 #INCLUDE_SHELL_LIB#
 
-if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ]; then
-  # roll back migration started in preinst
-  DIR=/usr/X11R6/lib/X11/app-defaults
-  if [ -d "$DIR.dpkg-tmp" ]; then
-    observe "rolling back removal of obsolete directory $DIR"
-    mv "$DIR.dpkg-tmp" "$DIR"
+MIGRATION_FILE=/var/run/libxt6.app-defaults.migration
+DIR=/usr/X11R6/lib/X11/app-defaults
+
+# If we were migrating the app-defaults directory but have aborted the install
+# or upgrade, we need to undo it.
+if [ "$1" = "abort-install" ] || [ "$1" = "abort-upgrade" ]; then
+  if [ -e "$MIGRATION_FILE" ]; then
+    warn "reverting migration of $DIR to $(maplink "$DIR")"
+    if ! migrate_dir_to_symlink "$(maplink "$DIR")" "$DIR"; then
+      die "failed to migrate $(maplink "$DIR") back to $DIR"
+    fi
   fi
 fi
 
@@ -32,4 +37,4 @@
 
 exit 0
 
-# vim:set ai et sts=2 sw=2 tw=0:
+# vim:set ai et sts=2 sw=2 tw=80:

Modified: 
branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.preinst.in
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.preinst.in    
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.preinst.in    
2004-08-21 06:09:33 UTC (rev 1740)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Debian libxt6 package pre-installation script
-# Copyright 2003 Branden Robinson.
+# Copyright 2003, 2004 Branden Robinson.
 # Licensed under the GNU General Public License, version 2.  See the file
 # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
 # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
@@ -9,23 +9,51 @@
 
 set -e
 
+# source debconf library
+. /usr/share/debconf/confmodule
+
 THIS_PACKAGE=libxt6
 THIS_SCRIPT=preinst
 
 #INCLUDE_SHELL_LIB#
 
-if [ "$1" = "install" -o "$1" = "upgrade" ]; then
+if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then
   # app-defaults directory moved in 4.0
+  MIGRATION_FILE=/var/run/libxt6.app-defaults.migration
   DIR=/usr/X11R6/lib/X11/app-defaults
-  if [ -d "$DIR" -a ! -L "$DIR" ]; then
-    observe "preparing obsolete directory $DIR for removal"
-    mv "$DIR" "$DIR.dpkg-tmp"
+  if [ -d "$DIR" ] && [ ! -L "$DIR" ]; then
+    # We do this debconf stuff in the preinst, not the postinst, because the
+    # migration needs to happen *before* other packages are unpacked.
+    # The question may not have been seen yet if this package wasn't
+    # pre-configured.  If not, we must ask now.
+    run db_metaget libxt6/migrate_app_defaults_dir seen
+    if [ "$RET" != "true" ]; then
+      run db_input low libxt6/migrate_app_defaults_dir
+      run db_go
+    fi
+    if db_get libxt6/migrate_app_defaults_dir; then
+      if [ "$RET" = "true" ]; then
+        if migrate_dir_to_symlink "$DIR" "$(maplink "$DIR")"; then
+          >"$MIGRATION_FILE"
+        else
+          die "failed to migrate $DIR to $(maplink "$DIR")"
+        fi
+      else
+        die "aborting at user request"
+      fi
+    else
+      internal_error "failure using db_get to retrieve" \
+        "libxt6/migrate_app_defaults_dir"
+    fi
   fi
-  check_symlinks_and_warn "$DIR"
+  # Ensure the app-defaults directory is in the correct place.
+  if ! check_symlink "$DIR"; then
+    make_symlink_sane "$DIR" "$(maplink "$DIR")"
+  fi
 fi
 
 #DEBHELPER#
 
 exit 0
 
-# vim:set ai et sts=2 sw=2 tw=0:
+# vim:set ai et sts=2 sw=2 tw=80:

Added: branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.templates
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.templates     
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/libxt6.templates     
2004-08-21 06:09:33 UTC (rev 1740)
@@ -0,0 +1,15 @@
+Template: libxt6/migrate_app_defaults_dir
+Type: boolean
+_Description: Migrate Xt application defaults directory?
+ The directory where application defaults for X Window System client programs
+ based on the X Toolkit Intrinsics (Xt) are stored has been changed from
+ /usr/X11R6/lib/X11/app-defaults to /etc/X11/app-defaults.
+ .
+ Your system is using the old location, and some programs, such as those from
+ old or unofficial Debian packages, may continue to install files there.
+ .
+ Would you like the app-defaults files on the system to be automatically
+ migrated from the old location to the new one?  Any existing files in the new
+ location that have the same name will be backed up and replaced by the
+ files from the old location.  A symbolic link from the old location to the
+ new one will be created to prevent legacy applications from breaking.

Modified: branches/app-defaults-and-xkb-dir-migration-fix/debian/shell-lib.sh
===================================================================
--- branches/app-defaults-and-xkb-dir-migration-fix/debian/shell-lib.sh 
2004-08-20 23:01:52 UTC (rev 1739)
+++ branches/app-defaults-and-xkb-dir-migration-fix/debian/shell-lib.sh 
2004-08-21 06:09:33 UTC (rev 1740)
@@ -275,6 +275,32 @@
   }
 fi
 
+check_symlink () {
+  # syntax: check_symlink symlink
+  #
+  # See if specified symlink points where it is supposed to.  Return 0 if it
+  # does, and 1 if it does not.
+  #
+  # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
+
+  local symlink
+
+  # validate arguments
+  if [ $# -ne 1 ]; then
+    usage_error "check_symlink() called with wrong number of arguments;" \
+                "expected 1, got $#"
+    exit $SHELL_LIB_USAGE_ERROR
+  fi
+
+  symlink="$1"
+
+  if [ "$(maplink "$symlink")" = "$(readlink "$symlink")" ]; then
+    return 0
+  else
+    return 1
+  fi
+}
+
 check_symlinks_and_warn () {
   # syntax: check_symlinks_and_warn symlink ...
   #
@@ -295,7 +321,7 @@
   while [ -n "$1" ]; do
     symlink="$1"
     if [ -L "$symlink" ]; then
-      if [ "$(maplink "$symlink")" != "$(readlink "$symlink")" ]; then
+      if ! check_symlink "$symlink"; then
         observe "$symlink symbolic link points to wrong location" \
                 "$(readlink "$symlink"); removing"
         rm "$symlink"
@@ -337,7 +363,7 @@
     problem=
     symlink="$1"
     if [ -L "$symlink" ]; then
-      if [ "$(maplink "$symlink")" != "$(readlink "$symlink")" ]; then
+      if ! check_symlink "$symlink"; then
         problem=yes
         warn "$symlink symbolic link points to wrong location" \
              "$(readlink "$symlink")"
@@ -594,4 +620,144 @@
   fi
 }
 
-# vim:set ai et sts=2 sw=2 tw=0:
+make_symlink_sane () {
+  # syntax: make_symlink_sane symlink target
+  #
+  # Ensure that the symbolic link symlink exists, and points to target.
+  #
+  # If symlink does not exist, create it and point it at target.
+  #
+  # If symlink exists but is not a symbolic link, back it up.
+  #
+  # If symlink exists, is a symbolic link, but points to the wrong location, 
fix
+  # it.
+  #
+  # If symlink exists, is a symbolic link, and already points to target, do
+  # nothing.
+  #
+  # This function wouldn't be needed if ln had an -I, --idempotent option.
+
+  # Validate arguments.
+  if [ $# -ne 2 ]; then
+    usage_error "make_symlink_sane() called with wrong number of arguments;" \
+      "expected 2, got $#"
+    exit $SHELL_LIB_USAGE_ERROR
+  fi
+
+  # We could just use the positional parameters as-is, but that makes things
+  # harder to follow.
+  local symlink target
+
+  symlink="$1"
+  target="$2"
+
+  if [ -L "$symlink" ] && [ "$(readlink "$symlink")" = "$target" ]; then
+      observe "link from $symlink to $target already exists"
+  else
+    observe "creating symbolic link from $symlink to $target"
+    ln -s -b -S ".dpkg-old" "$target" "$symlink"
+  fi
+}
+
+migrate_dir_to_symlink () {
+  # syntax: migrate_dir_to_symlink old_location new_location
+  #
+  # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
+  # symbolic link to a directory or vice versa; instead, the existing state
+  # (symlink or not) will be left alone and dpkg will follow the symlink if
+  # there is one."
+  #
+  # We have to do it ourselves.
+  #
+  # This function moves the contents of old_location, a directory, into
+  # new_location, a directory, then makes old_location a symbolic link to
+  # new_location.
+  #
+  # old_location need not exist, but if it does, it must be a directory (or a
+  # symlink to a directory).  If it is not, it is backed up.  If new_location
+  # exists already and is not a directory, it is backed up.
+  #
+  # This function should be called from a package's preinst so that other
+  # packages unpacked after this one --- but before this package's postinst 
runs
+  # --- are unpacked into new_location even if their payloads contain
+  # old_location filespecs.
+
+  # Validate arguments.
+  if [ $# -ne 2 ]; then
+    usage_error "migrate_dir_to_symlink() called with wrong number of"
+                "arguments; expected 2, got $#"
+    exit $SHELL_LIB_USAGE_ERROR
+  fi
+
+  # We could just use the positional parameters as-is, but that makes things
+  # harder to follow.
+  local new old
+
+  old="$1"
+  new="$2"
+
+  # Is old location a symlink?
+  if [ -L "$old" ]; then
+    # Does it already point to new location?
+    if [ "$(readlink "$old")" = "$new" ]; then
+      # Nothing to do; migration has already been done.
+      observe "migration of $old to $new already done"
+      return 0
+    else
+      # Back it up.
+      warn "backing up symbolic link $old as $old.dpkg-old"
+      mv -b "$old" "$old.dpkg-old"
+    fi
+  fi
+
+  # Does old location exist, but is not a directory?
+  if [ -e "$old" ] && [ ! -d "$old" ]; then
+      # Back it up.
+      warn "backing up non-directory $old as $old.dpkg-old"
+      mv -b "$old" "$old.dpkg-old"
+  fi
+
+  observe "migrating $old to $new"
+
+  # Is new location a symlink?
+  if [ -L "$new" ]; then
+    # Does it point the wrong way, i.e., back to where we're migrating from?
+    if [ "$(readlink "$new")" = "$old" ]; then
+    # Get rid of it.
+      observe "removing symbolic link $new which points to $old"
+      rm "$new"
+    else
+      # Back it up.
+      warn "backing up symbolic link $new as $new.dpkg-old"
+      mv -b "$new" "$new.dpkg-old"
+    fi
+  fi
+
+  # Does new location exist, but is not a directory?
+  if [ -e "$new" ] && [ ! -d "$new" ]; then
+    warn "backing up non-directory $new as $new.dpkg-old"
+    mv -b "$new" "$new.dpkg-old"
+  fi
+
+  # Create new directory if it does not yet exist.
+  if [ ! -e "$new" ]; then
+    observe "creating $new"
+    mkdir -p "$new"
+  fi
+
+  # Copy files in old location to new location.  Back up any filenames that
+  # already exist in the new location with the extension ".dpkg-old".
+  observe "copying files from $old to $new"
+  if ! (cd "$old" && cp -a -b -S ".dpkg-old" . "$new"); then
+    die "error(s) encountered while copying files from $old to $new"
+  fi
+
+  # Remove files at old location.
+  observe "removing $old"
+  rm -r "$old"
+
+  # Create symlink from old location to new location.
+  make_symlink_sane "$old" "$new"
+}
+
+# vim:set ai et sts=2 sw=2 tw=80:

Reply via email to