~ubuntu-branches/ubuntu/utopic/xdm/utopic

« back to all changes in this revision

Viewing changes to debian/xdm.postinst

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2005-09-08 09:43:15 UTC
  • Revision ID: james.westby@ubuntu.com-20050908094315-gsz39ui3k1xe1ydd
Tags: 1:0.99.1-3
* Run proper debconf-po stuff.

* Fix maintainer scripts for the new X layout

(Closes: #14412)

Show diffs side-by-side

added added

removed removed

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