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.prerm < prev    next >
Encoding:
Text File  |  2006-08-04  |  29.0 KB  |  896 lines

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