home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / var / lib / dpkg / info / xcursor-themes.postinst < prev    next >
Encoding:
Text File  |  2006-08-04  |  29.0 KB  |  896 lines

  1. #!/bin/sh
  2. # Debian xcursor-themes package post-installation script
  3. # Copyright 2003 Daniel Stone, Branden Robinson.
  4. # Licensed under the GNU General Public License, version 2.  See the file
  5. # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
  6. # Acknowledgements to Stephen Early, Mark Eichin, and Manoj Srivastava.
  7.  
  8. # $Id: xcursor-themes.postinst.in 1860 2006-04-19 01:27:05Z vorlon $
  9.  
  10. set -e
  11.  
  12. THIS_PACKAGE=xcursor-themes
  13. THIS_SCRIPT=postinst
  14.  
  15. # $Id: shell-lib.sh 586 2005-09-03 18:37:47Z branden $
  16.  
  17. SOURCE_VERSION=1.0.1-4build1
  18. OFFICIAL_BUILD=
  19.  
  20. # Use special abnormal exit codes so that problems with this library are more
  21. # easily tracked down.
  22. SHELL_LIB_INTERNAL_ERROR=86
  23. SHELL_LIB_THROWN_ERROR=74
  24. SHELL_LIB_USAGE_ERROR=99
  25.  
  26. # old -> new variable names
  27. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  28.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  29. fi
  30. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  31.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  32. fi
  33.  
  34. # initial sanity checks
  35. if [ -z "$THIS_PACKAGE" ]; then
  36.   cat >&2 <<EOF
  37. Error: package maintainer script attempted to use shell library without
  38. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  39. version, and the text of this error message to the Debian Bug Tracking System.
  40. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  41. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  42. "doc-debian" package, or install the "reportbug" package and use the command of
  43. the same name to file a report against version $SOURCE_VERSION of this package.
  44. EOF
  45.   exit $SHELL_LIB_USAGE_ERROR
  46. fi
  47.  
  48. if [ -z "$THIS_SCRIPT" ]; then
  49.   cat >&2 <<EOF
  50. Error: package maintainer script attempted to use shell library without
  51. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  52. version, and the text of this error message to the Debian Bug Tracking System.
  53. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  54. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  55. "doc-debian" package, or install the "reportbug" package and use the command of
  56. the same name to file a report against version $SOURCE_VERSION of the
  57. "$THIS_PACKAGE" package.
  58. EOF
  59.   exit $SHELL_LIB_USAGE_ERROR
  60. fi
  61.  
  62. trap "message;\
  63.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  64.       message;\
  65.       exit 1" HUP INT QUIT TERM
  66.  
  67. reject_nondigits () {
  68.   # syntax: reject_nondigits [ operand ... ]
  69.   #
  70.   # scan operands (typically shell variables whose values cannot be trusted) for
  71.   # characters other than decimal digits and barf if any are found
  72.   while [ -n "$1" ]; do
  73.     # does the operand contain anything but digits?
  74.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  75.       # can't use die(), because it wraps message() which wraps this function
  76.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  77.            "possibly malicious garbage \"$1\"" >&2
  78.       exit $SHELL_LIB_THROWN_ERROR
  79.     fi
  80.     shift
  81.   done
  82. }
  83.  
  84. reject_whitespace () {
  85.   # syntax: reject_whitespace [ operand ]
  86.   #
  87.   # scan operand (typically a shell variable whose value cannot be trusted) for
  88.   # whitespace characters and barf if any are found
  89.   if [ -n "$1" ]; then
  90.     # does the operand contain any whitespace?
  91.     if expr "$1" : "[[:space:]]" > /dev/null 2>&1; then
  92.       # can't use die(), because I want to avoid forward references
  93.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_whitespace() encountered" \
  94.            "possibly malicious garbage \"$1\"" >&2
  95.       exit $SHELL_LIB_THROWN_ERROR
  96.     fi
  97.   fi
  98. }
  99.  
  100. reject_unlikely_path_chars () {
  101.   # syntax: reject_unlikely_path_chars [ operand ... ]
  102.   #
  103.   # scan operands (typically shell variables whose values cannot be trusted) for
  104.   # characters unlikely to be seen in a path and which the shell might
  105.   # interpret and barf if any are found
  106.   while [ -n "$1" ]; do
  107.     # does the operand contain any funny characters?
  108.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  109.       # can't use die(), because I want to avoid forward references
  110.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  111.            "encountered possibly malicious garbage \"$1\"" >&2
  112.       exit $SHELL_LIB_THROWN_ERROR
  113.     fi
  114.     shift
  115.   done
  116. }
  117.  
  118. # Query the terminal to establish a default number of columns to use for
  119. # displaying messages to the user.  This is used only as a fallback in the
  120. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  121. # the script is running, and this cannot, only being calculated once.)
  122. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  123. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  124.   DEFCOLUMNS=80
  125. fi
  126.  
  127. message () {
  128.   # pretty-print messages of arbitrary length
  129.   reject_nondigits "$COLUMNS"
  130.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  131. }
  132.  
  133. observe () {
  134.   # syntax: observe message ...
  135.   #
  136.   # issue observational message suitable for logging someday when support for
  137.   # it exists in dpkg
  138.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  139.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  140.   fi
  141. }
  142.  
  143. warn () {
  144.   # syntax: warn message ...
  145.   #
  146.   # issue warning message suitable for logging someday when support for
  147.   # it exists in dpkg; also send to standard error
  148.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  149. }
  150.  
  151. die () {
  152.   # syntax: die message ...
  153.   #
  154.   # exit script with error message
  155.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  156.   exit $SHELL_LIB_THROWN_ERROR
  157. }
  158.  
  159. internal_error () {
  160.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  161.   message "internal error: $*"
  162.   if [ -n "$OFFICIAL_BUILD" ]; then
  163.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  164.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  165.             "Tracking System.  Include all messages above that mention the" \
  166.             "$THIS_PACKAGE package.  Visit " \
  167.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  168.             "instructions, read the file" \
  169.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  170.             "package, or install the reportbug package and use the command of" \
  171.             "the same name to file a report."
  172.   fi
  173.   exit $SHELL_LIB_INTERNAL_ERROR
  174. }
  175.  
  176. usage_error () {
  177.   message "usage error: $*"
  178.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  179.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  180.           "Tracking System.  Include all messages above that mention the" \
  181.           "$THIS_PACKAGE package.  Visit " \
  182.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  183.           "instructions, read the file" \
  184.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  185.           "package, or install the reportbug package and use the command of" \
  186.           "the same name to file a report."
  187.   exit $SHELL_LIB_USAGE_ERROR
  188. }
  189.  
  190.  
  191. maplink () {
  192.   # returns what symlink should point to; i.e., what the "sane" answer is
  193.   # Keep this in sync with the debian/*.links files.
  194.   # This is only needed for symlinks to directories.
  195.   case "$1" in
  196.     /etc/X11/xkb/compiled) echo /var/lib/xkb ;;
  197.     /etc/X11/xkb/xkbcomp) echo /usr/X11R6/bin/xkbcomp ;;
  198.     /usr/X11R6/lib/X11/app-defaults) echo /etc/X11/app-defaults ;;
  199.     /usr/X11R6/lib/X11/fs) echo /etc/X11/fs ;;
  200.     /usr/X11R6/lib/X11/lbxproxy) echo /etc/X11/lbxproxy ;;
  201.     /usr/X11R6/lib/X11/proxymngr) echo /etc/X11/proxymngr ;;
  202.     /usr/X11R6/lib/X11/rstart) echo /etc/X11/rstart ;;
  203.     /usr/X11R6/lib/X11/twm) echo /etc/X11/twm ;;
  204.     /usr/X11R6/lib/X11/xdm) echo /etc/X11/xdm ;;
  205.     /usr/X11R6/lib/X11/xinit) echo /etc/X11/xinit ;;
  206.     /usr/X11R6/lib/X11/xkb) echo /etc/X11/xkb ;;
  207.     /usr/X11R6/lib/X11/xserver) echo /etc/X11/xserver ;;
  208.     /usr/X11R6/lib/X11/xsm) echo /etc/X11/xsm ;;
  209.     /usr/bin/X11) echo ../X11R6/bin ;;
  210.     /usr/bin/rstartd) echo ../X11R6/bin/rstartd ;;
  211.     /usr/include/X11) echo ../X11R6/include/X11 ;;
  212.     /usr/lib/X11) echo ../X11R6/lib/X11 ;;
  213.     *) internal_error "maplink() called with unknown path \"$1\"" ;;
  214.   esac
  215. }
  216.  
  217. analyze_path () {
  218.   # given a supplied set of pathnames, break each one up by directory and do an
  219.   # ls -dl on each component, cumulatively; i.e.
  220.   # analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
  221.   # Thanks to Randolph Chung for this clever hack.
  222.  
  223.   #local f g
  224.  
  225.   while [ -n "$1" ]; do
  226.     reject_whitespace "$1"
  227.     _g=
  228.     message "Analyzing $1:"
  229.     for _f in $(echo "$1" | tr / \  ); do
  230.       if [ -e /$_g$_f ]; then
  231.         ls -dl /$_g$_f /$_g$_f.dpkg-* 2> /dev/null || true
  232.         _g=$_g$_f/
  233.       else
  234.         message "/$_g$_f: nonexistent; directory contents of /$_g:"
  235.         ls -l /$_g
  236.         break
  237.       fi
  238.     done
  239.     shift
  240.   done
  241. }
  242.  
  243. find_culprits () {
  244.   #local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
  245.   #  msg
  246.  
  247.   reject_whitespace "$1"
  248.   message "Searching for overlapping packages..."
  249.   _dpkg_info_dir=/var/lib/dpkg/info
  250.   if [ -d $_dpkg_info_dir ]; then
  251.     if [ "$(echo $_dpkg_info_dir/*.list)" != "$_dpkg_info_dir/*.list" ]; then
  252.       _possible_culprits=$(ls -1 $_dpkg_info_dir/*.list | egrep -v \
  253.         "(xbase-clients|x11-common|xfs|xlibs)")
  254.       if [ -n "$_possible_culprits" ]; then
  255.         _smoking_guns=$(grep -l "$1" $_possible_culprits)
  256.         if [ -n "$_smoking_guns" ]; then
  257.           _bad_packages=$(printf "\\n")
  258.           for f in $_smoking_guns; do
  259.             # too bad you can't nest parameter expansion voodoo
  260.             p=${f%*.list}      # strip off the trailing ".list"
  261.             _package=${p##*/}   # strip off the directories
  262.             _bad_packages=$(printf "%s\n%s" "$_bad_packages" "$_package")
  263.           done
  264.           _msg=$(cat <<EOF
  265. The following packages appear to have file overlaps with the X.Org packages;
  266. these packages are either very old, or in violation of Debian Policy.  Try
  267. upgrading each of these packages to the latest available version if possible:
  268. for example, with the command "apt-get install".  If no newer version of a
  269. package is available, you will have to remove it; for example, with the command
  270. "apt-get remove".  If even the latest available version of the package has
  271. this file overlap, please file a bug against that package with the Debian Bug
  272. Tracking System.  You may want to refer the package maintainer to section 12.8
  273. of the Debian Policy manual.
  274. EOF
  275. )
  276.           message "$_msg"
  277.           message "The overlapping packages are: $_bad_packages"
  278.         else
  279.           message "no overlaps found."
  280.         fi
  281.       fi
  282.     else
  283.       message "cannot search; no matches for $_dpkg_info_dir/*.list."
  284.     fi
  285.   else
  286.     message "cannot search; $_dpkg_info_dir does not exist."
  287.   fi
  288. }
  289.  
  290. # we require a readlink command or shell function
  291. if ! which readlink > /dev/null 2>&1; then
  292.   message "The readlink command was not found.  Please install version" \
  293.           "1.13.1 or later of the debianutils package."
  294.   readlink () {
  295.     # returns what symlink in $1 actually points to
  296.     perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' "$1"
  297.   }
  298. fi
  299.  
  300. check_symlink () {
  301.   # syntax: check_symlink symlink
  302.   #
  303.   # See if specified symlink points where it is supposed to.  Return 0 if it
  304.   # does, and 1 if it does not.
  305.   #
  306.   # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
  307.  
  308.   #local symlink
  309.  
  310.   # validate arguments
  311.   if [ $# -ne 1 ]; then
  312.     usage_error "check_symlink() called with wrong number of arguments;" \
  313.                 "expected 1, got $#"
  314.     exit $SHELL_LIB_USAGE_ERROR
  315.   fi
  316.  
  317.   _symlink="$1"
  318.  
  319.   if [ "$(maplink "$_symlink")" = "$(readlink "$_symlink")" ]; then
  320.     return 0
  321.   else
  322.     return 1
  323.   fi
  324. }
  325.  
  326. check_symlinks_and_warn () {
  327.   # syntax: check_symlinks_and_warn symlink ...
  328.   #
  329.   # For each argument, check for symlink sanity, and warn if it isn't sane.
  330.   #
  331.   # Call this function from a preinst script in the event $1 is "upgrade" or
  332.   # "install".
  333.  
  334.   #local errmsg symlink
  335.  
  336.   # validate arguments
  337.   if [ $# -lt 1 ]; then
  338.     usage_error "check_symlinks_and_warn() called with wrong number of" \
  339.                 "arguments; expected at least 1, got $#"
  340.     exit $SHELL_LIB_USAGE_ERROR
  341.   fi
  342.  
  343.   while [ -n "$1" ]; do
  344.     _symlink="$1"
  345.     if [ -L "$_symlink" ]; then
  346.       if ! check_symlink "$_symlink"; then
  347.         observe "$_symlink symbolic link points to wrong location" \
  348.                 "$(readlink "$_symlink"); removing"
  349.         rm "$_symlink"
  350.       fi
  351.     elif [ -e "$_symlink" ]; then
  352.       _errmsg="$_symlink exists and is not a symbolic link; this package cannot"
  353.       _errmsg="$_errmsg be installed until this"
  354.       if [ -f "$_symlink" ]; then
  355.         _errmsg="$_errmsg file"
  356.       elif [ -d "$_symlink" ]; then
  357.         _errmsg="$_errmsg directory"
  358.       else
  359.         _errmsg="$_errmsg thing"
  360.       fi
  361.       _errmsg="$_errmsg is removed"
  362.       die "$_errmsg"
  363.     fi
  364.     shift
  365.   done
  366. }
  367.  
  368. check_symlinks_and_bomb () {
  369.   # syntax: check_symlinks_and_bomb symlink ...
  370.   #
  371.   # For each argument, check for symlink sanity, and bomb if it isn't sane.
  372.   #
  373.   # Call this function from a postinst script.
  374.  
  375.   #local problem symlink
  376.  
  377.   # validate arguments
  378.   if [ $# -lt 1 ]; then
  379.     usage_error "check_symlinks_and_bomb() called with wrong number of"
  380.                 "arguments; expected at least 1, got $#"
  381.     exit $SHELL_LIB_USAGE_ERROR
  382.   fi
  383.  
  384.   while [ -n "$1" ]; do
  385.     _problem=
  386.     _symlink="$1"
  387.     if [ -L "$_symlink" ]; then
  388.       if ! check_symlink "$_symlink"; then
  389.         _problem=yes
  390.         warn "$_symlink symbolic link points to wrong location" \
  391.              "$(readlink "$_symlink")"
  392.       fi
  393.     elif [ -e "$_symlink" ]; then
  394.       _problem=yes
  395.       warn "$_symlink is not a symbolic link"
  396.     else
  397.       _problem=yes
  398.       warn "$_symlink symbolic link does not exist"
  399.     fi
  400.     if [ -n "$_problem" ]; then
  401.       analyze_path "$_symlink" "$(readlink "$_symlink")"
  402.       find_culprits "$_symlink"
  403.       die "bad symbolic links on system"
  404.     fi
  405.     shift
  406.   done
  407. }
  408.  
  409. font_update () {
  410.   # run $UPDATECMDS in $FONTDIRS
  411.  
  412.   #local dir cmd shortcmd x_font_dir_prefix
  413.  
  414.   _x_font_dir_prefix="/usr/share/fonts/X11"
  415.  
  416.   if [ -z "$UPDATECMDS" ]; then
  417.     usage_error "font_update() called but \$UPDATECMDS not set"
  418.   fi
  419.   if [ -z "$FONTDIRS" ]; then
  420.     usage_error "font_update() called but \$FONTDIRS not set"
  421.   fi
  422.  
  423.   reject_unlikely_path_chars "$UPDATECMDS"
  424.   reject_unlikely_path_chars "$FONTDIRS"
  425.  
  426.   for _dir in $FONTDIRS; do
  427.     if [ -d "$_x_font_dir_prefix/$_dir" ]; then
  428.       for _cmd in $UPDATECMDS; do
  429.         if which "$_cmd" > /dev/null 2>&1; then
  430.           _shortcmd=${_cmd##*/}
  431.           observe "running $_shortcmd in $_dir font directory"
  432.       _cmd_opts=
  433.           if [ "$_shortcmd" = "update-fonts-alias" ]; then
  434.             _cmd_opts=--x11r7-layout
  435.           fi
  436.           if [ "$_shortcmd" = "update-fonts-dir" ]; then
  437.             _cmd_opts=--x11r7-layout
  438.           fi
  439.           if [ "$_shortcmd" = "update-fonts-scale" ]; then
  440.             _cmd_opts=--x11r7-layout
  441.           fi
  442.           $_cmd $_cmd_opts $_dir || warn "$_cmd $_cmd_opts $_dir" \
  443.                               "failed; font directory data may not" \
  444.                               "be up to date"
  445.         else
  446.           warn "$_cmd not found; not updating corresponding $_dir font" \
  447.                "directory data"
  448.         fi
  449.       done
  450.     else
  451.       warn "$_dir is not a directory; not updating font directory data"
  452.     fi
  453.   done
  454. }
  455.  
  456. remove_conffile_prepare () {
  457.   # syntax: remove_conffile_prepare filename official_md5sum ...
  458.   #
  459.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  460.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  461.   # operands provided, then prepare the conffile for removal from the system.
  462.   # We defer actual deletion until the package is configured so that we can
  463.   # roll this operation back if package installation fails.
  464.   #
  465.   # Call this function from a preinst script in the event $1 is "upgrade" or
  466.   # "install" and verify $2 to ensure the package is being upgraded from a
  467.   # version (or installed over a version removed-but-not-purged) prior to the
  468.   # one in which the conffile was obsoleted.
  469.  
  470.   #local conffile current_checksum
  471.  
  472.   # validate arguments
  473.   if [ $# -lt 2 ]; then
  474.     usage_error "remove_conffile_prepare() called with wrong number of" \
  475.                 "arguments; expected at least 2, got $#"
  476.     exit $SHELL_LIB_USAGE_ERROR
  477.   fi
  478.  
  479.   _conffile="$1"
  480.   shift
  481.  
  482.   # does the _conffile even exist?
  483.   if [ -e "$_conffile" ]; then
  484.     # calculate its checksum
  485.     _current_checksum=$(md5sum < "$_conffile" | sed 's/[[:space:]].*//')
  486.     # compare it to each supplied checksum
  487.     while [ -n "$1" ]; do
  488.       if [ "$_current_checksum" = "$1" ]; then
  489.         # we found a match; move the confffile and stop looking
  490.         observe "preparing obsolete conffile $_conffile for removal"
  491.         mv "$_conffile" "$_conffile.$THIS_PACKAGE-tmp"
  492.         break
  493.       fi
  494.       shift
  495.     done
  496.   fi
  497. }
  498.  
  499. remove_conffile_commit () {
  500.   # syntax: remove_conffile_commit filename
  501.   #
  502.   # Complete the removal of a conffile "filename" that has become obsolete.
  503.   #
  504.   # Call this function from a postinst script after having used
  505.   # remove_conffile_prepare() in the preinst.
  506.  
  507.   #local conffile
  508.  
  509.   # validate arguments
  510.   if [ $# -ne 1 ]; then
  511.     usage_error "remove_conffile_commit() called with wrong number of" \
  512.                 "arguments; expected 1, got $#"
  513.     exit $SHELL_LIB_USAGE_ERROR
  514.   fi
  515.  
  516.   _conffile="$1"
  517.  
  518.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  519.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  520.     observe "committing removal of obsolete conffile $_conffile"
  521.     rm "$_conffile.$THIS_PACKAGE-tmp"
  522.   fi
  523. }
  524.  
  525. remove_conffile_rollback () {
  526.   # syntax: remove_conffile_rollback filename
  527.   #
  528.   # Roll back the removal of a conffile "filename".
  529.   #
  530.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  531.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  532.   # preinst.
  533.  
  534.   #local conffile
  535.  
  536.   # validate arguments
  537.   if [ $# -ne 1 ]; then
  538.     usage_error "remove_conffile_rollback() called with wrong number of" \
  539.                 "arguments; expected 1, got $#"
  540.     exit $SHELL_LIB_USAGE_ERROR
  541.   fi
  542.  
  543.   _conffile="$1"
  544.  
  545.   # if the temporary file created by remove_conffile_prepare() exists, move it
  546.   # back
  547.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  548.     observe "rolling back removal of obsolete conffile $_conffile"
  549.     mv "$_conffile.$THIS_PACKAGE-tmp" "$_conffile"
  550.   fi
  551. }
  552.  
  553. replace_conffile_with_symlink_prepare () {
  554.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  555.   # official_md5sum ...
  556.   #
  557.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  558.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  559.   # operands provided, then prepare the conffile for removal from the system.
  560.   # We defer actual deletion until the package is configured so that we can
  561.   # roll this operation back if package installation fails. Otherwise copy it
  562.   # to newfilename and let dpkg handle it through conffiles mechanism.
  563.   #
  564.   # Call this function from a preinst script in the event $1 is "upgrade" or
  565.   # "install" and verify $2 to ensure the package is being upgraded from a
  566.   # version (or installed over a version removed-but-not-purged) prior to the
  567.   # one in which the conffile was obsoleted.
  568.  
  569.   #local conffile current_checksum
  570.  
  571.   # validate arguments
  572.   if [ $# -lt 3 ]; then
  573.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  574.                 " number of arguments; expected at least 3, got $#"
  575.     exit $SHELL_LIB_USAGE_ERROR
  576.   fi
  577.  
  578.   _oldconffile="$1"
  579.   shift
  580.   _newconffile="$1"
  581.   shift
  582.  
  583.   remove_conffile_prepare "$_oldconffile" "$@"
  584.   # If $_oldconffile still exists, then md5sums didn't match.
  585.   # Copy it to new one.
  586.   if [ -f "$_oldconffile" ]; then
  587.     cp "$_oldconffile" "$_newconffile"
  588.   fi
  589.  
  590. }
  591.  
  592. replace_conffile_with_symlink_commit () {
  593.   # syntax: replace_conffile_with_symlink_commit oldfilename
  594.   #
  595.   # Complete the removal of a conffile "oldfilename" that has been
  596.   # replaced by a symlink.
  597.   #
  598.   # Call this function from a postinst script after having used
  599.   # replace_conffile_with_symlink_prepare() in the preinst.
  600.  
  601.   #local conffile
  602.  
  603.   # validate arguments
  604.   if [ $# -ne 1 ]; then
  605.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  606.                 "number of arguments; expected 1, got $#"
  607.     exit $SHELL_LIB_USAGE_ERROR
  608.   fi
  609.  
  610.   _conffile="$1"
  611.  
  612.   remove_conffile_commit "$_conffile"
  613. }
  614.  
  615. replace_conffile_with_symlink_rollback () {
  616.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  617.   #
  618.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  619.   # "newfilename".
  620.   #
  621.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  622.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  623.   # from a version (or install over a version removed-but-not-purged) prior
  624.   # to the one in which the conffile was obsoleted.
  625.   # You should have  used replace_conffile_with_symlink_prepare() in the
  626.   # preinst.
  627.  
  628.   #local conffile
  629.  
  630.   # validate arguments
  631.   if [ $# -ne 2 ]; then
  632.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  633.                 "number of arguments; expected 2, got $#"
  634.     exit $SHELL_LIB_USAGE_ERROR
  635.   fi
  636.  
  637.   _oldconffile="$1"
  638.   _newconffile="$2"
  639.  
  640.   remove_conffile_rollback "$_oldconffile"
  641.   if [ -f "$_newconffile" ]; then
  642.     rm "$_newconffile"
  643.   fi
  644. }
  645.  
  646. run () {
  647.   # syntax: run command [ argument ... ]
  648.   #
  649.   # Run specified command with optional arguments and report its exit status.
  650.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  651.   # or commands whose failure is not fatal to us.
  652.   #
  653.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  654.   # those cases the return value of the debconf command *must* be checked
  655.   # before the string returned by debconf is used for anything.
  656.  
  657.   #local retval
  658.  
  659.   # validate arguments
  660.   if [ $# -lt 1 ]; then
  661.     usage_error "run() called with wrong number of arguments; expected at" \
  662.                 "least 1, got $#"
  663.     exit $SHELL_LIB_USAGE_ERROR
  664.   fi
  665.  
  666.   "$@" || _retval=$?
  667.  
  668.   if [ ${_retval:-0} -ne 0 ]; then
  669.     observe "command \"$*\" exited with status $_retval"
  670.   fi
  671. }
  672.  
  673. register_x_lib_dir_with_ld_so () {
  674.   # syntax: register_x_lib_dir_with_ld_so
  675.   #
  676.   # Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
  677.   # libraries.
  678.   #
  679.   # Call this function from the postinst script of a package that places a
  680.   # shared library in /usr/X11R6/lib, before invoking ldconfig.
  681.  
  682.   #local dir ldsoconf
  683.  
  684.   _dir="/usr/X11R6/lib"
  685.   _ldsoconf="/etc/ld.so.conf"
  686.  
  687.   # is the line not already present?
  688.   if ! fgrep -qsx "$_dir" "$_ldsoconf"; then
  689.     observe "adding $_dir directory to $_ldsoconf"
  690.     echo "$_dir" >> "$_ldsoconf"
  691.   fi
  692. }
  693.  
  694. deregister_x_lib_dir_with_ld_so () {
  695.   # syntax: deregister_x_lib_dir_with_ld_so
  696.   #
  697.   # Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
  698.   # libraries, if and only if no shared libaries remain there.
  699.   #
  700.   # Call this function from the postrm script of a package that places a shared
  701.   # library in /usr/X11R6/lib, in the event "$1" is "remove", and before
  702.   # invoking ldconfig.
  703.  
  704.   #local dir ldsoconf fgrep_status cmp_status
  705.  
  706.   _dir="/usr/X11R6/lib"
  707.   _ldsoconf="/etc/ld.so.conf"
  708.  
  709.   # is the line present?
  710.   if fgrep -qsx "$_dir" "$_ldsoconf"; then
  711.     # are there any shared objects in the directory?
  712.     if [ "$(echo "$_dir"/lib*.so.*.*)" = "$_dir/lib*.so.*.*" ]; then
  713.       # glob expansion produced nothing, so no shared libraries are present
  714.       observe "removing $_dir directory from $_ldsoconf"
  715.       # rewrite the file (very carefully)
  716.       set +e
  717.       fgrep -svx "$_dir" "$_ldsoconf" > "$_ldsoconf.dpkg-tmp"
  718.       _fgrep_status=$?
  719.       set -e
  720.       case $_fgrep_status in
  721.         0|1) ;; # we don't actually care if any lines matched or not
  722.         *) die "error reading \"$_ldsoconf\"; fgrep exited with status" \
  723.           "$_fgrep_status" ;;
  724.       esac
  725.       set +e
  726.       cmp -s "$_ldsoconf.dpkg-tmp" "$_ldsoconf"
  727.       _cmp_status=$?
  728.       set -e
  729.       case $_cmp_status in
  730.         0) rm "$_ldsoconf.dpkg-tmp" ;; # files are identical
  731.         1) mv "$_ldsoconf.dpkg-tmp" "$_ldsoconf" ;; # files differ
  732.         *) die "error comparing \"$_ldsoconf.dpkg-tmp\" to \"$_ldsoconf\";" \
  733.           "cmp exited with status $_cmp_status" ;;
  734.       esac
  735.     fi
  736.   fi
  737. }
  738.  
  739. make_symlink_sane () {
  740.   # syntax: make_symlink_sane symlink target
  741.   #
  742.   # Ensure that the symbolic link symlink exists, and points to target.
  743.   #
  744.   # If symlink does not exist, create it and point it at target.
  745.   #
  746.   # If symlink exists but is not a symbolic link, back it up.
  747.   #
  748.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  749.   # it.
  750.   #
  751.   # If symlink exists, is a symbolic link, and already points to target, do
  752.   # nothing.
  753.   #
  754.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  755.  
  756.   # Validate arguments.
  757.   if [ $# -ne 2 ]; then
  758.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  759.       "expected 2, got $#"
  760.     exit $SHELL_LIB_USAGE_ERROR
  761.   fi
  762.  
  763.   # We could just use the positional parameters as-is, but that makes things
  764.   # harder to follow.
  765.   #local symlink target
  766.  
  767.   _symlink="$1"
  768.   _target="$2"
  769.  
  770.   if [ -L "$_symlink" ] && [ "$(readlink "$_symlink")" = "$_target" ]; then
  771.       observe "link from $_symlink to $_target already exists"
  772.   else
  773.     observe "creating symbolic link from $_symlink to $_target"
  774.     mkdir -p "${_target%/*}" "${_symlink%/*}"
  775.     ln -s -b -S ".dpkg-old" "$_target" "$_symlink"
  776.   fi
  777. }
  778.  
  779. migrate_dir_to_symlink () {
  780.   # syntax: migrate_dir_to_symlink old_location new_location
  781.   #
  782.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  783.   # symbolic link to a directory or vice versa; instead, the existing state
  784.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  785.   # there is one."
  786.   #
  787.   # We have to do it ourselves.
  788.   #
  789.   # This function moves the contents of old_location, a directory, into
  790.   # new_location, a directory, then makes old_location a symbolic link to
  791.   # new_location.
  792.   #
  793.   # old_location need not exist, but if it does, it must be a directory (or a
  794.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  795.   # exists already and is not a directory, it is backed up.
  796.   #
  797.   # This function should be called from a package's preinst so that other
  798.   # packages unpacked after this one --- but before this package's postinst runs
  799.   # --- are unpacked into new_location even if their payloads contain
  800.   # old_location filespecs.
  801.  
  802.   # Validate arguments.
  803.   if [ $# -ne 2 ]; then
  804.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  805.                 "arguments; expected 2, got $#"
  806.     exit $SHELL_LIB_USAGE_ERROR
  807.   fi
  808.  
  809.   # We could just use the positional parameters as-is, but that makes things
  810.   # harder to follow.
  811.   local _new _old
  812.  
  813.   _old="$1"
  814.   _new="$2"
  815.  
  816.   # Is old location a symlink?
  817.   if [ -L "$_old" ]; then
  818.     # Does it already point to new location?
  819.     if [ "$(readlink "$_old")" = "$_new" ]; then
  820.       # Nothing to do; migration has already been done.
  821.       observe "migration of $_old to $_new already done"
  822.       return 0
  823.     else
  824.       # Back it up.
  825.       warn "backing up symbolic link $_old as $_old.dpkg-old"
  826.       mv -b "$_old" "$_old.dpkg-old"
  827.     fi
  828.   fi
  829.  
  830.   # Does old location exist, but is not a directory?
  831.   if [ -e "$_old" ] && ! [ -d "$_old" ]; then
  832.       # Back it up.
  833.       warn "backing up non-directory $_old as $_old.dpkg-old"
  834.       mv -b "$_old" "$_old.dpkg-old"
  835.   fi
  836.  
  837.   observe "migrating $_old to $_new"
  838.  
  839.   # Is new location a symlink?
  840.   if [ -L "$_new" ]; then
  841.     # Does it point the wrong way, i.e., back to where we're migrating from?
  842.     if [ "$(readlink "$_new")" = "$_old" ]; then
  843.       # Get rid of it.
  844.       observe "removing symbolic link $_new which points to $_old"
  845.       rm "$_new"
  846.     else
  847.       # Back it up.
  848.       warn "backing up symbolic link $_new as $_new.dpkg-old"
  849.       mv -b "$_new" "$_new.dpkg-old"
  850.     fi
  851.   fi
  852.  
  853.   # Does new location exist, but is not a directory?
  854.   if [ -e "$_new" ] && ! [ -d "$_new" ]; then
  855.     warn "backing up non-directory $_new as $_new.dpkg-old"
  856.     mv -b "$_new" "$_new.dpkg-old"
  857.   fi
  858.  
  859.   # Create new directory if it does not yet exist.
  860.   if ! [ -e "$_new" ]; then
  861.     observe "creating $_new"
  862.     mkdir -p "$_new"
  863.   fi
  864.  
  865.   # Copy files in old location to new location.  Back up any filenames that
  866.   # already exist in the new location with the extension ".dpkg-old".
  867.   observe "copying files from $_old to $_new"
  868.   if ! (cd "$_old" && cp -a -b -S ".dpkg-old" . "$_new"); then
  869.     die "error(s) encountered while copying files from $_old to $_new"
  870.   fi
  871.  
  872.   # Remove files at old location.
  873.   observe "removing $_old"
  874.   rm -r "$_old"
  875.  
  876.   # Create symlink from old location to new location.
  877.   make_symlink_sane "$_old" "$_new"
  878. }
  879.  
  880. # vim:set ai et sts=2 sw=2 tw=80:
  881.  
  882. # register available X cursor themes with update-alternatives
  883. update-alternatives --install /usr/share/icons/default/index.theme \
  884.                               x-cursor-theme /etc/X11/cursors/core.theme 30
  885. for THEME in redglass whiteglass handhelds; do
  886.   update-alternatives --install /usr/share/icons/default/index.theme \
  887.                                 x-cursor-theme "/etc/X11/cursors/$THEME.theme" \
  888.                                 20
  889. done
  890.  
  891.  
  892.  
  893. exit 0
  894.  
  895. # vim:set ai et sts=2 sw=2 tw=0:
  896.