~ubuntu-branches/ubuntu/maverick/xf86-input-evtouch/maverick-proposed

« back to all changes in this revision

Viewing changes to debian/xsfbs/xsfbs.sh

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker
  • Date: 2010-06-13 16:12:44 UTC
  • mfrom: (6.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100613161244-ko28amhhplmcluku
Tags: 0.8.8-4fakesync1
Fake sync due to mismatching orig tarball (LP: #589535).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id$
2
 
 
3
1
# This is the X Strike Force shell library for X Window System package
4
2
# maintainer scripts.  It serves to define shell functions commonly used by
5
3
# such packages, and performs some error checking necessary for proper operation
8
6
# removal tasks.
9
7
 
10
8
# If you are reading this within a Debian package maintainer script (e.g.,
11
 
# /var/lib/dpkg)info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
 
9
# /var/lib/dpkg/info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
12
10
# skip past this library by scanning forward in this file to the string
13
11
# "GOBSTOPPER".
14
12
 
57
55
  exit $SHELL_LIB_USAGE_ERROR
58
56
fi
59
57
 
60
 
ARCHITECTURE="$(dpkg --print-installation-architecture)"
61
 
 
62
58
if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
63
59
  RECONFIGURE="true"
64
60
else
95
91
  done
96
92
}
97
93
 
98
 
reject_whitespace () {
99
 
  # syntax: reject_whitespace [ operand ]
100
 
  #
101
 
  # scan operand (typically a shell variable whose value cannot be trusted) for
102
 
  # whitespace characters and barf if any are found
103
 
  if [ -n "$1" ]; then
104
 
    # does the operand contain any whitespace?
105
 
    if expr "$1" : "[[:space:]]" > /dev/null 2>&1; then
106
 
      # can't use die(), because I want to avoid forward references
107
 
      echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_whitespace() encountered" \
108
 
           "possibly malicious garbage \"$1\"" >&2
109
 
      exit $SHELL_LIB_THROWN_ERROR
110
 
    fi
111
 
  fi
112
 
}
113
 
 
114
94
reject_unlikely_path_chars () {
115
95
  # syntax: reject_unlikely_path_chars [ operand ... ]
116
96
  #
201
181
  exit $SHELL_LIB_USAGE_ERROR
202
182
}
203
183
 
204
 
 
205
 
maplink () {
206
 
  # returns what symlink should point to; i.e., what the "sane" answer is
207
 
  # Keep this in sync with the debian/*.links files.
208
 
  # This is only needed for symlinks to directories.
209
 
  #
210
 
  # XXX: Most of these look wrong in the X11R7 world and need to be fixed.
211
 
  # If we've stopped using this function, fixing it might enable us to re-enable
212
 
  # it again and catch more errors.
213
 
  case "$1" in
214
 
    /etc/X11/xkb/compiled) echo /var/lib/xkb ;;
215
 
    /etc/X11/xkb/xkbcomp) echo /usr/X11R6/bin/xkbcomp ;;
216
 
    /usr/X11R6/lib/X11/app-defaults) echo /etc/X11/app-defaults ;;
217
 
    /usr/X11R6/lib/X11/fs) echo /etc/X11/fs ;;
218
 
    /usr/X11R6/lib/X11/lbxproxy) echo /etc/X11/lbxproxy ;;
219
 
    /usr/X11R6/lib/X11/proxymngr) echo /etc/X11/proxymngr ;;
220
 
    /usr/X11R6/lib/X11/rstart) echo /etc/X11/rstart ;;
221
 
    /usr/X11R6/lib/X11/twm) echo /etc/X11/twm ;;
222
 
    /usr/X11R6/lib/X11/xdm) echo /etc/X11/xdm ;;
223
 
    /usr/X11R6/lib/X11/xinit) echo /etc/X11/xinit ;;
224
 
    /usr/X11R6/lib/X11/xkb) echo /etc/X11/xkb ;;
225
 
    /usr/X11R6/lib/X11/xserver) echo /etc/X11/xserver ;;
226
 
    /usr/X11R6/lib/X11/xsm) echo /etc/X11/xsm ;;
227
 
    /usr/bin/X11) echo ../X11R6/bin ;;
228
 
    /usr/bin/rstartd) echo ../X11R6/bin/rstartd ;;
229
 
    /usr/include/X11) echo ../X11R6/include/X11 ;;
230
 
    /usr/lib/X11) echo ../X11R6/lib/X11 ;;
231
 
    *) internal_error "maplink() called with unknown path \"$1\"" ;;
232
 
  esac
233
 
}
234
 
 
235
 
analyze_path () {
236
 
  # given a supplied set of pathnames, break each one up by directory and do an
237
 
  # ls -dl on each component, cumulatively; i.e.
238
 
  # analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
239
 
  # Thanks to Randolph Chung for this clever hack.
240
 
 
241
 
  local f g
242
 
 
243
 
  while [ -n "$1" ]; do
244
 
    reject_whitespace "$1"
245
 
    g=
246
 
    message "Analyzing $1:"
247
 
    for f in $(echo "$1" | tr / \  ); do
248
 
      if [ -e /$g$f ]; then
249
 
        ls -dl /$g$f /$g$f.dpkg-* 2> /dev/null || true
250
 
        g=$g$f/
251
 
      else
252
 
        message "/$g$f: nonexistent; directory contents of /$g:"
253
 
        ls -l /$g
254
 
        break
255
 
      fi
256
 
    done
257
 
    shift
258
 
  done
259
 
}
260
 
 
261
 
find_culprits () {
262
 
  local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
263
 
    msg
264
 
 
265
 
  reject_whitespace "$1"
266
 
  message "Searching for overlapping packages..."
267
 
  dpkg_info_dir=/var/lib/dpkg/info
268
 
  if [ -d $dpkg_info_dir ]; then
269
 
    if [ "$(echo $dpkg_info_dir/*.list)" != "$dpkg_info_dir/*.list" ]; then
270
 
      possible_culprits=$(ls -1 $dpkg_info_dir/*.list | egrep -v \
271
 
        "(xbase-clients|x11-common|xfs|xlibs)")
272
 
      if [ -n "$possible_culprits" ]; then
273
 
        smoking_guns=$(grep -l "$1" $possible_culprits || true)
274
 
        if [ -n "$smoking_guns" ]; then
275
 
          bad_packages=$(printf "\\n")
276
 
          for f in $smoking_guns; do
277
 
            # too bad you can't nest parameter expansion voodoo
278
 
            p=${f%*.list}      # strip off the trailing ".list"
279
 
            package=${p##*/}   # strip off the directories
280
 
            bad_packages=$(printf "%s\n%s" "$bad_packages" "$package")
281
 
          done
282
 
          msg=$(cat <<EOF
283
 
The following packages appear to have file overlaps with the X.Org packages;
284
 
these packages are either very old, or in violation of Debian Policy.  Try
285
 
upgrading each of these packages to the latest available version if possible:
286
 
for example, with the command "apt-get install".  If no newer version of a
287
 
package is available, you will have to remove it; for example, with the command
288
 
"apt-get remove".  If even the latest available version of the package has
289
 
this file overlap, please file a bug against that package with the Debian Bug
290
 
Tracking System.  You may want to refer the package maintainer to section 12.8
291
 
of the Debian Policy manual.
292
 
EOF
293
 
)
294
 
          message "$msg"
295
 
          message "The overlapping packages are: $bad_packages"
296
 
        else
297
 
          message "no overlaps found."
298
 
        fi
299
 
      fi
300
 
    else
301
 
      message "cannot search; no matches for $dpkg_info_dir/*.list."
302
 
    fi
303
 
  else
304
 
    message "cannot search; $dpkg_info_dir does not exist."
305
 
  fi
306
 
}
307
 
 
308
 
# we require a readlink command or shell function
309
 
if ! which readlink > /dev/null 2>&1; then
310
 
  message "The readlink command was not found.  Please install version" \
311
 
          "1.13.1 or later of the debianutils package."
312
 
  readlink () {
313
 
    # returns what symlink in $1 actually points to
314
 
    perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' "$1"
315
 
  }
316
 
fi
317
 
 
318
 
check_symlink () {
319
 
  # syntax: check_symlink symlink
320
 
  #
321
 
  # See if specified symlink points where it is supposed to.  Return 0 if it
322
 
  # does, and 1 if it does not.
323
 
  #
324
 
  # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
325
 
 
326
 
  local symlink
327
 
 
328
 
  # validate arguments
329
 
  if [ $# -ne 1 ]; then
330
 
    usage_error "check_symlink() called with wrong number of arguments;" \
331
 
                "expected 1, got $#"
332
 
    exit $SHELL_LIB_USAGE_ERROR
333
 
  fi
334
 
 
335
 
  symlink="$1"
336
 
 
337
 
  if [ "$(maplink "$symlink")" = "$(readlink "$symlink")" ]; then
338
 
    return 0
339
 
  else
340
 
    return 1
341
 
  fi
342
 
}
343
 
 
344
 
check_symlinks_and_warn () {
345
 
  # syntax: check_symlinks_and_warn symlink ...
346
 
  #
347
 
  # For each argument, check for symlink sanity, and warn if it isn't sane.
348
 
  #
349
 
  # Call this function from a preinst script in the event $1 is "upgrade" or
350
 
  # "install".
351
 
 
352
 
  local errmsg symlink
353
 
 
354
 
  # validate arguments
355
 
  if [ $# -lt 1 ]; then
356
 
    usage_error "check_symlinks_and_warn() called with wrong number of" \
357
 
                "arguments; expected at least 1, got $#"
358
 
    exit $SHELL_LIB_USAGE_ERROR
359
 
  fi
360
 
 
361
 
  while [ -n "$1" ]; do
362
 
    symlink="$1"
363
 
    if [ -L "$symlink" ]; then
364
 
      if ! check_symlink "$symlink"; then
365
 
        observe "$symlink symbolic link points to wrong location" \
366
 
                "$(readlink "$symlink"); removing"
367
 
        rm "$symlink"
368
 
      fi
369
 
    elif [ -e "$symlink" ]; then
370
 
      errmsg="$symlink exists and is not a symbolic link; this package cannot"
371
 
      errmsg="$errmsg be installed until this"
372
 
      if [ -f "$symlink" ]; then
373
 
        errmsg="$errmsg file"
374
 
      elif [ -d "$symlink" ]; then
375
 
        errmsg="$errmsg directory"
376
 
      else
377
 
        errmsg="$errmsg thing"
378
 
      fi
379
 
      errmsg="$errmsg is removed"
380
 
      die "$errmsg"
381
 
    fi
382
 
    shift
383
 
  done
384
 
}
385
 
 
386
 
check_symlinks_and_bomb () {
387
 
  # syntax: check_symlinks_and_bomb symlink ...
388
 
  #
389
 
  # For each argument, check for symlink sanity, and bomb if it isn't sane.
390
 
  #
391
 
  # Call this function from a postinst script.
392
 
 
393
 
  local problem symlink
394
 
 
395
 
  # validate arguments
396
 
  if [ $# -lt 1 ]; then
397
 
    usage_error "check_symlinks_and_bomb() called with wrong number of"
398
 
                "arguments; expected at least 1, got $#"
399
 
    exit $SHELL_LIB_USAGE_ERROR
400
 
  fi
401
 
 
402
 
  while [ -n "$1" ]; do
403
 
    problem=
404
 
    symlink="$1"
405
 
    if [ -L "$symlink" ]; then
406
 
      if ! check_symlink "$symlink"; then
407
 
        problem=yes
408
 
        warn "$symlink symbolic link points to wrong location" \
409
 
             "$(readlink "$symlink")"
410
 
      fi
411
 
    elif [ -e "$symlink" ]; then
412
 
      problem=yes
413
 
      warn "$symlink is not a symbolic link"
414
 
    else
415
 
      problem=yes
416
 
      warn "$symlink symbolic link does not exist"
417
 
    fi
418
 
    if [ -n "$problem" ]; then
419
 
      analyze_path "$symlink" "$(readlink "$symlink")"
420
 
      find_culprits "$symlink"
421
 
      die "bad symbolic links on system"
422
 
    fi
423
 
    shift
424
 
  done
425
 
}
426
 
 
427
184
font_update () {
428
185
  # run $UPDATECMDS in $FONTDIRS
429
186
 
719
476
  fi
720
477
}
721
478
 
722
 
register_x_lib_dir_with_ld_so () {
723
 
  # syntax: register_x_lib_dir_with_ld_so
724
 
  #
725
 
  # Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
726
 
  # libraries.
727
 
  #
728
 
  # Call this function from the postinst script of a package that places a
729
 
  # shared library in /usr/X11R6/lib, before invoking ldconfig.
730
 
 
731
 
  local dir ldsoconf
732
 
 
733
 
  dir="/usr/X11R6/lib"
734
 
  ldsoconf="/etc/ld.so.conf"
735
 
 
736
 
  # is the line not already present?
737
 
  if ! fgrep -qsx "$dir" "$ldsoconf"; then
738
 
    observe "adding $dir directory to $ldsoconf"
739
 
    echo "$dir" >> "$ldsoconf"
740
 
  fi
741
 
}
742
 
 
743
 
deregister_x_lib_dir_with_ld_so () {
744
 
  # syntax: deregister_x_lib_dir_with_ld_so
745
 
  #
746
 
  # Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
747
 
  # libraries, if and only if no shared libaries remain there.
748
 
  #
749
 
  # Call this function from the postrm script of a package that places a shared
750
 
  # library in /usr/X11R6/lib, in the event "$1" is "remove", and before
751
 
  # invoking ldconfig.
752
 
 
753
 
  local dir ldsoconf fgrep_status cmp_status
754
 
 
755
 
  dir="/usr/X11R6/lib"
756
 
  ldsoconf="/etc/ld.so.conf"
757
 
 
758
 
  # is the line present?
759
 
  if fgrep -qsx "$dir" "$ldsoconf"; then
760
 
    # are there any shared objects in the directory?
761
 
    if [ "$(echo "$dir"/lib*.so.*.*)" = "$dir/lib*.so.*.*" ]; then
762
 
      # glob expansion produced nothing, so no shared libraries are present
763
 
      observe "removing $dir directory from $ldsoconf"
764
 
      # rewrite the file (very carefully)
765
 
      set +e
766
 
      fgrep -svx "$dir" "$ldsoconf" > "$ldsoconf.dpkg-tmp"
767
 
      fgrep_status=$?
768
 
      set -e
769
 
      case $fgrep_status in
770
 
        0|1) ;; # we don't actually care if any lines matched or not
771
 
        *) die "error reading \"$ldsoconf\"; fgrep exited with status" \
772
 
          "$fgrep_status" ;;
773
 
      esac
774
 
      set +e
775
 
      cmp -s "$ldsoconf.dpkg-tmp" "$ldsoconf"
776
 
      cmp_status=$?
777
 
      set -e
778
 
      case $cmp_status in
779
 
        0) rm "$ldsoconf.dpkg-tmp" ;; # files are identical
780
 
        1) mv "$ldsoconf.dpkg-tmp" "$ldsoconf" ;; # files differ
781
 
        *) die "error comparing \"$ldsoconf.dpkg-tmp\" to \"$ldsoconf\";" \
782
 
          "cmp exited with status $cmp_status" ;;
783
 
      esac
784
 
    fi
785
 
  fi
786
 
}
787
 
 
788
479
make_symlink_sane () {
789
480
  # syntax: make_symlink_sane symlink target
790
481
  #