~ubuntu-branches/ubuntu/precise/x11proto-gl/precise-security

« back to all changes in this revision

Viewing changes to debian/xsfbs/xsfbs.sh

  • Committer: Bazaar Package Importer
  • Author(s): Julien Cristau
  • Date: 2009-06-08 17:30:57 UTC
  • mfrom: (0.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090608173057-x0dyudsi6uztcqak
Tags: 1.4.10-1
* All the code under the GLX Public License has been made available under
  the SGI Free Software License B, so remove GLXPL from debian/copyright.
* New upstream release.
* Run autoreconf on build.
* Drop XS- prefix from Vcs fields in debian/control.
* Add README.source, bump Standards-Version to 3.8.1.
* Remove Branden from Uploaders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
  exit $SHELL_LIB_USAGE_ERROR
58
58
fi
59
59
 
60
 
ARCHITECTURE="$(dpkg --print-installation-architecture)"
61
 
 
62
60
if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
63
61
  RECONFIGURE="true"
64
62
else
238
236
  # analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
239
237
  # Thanks to Randolph Chung for this clever hack.
240
238
 
241
 
  #local f g
 
239
  local f g
242
240
 
243
241
  while [ -n "$1" ]; do
244
242
    reject_whitespace "$1"
245
 
    _g=
 
243
    g=
246
244
    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/
 
245
    for f in $(echo "$1" | tr / \  ); do
 
246
      if [ -e /$g$f ]; then
 
247
        ls -dl /$g$f /$g$f.dpkg-* 2> /dev/null || true
 
248
        g=$g$f/
251
249
      else
252
 
        message "/$_g$_f: nonexistent; directory contents of /$_g:"
253
 
        ls -l /$_g
 
250
        message "/$g$f: nonexistent; directory contents of /$g:"
 
251
        ls -l /$g
254
252
        break
255
253
      fi
256
254
    done
259
257
}
260
258
 
261
259
find_culprits () {
262
 
  #local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
263
 
  #  msg
 
260
  local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
 
261
    msg
264
262
 
265
263
  reject_whitespace "$1"
266
264
  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 \
 
265
  dpkg_info_dir=/var/lib/dpkg/info
 
266
  if [ -d $dpkg_info_dir ]; then
 
267
    if [ "$(echo $dpkg_info_dir/*.list)" != "$dpkg_info_dir/*.list" ]; then
 
268
      possible_culprits=$(ls -1 $dpkg_info_dir/*.list | egrep -v \
271
269
        "(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
 
270
      if [ -n "$possible_culprits" ]; then
 
271
        smoking_guns=$(grep -l "$1" $possible_culprits || true)
 
272
        if [ -n "$smoking_guns" ]; then
 
273
          bad_packages=$(printf "\\n")
 
274
          for f in $smoking_guns; do
277
275
            # too bad you can't nest parameter expansion voodoo
278
276
            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")
 
277
            package=${p##*/}   # strip off the directories
 
278
            bad_packages=$(printf "%s\n%s" "$bad_packages" "$package")
281
279
          done
282
 
          _msg=$(cat <<EOF
 
280
          msg=$(cat <<EOF
283
281
The following packages appear to have file overlaps with the X.Org packages;
284
282
these packages are either very old, or in violation of Debian Policy.  Try
285
283
upgrading each of these packages to the latest available version if possible:
291
289
of the Debian Policy manual.
292
290
EOF
293
291
)
294
 
          message "$_msg"
295
 
          message "The overlapping packages are: $_bad_packages"
 
292
          message "$msg"
 
293
          message "The overlapping packages are: $bad_packages"
296
294
        else
297
295
          message "no overlaps found."
298
296
        fi
299
297
      fi
300
298
    else
301
 
      message "cannot search; no matches for $_dpkg_info_dir/*.list."
 
299
      message "cannot search; no matches for $dpkg_info_dir/*.list."
302
300
    fi
303
301
  else
304
 
    message "cannot search; $_dpkg_info_dir does not exist."
 
302
    message "cannot search; $dpkg_info_dir does not exist."
305
303
  fi
306
304
}
307
305
 
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
306
check_symlink () {
319
307
  # syntax: check_symlink symlink
320
308
  #
323
311
  #
324
312
  # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
325
313
 
326
 
  #local symlink
 
314
  local symlink
327
315
 
328
316
  # validate arguments
329
317
  if [ $# -ne 1 ]; then
332
320
    exit $SHELL_LIB_USAGE_ERROR
333
321
  fi
334
322
 
335
 
  _symlink="$1"
 
323
  symlink="$1"
336
324
 
337
 
  if [ "$(maplink "$_symlink")" = "$(readlink "$_symlink")" ]; then
 
325
  if [ "$(maplink "$symlink")" = "$(readlink "$symlink")" ]; then
338
326
    return 0
339
327
  else
340
328
    return 1
349
337
  # Call this function from a preinst script in the event $1 is "upgrade" or
350
338
  # "install".
351
339
 
352
 
  #local errmsg symlink
 
340
  local errmsg symlink
353
341
 
354
342
  # validate arguments
355
343
  if [ $# -lt 1 ]; then
359
347
  fi
360
348
 
361
349
  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"
 
350
    symlink="$1"
 
351
    if [ -L "$symlink" ]; then
 
352
      if ! check_symlink "$symlink"; then
 
353
        observe "$symlink symbolic link points to wrong location" \
 
354
                "$(readlink "$symlink"); removing"
 
355
        rm "$symlink"
368
356
      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"
 
357
    elif [ -e "$symlink" ]; then
 
358
      errmsg="$symlink exists and is not a symbolic link; this package cannot"
 
359
      errmsg="$errmsg be installed until this"
 
360
      if [ -f "$symlink" ]; then
 
361
        errmsg="$errmsg file"
 
362
      elif [ -d "$symlink" ]; then
 
363
        errmsg="$errmsg directory"
376
364
      else
377
 
        _errmsg="$_errmsg thing"
 
365
        errmsg="$errmsg thing"
378
366
      fi
379
 
      _errmsg="$_errmsg is removed"
380
 
      die "$_errmsg"
 
367
      errmsg="$errmsg is removed"
 
368
      die "$errmsg"
381
369
    fi
382
370
    shift
383
371
  done
390
378
  #
391
379
  # Call this function from a postinst script.
392
380
 
393
 
  #local problem symlink
 
381
  local problem symlink
394
382
 
395
383
  # validate arguments
396
384
  if [ $# -lt 1 ]; then
400
388
  fi
401
389
 
402
390
  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")"
 
391
    problem=
 
392
    symlink="$1"
 
393
    if [ -L "$symlink" ]; then
 
394
      if ! check_symlink "$symlink"; then
 
395
        problem=yes
 
396
        warn "$symlink symbolic link points to wrong location" \
 
397
             "$(readlink "$symlink")"
410
398
      fi
411
 
    elif [ -e "$_symlink" ]; then
412
 
      _problem=yes
413
 
      warn "$_symlink is not a symbolic link"
 
399
    elif [ -e "$symlink" ]; then
 
400
      problem=yes
 
401
      warn "$symlink is not a symbolic link"
414
402
    else
415
 
      _problem=yes
416
 
      warn "$_symlink symbolic link does not exist"
 
403
      problem=yes
 
404
      warn "$symlink symbolic link does not exist"
417
405
    fi
418
 
    if [ -n "$_problem" ]; then
419
 
      analyze_path "$_symlink" "$(readlink "$_symlink")"
420
 
      find_culprits "$_symlink"
 
406
    if [ -n "$problem" ]; then
 
407
      analyze_path "$symlink" "$(readlink "$symlink")"
 
408
      find_culprits "$symlink"
421
409
      die "bad symbolic links on system"
422
410
    fi
423
411
    shift
427
415
font_update () {
428
416
  # run $UPDATECMDS in $FONTDIRS
429
417
 
430
 
  #local dir cmd shortcmd x_font_dir_prefix
 
418
  local dir cmd shortcmd x_font_dir_prefix
431
419
 
432
 
  _x_font_dir_prefix="/usr/share/fonts/X11"
 
420
  x_font_dir_prefix="/usr/share/fonts/X11"
433
421
 
434
422
  if [ -z "$UPDATECMDS" ]; then
435
423
    usage_error "font_update() called but \$UPDATECMDS not set"
441
429
  reject_unlikely_path_chars "$UPDATECMDS"
442
430
  reject_unlikely_path_chars "$FONTDIRS"
443
431
 
444
 
  for _dir in $FONTDIRS; do
445
 
    if [ -d "$_x_font_dir_prefix/$_dir" ]; then
446
 
      for _cmd in $UPDATECMDS; do
447
 
        if which "$_cmd" > /dev/null 2>&1; then
448
 
          _shortcmd=${_cmd##*/}
449
 
          observe "running $_shortcmd in $_dir font directory"
450
 
          _cmd_opts=
451
 
          if [ "$_shortcmd" = "update-fonts-alias" ]; then
452
 
            _cmd_opts=--x11r7-layout
453
 
          fi
454
 
          if [ "$_shortcmd" = "update-fonts-dir" ]; then
455
 
            _cmd_opts=--x11r7-layout
456
 
          fi
457
 
          if [ "$_shortcmd" = "update-fonts-scale" ]; then
458
 
            _cmd_opts=--x11r7-layout
459
 
          fi
460
 
          $_cmd $_cmd_opts $_dir || warn "$_cmd $_cmd_opts $_dir" \
 
432
  for dir in $FONTDIRS; do
 
433
    if [ -d "$x_font_dir_prefix/$dir" ]; then
 
434
      for cmd in $UPDATECMDS; do
 
435
        if which "$cmd" > /dev/null 2>&1; then
 
436
          shortcmd=${cmd##*/}
 
437
          observe "running $shortcmd in $dir font directory"
 
438
          cmd_opts=
 
439
          if [ "$shortcmd" = "update-fonts-alias" ]; then
 
440
            cmd_opts=--x11r7-layout
 
441
          fi
 
442
          if [ "$shortcmd" = "update-fonts-dir" ]; then
 
443
            cmd_opts=--x11r7-layout
 
444
          fi
 
445
          if [ "$shortcmd" = "update-fonts-scale" ]; then
 
446
            cmd_opts=--x11r7-layout
 
447
          fi
 
448
          $cmd $cmd_opts $dir || warn "$cmd $cmd_opts $dir" \
461
449
                              "failed; font directory data may not" \
462
450
                              "be up to date"
463
451
        else
464
 
          warn "$_cmd not found; not updating corresponding $_dir font" \
 
452
          warn "$cmd not found; not updating corresponding $dir font" \
465
453
               "directory data"
466
454
        fi
467
455
      done
468
456
    else
469
 
      warn "$_dir is not a directory; not updating font directory data"
 
457
      warn "$dir is not a directory; not updating font directory data"
470
458
    fi
471
459
  done
472
460
}
485
473
  # version (or installed over a version removed-but-not-purged) prior to the
486
474
  # one in which the conffile was obsoleted.
487
475
 
488
 
  #local conffile current_checksum
 
476
  local conffile current_checksum
489
477
 
490
478
  # validate arguments
491
479
  if [ $# -lt 2 ]; then
494
482
    exit $SHELL_LIB_USAGE_ERROR
495
483
  fi
496
484
 
497
 
  _conffile="$1"
 
485
  conffile="$1"
498
486
  shift
499
487
 
500
 
  # does the _conffile even exist?
501
 
  if [ -e "$_conffile" ]; then
 
488
  # does the conffile even exist?
 
489
  if [ -e "$conffile" ]; then
502
490
    # calculate its checksum
503
 
    _current_checksum=$(md5sum < "$_conffile" | sed 's/[[:space:]].*//')
 
491
    current_checksum=$(md5sum < "$conffile" | sed 's/[[:space:]].*//')
504
492
    # compare it to each supplied checksum
505
493
    while [ -n "$1" ]; do
506
 
      if [ "$_current_checksum" = "$1" ]; then
 
494
      if [ "$current_checksum" = "$1" ]; then
507
495
        # we found a match; move the confffile and stop looking
508
 
        observe "preparing obsolete conffile $_conffile for removal"
509
 
        mv "$_conffile" "$_conffile.$THIS_PACKAGE-tmp"
 
496
        observe "preparing obsolete conffile $conffile for removal"
 
497
        mv "$conffile" "$conffile.$THIS_PACKAGE-tmp"
510
498
        break
511
499
      fi
512
500
      shift
514
502
  fi
515
503
}
516
504
 
 
505
remove_conffile_lookup () {
 
506
  # syntax: remove_conffile_lookup package filename
 
507
  #
 
508
  # Lookup the md5sum of a conffile in dpkg's database, and prepare for removal
 
509
  # if it matches the actual file's md5sum.
 
510
  #
 
511
  # Call this function when you would call remove_conffile_prepare but only
 
512
  # want to check against dpkg's status database instead of known checksums.
 
513
 
 
514
  local package conffile old_md5sum
 
515
 
 
516
  # validate arguments
 
517
  if [ $# -ne 2 ]; then
 
518
    usage_error "remove_conffile_lookup() called with wrong number of" \
 
519
                "arguments; expected 1, got $#"
 
520
    exit $SHELL_LIB_USAGE_ERROR
 
521
  fi
 
522
 
 
523
  package="$1"
 
524
  conffile="$2"
 
525
 
 
526
  if ! [ -e "$conffile" ]; then
 
527
    return
 
528
  fi
 
529
  old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$package" | \
 
530
    awk '{ if (match($0, "^ '"$conffile"' ")) print $2}')"
 
531
  if [ -n "$old_md5sum" ]; then
 
532
    remove_conffile_prepare "$conffile" "$old_md5sum"
 
533
  fi
 
534
}
 
535
 
517
536
remove_conffile_commit () {
518
537
  # syntax: remove_conffile_commit filename
519
538
  #
522
541
  # Call this function from a postinst script after having used
523
542
  # remove_conffile_prepare() in the preinst.
524
543
 
525
 
  #local conffile
 
544
  local conffile
526
545
 
527
546
  # validate arguments
528
547
  if [ $# -ne 1 ]; then
531
550
    exit $SHELL_LIB_USAGE_ERROR
532
551
  fi
533
552
 
534
 
  _conffile="$1"
 
553
  conffile="$1"
535
554
 
536
555
  # if the temporary file created by remove_conffile_prepare() exists, remove it
537
 
  if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
538
 
    observe "committing removal of obsolete conffile $_conffile"
539
 
    rm "$_conffile.$THIS_PACKAGE-tmp"
 
556
  if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
 
557
    observe "committing removal of obsolete conffile $conffile"
 
558
    rm "$conffile.$THIS_PACKAGE-tmp"
540
559
  fi
541
560
}
542
561
 
549
568
  # or "abort-install" is  after having used remove_conffile_prepare() in the
550
569
  # preinst.
551
570
 
552
 
  #local conffile
 
571
  local conffile
553
572
 
554
573
  # validate arguments
555
574
  if [ $# -ne 1 ]; then
558
577
    exit $SHELL_LIB_USAGE_ERROR
559
578
  fi
560
579
 
561
 
  _conffile="$1"
 
580
  conffile="$1"
562
581
 
563
582
  # if the temporary file created by remove_conffile_prepare() exists, move it
564
583
  # back
565
 
  if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
566
 
    observe "rolling back removal of obsolete conffile $_conffile"
567
 
    mv "$_conffile.$THIS_PACKAGE-tmp" "$_conffile"
 
584
  if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
 
585
    observe "rolling back removal of obsolete conffile $conffile"
 
586
    mv "$conffile.$THIS_PACKAGE-tmp" "$conffile"
568
587
  fi
569
588
}
570
589
 
584
603
  # version (or installed over a version removed-but-not-purged) prior to the
585
604
  # one in which the conffile was obsoleted.
586
605
 
587
 
  #local conffile current_checksum
 
606
  local conffile current_checksum
588
607
 
589
608
  # validate arguments
590
609
  if [ $# -lt 3 ]; then
593
612
    exit $SHELL_LIB_USAGE_ERROR
594
613
  fi
595
614
 
596
 
  _oldconffile="$1"
 
615
  oldconffile="$1"
597
616
  shift
598
 
  _newconffile="$1"
 
617
  newconffile="$1"
599
618
  shift
600
619
 
601
620
  remove_conffile_prepare "$_oldconffile" "$@"
602
 
  # If $_oldconffile still exists, then md5sums didn't match.
 
621
  # If $oldconffile still exists, then md5sums didn't match.
603
622
  # Copy it to new one.
604
 
  if [ -f "$_oldconffile" ]; then
605
 
    cp "$_oldconffile" "$_newconffile"
 
623
  if [ -f "$oldconffile" ]; then
 
624
    cp "$oldconffile" "$newconffile"
606
625
  fi
607
626
 
608
627
}
616
635
  # Call this function from a postinst script after having used
617
636
  # replace_conffile_with_symlink_prepare() in the preinst.
618
637
 
619
 
  #local conffile
 
638
  local conffile
620
639
 
621
640
  # validate arguments
622
641
  if [ $# -ne 1 ]; then
625
644
    exit $SHELL_LIB_USAGE_ERROR
626
645
  fi
627
646
 
628
 
  _conffile="$1"
 
647
  conffile="$1"
629
648
 
630
 
  remove_conffile_commit "$_conffile"
 
649
  remove_conffile_commit "$conffile"
631
650
}
632
651
 
633
652
replace_conffile_with_symlink_rollback () {
643
662
  # You should have  used replace_conffile_with_symlink_prepare() in the
644
663
  # preinst.
645
664
 
646
 
  #local conffile
 
665
  local conffile
647
666
 
648
667
  # validate arguments
649
668
  if [ $# -ne 2 ]; then
652
671
    exit $SHELL_LIB_USAGE_ERROR
653
672
  fi
654
673
 
655
 
  _oldconffile="$1"
656
 
  _newconffile="$2"
 
674
  oldconffile="$1"
 
675
  newconffile="$2"
657
676
 
658
677
  remove_conffile_rollback "$_oldconffile"
659
 
  if [ -f "$_newconffile" ]; then
660
 
    rm "$_newconffile"
 
678
  if [ -f "$newconffile" ]; then
 
679
    rm "$newconffile"
661
680
  fi
662
681
}
663
682
 
672
691
  # those cases the return value of the debconf command *must* be checked
673
692
  # before the string returned by debconf is used for anything.
674
693
 
675
 
  #local retval
 
694
  local retval
676
695
 
677
696
  # validate arguments
678
697
  if [ $# -lt 1 ]; then
681
700
    exit $SHELL_LIB_USAGE_ERROR
682
701
  fi
683
702
 
684
 
  "$@" || _retval=$?
685
 
 
686
 
  if [ ${_retval:-0} -ne 0 ]; then
687
 
    observe "command \"$*\" exited with status $_retval"
688
 
  fi
689
 
}
690
 
 
691
 
register_x_lib_dir_with_ld_so () {
692
 
  # syntax: register_x_lib_dir_with_ld_so
693
 
  #
694
 
  # Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
695
 
  # libraries.
696
 
  #
697
 
  # Call this function from the postinst script of a package that places a
698
 
  # shared library in /usr/X11R6/lib, before invoking ldconfig.
699
 
 
700
 
  #local dir ldsoconf
701
 
 
702
 
  _dir="/usr/X11R6/lib"
703
 
  _ldsoconf="/etc/ld.so.conf"
704
 
 
705
 
  # is the line not already present?
706
 
  if ! fgrep -qsx "$_dir" "$_ldsoconf"; then
707
 
    observe "adding $_dir directory to $_ldsoconf"
708
 
    echo "$_dir" >> "$_ldsoconf"
709
 
  fi
710
 
}
711
 
 
712
 
deregister_x_lib_dir_with_ld_so () {
713
 
  # syntax: deregister_x_lib_dir_with_ld_so
714
 
  #
715
 
  # Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
716
 
  # libraries, if and only if no shared libaries remain there.
717
 
  #
718
 
  # Call this function from the postrm script of a package that places a shared
719
 
  # library in /usr/X11R6/lib, in the event "$1" is "remove", and before
720
 
  # invoking ldconfig.
721
 
 
722
 
  #local dir ldsoconf fgrep_status cmp_status
723
 
 
724
 
  _dir="/usr/X11R6/lib"
725
 
  _ldsoconf="/etc/ld.so.conf"
726
 
 
727
 
  # is the line present?
728
 
  if fgrep -qsx "$_dir" "$_ldsoconf"; then
729
 
    # are there any shared objects in the directory?
730
 
    if [ "$(echo "$_dir"/lib*.so.*.*)" = "$_dir/lib*.so.*.*" ]; then
731
 
      # glob expansion produced nothing, so no shared libraries are present
732
 
      observe "removing $_dir directory from $_ldsoconf"
733
 
      # rewrite the file (very carefully)
734
 
      set +e
735
 
      fgrep -svx "$_dir" "$_ldsoconf" > "$_ldsoconf.dpkg-tmp"
736
 
      _fgrep_status=$?
737
 
      set -e
738
 
      case $_fgrep_status in
739
 
        0|1) ;; # we don't actually care if any lines matched or not
740
 
        *) die "error reading \"$_ldsoconf\"; fgrep exited with status" \
741
 
          "$_fgrep_status" ;;
742
 
      esac
743
 
      set +e
744
 
      cmp -s "$_ldsoconf.dpkg-tmp" "$_ldsoconf"
745
 
      _cmp_status=$?
746
 
      set -e
747
 
      case $_cmp_status in
748
 
        0) rm "$_ldsoconf.dpkg-tmp" ;; # files are identical
749
 
        1) mv "$_ldsoconf.dpkg-tmp" "$_ldsoconf" ;; # files differ
750
 
        *) die "error comparing \"$_ldsoconf.dpkg-tmp\" to \"$_ldsoconf\";" \
751
 
          "cmp exited with status $_cmp_status" ;;
752
 
      esac
753
 
    fi
 
703
  "$@" || retval=$?
 
704
 
 
705
  if [ ${retval:-0} -ne 0 ]; then
 
706
    observe "command \"$*\" exited with status $retval"
754
707
  fi
755
708
}
756
709
 
780
733
 
781
734
  # We could just use the positional parameters as-is, but that makes things
782
735
  # harder to follow.
783
 
  #local symlink target
784
 
 
785
 
  _symlink="$1"
786
 
  _target="$2"
787
 
 
788
 
  if [ -L "$_symlink" ] && [ "$(readlink "$_symlink")" = "$_target" ]; then
789
 
      observe "link from $_symlink to $_target already exists"
 
736
  local symlink target
 
737
 
 
738
  symlink="$1"
 
739
  target="$2"
 
740
 
 
741
  if [ -L "$symlink" ] && [ "$(readlink "$symlink")" = "$target" ]; then
 
742
      observe "link from $symlink to $target already exists"
790
743
  else
791
 
    observe "creating symbolic link from $_symlink to $_target"
792
 
    mkdir -p "${_target%/*}" "${_symlink%/*}"
793
 
    ln -s -b -S ".dpkg-old" "$_target" "$_symlink"
 
744
    observe "creating symbolic link from $symlink to $target"
 
745
    mkdir -p "${target%/*}" "${symlink%/*}"
 
746
    ln -s -b -S ".dpkg-old" "$target" "$symlink"
794
747
  fi
795
748
}
796
749
 
826
779
 
827
780
  # We could just use the positional parameters as-is, but that makes things
828
781
  # harder to follow.
829
 
  local _new _old
 
782
  local new old
830
783
 
831
 
  _old="$1"
832
 
  _new="$2"
 
784
  old="$1"
 
785
  new="$2"
833
786
 
834
787
  # Is old location a symlink?
835
 
  if [ -L "$_old" ]; then
 
788
  if [ -L "$old" ]; then
836
789
    # Does it already point to new location?
837
 
    if [ "$(readlink "$_old")" = "$_new" ]; then
 
790
    if [ "$(readlink "$old")" = "$new" ]; then
838
791
      # Nothing to do; migration has already been done.
839
 
      observe "migration of $_old to $_new already done"
 
792
      observe "migration of $old to $new already done"
840
793
      return 0
841
794
    else
842
795
      # Back it up.
843
 
      warn "backing up symbolic link $_old as $_old.dpkg-old"
844
 
      mv -b "$_old" "$_old.dpkg-old"
 
796
      warn "backing up symbolic link $old as $old.dpkg-old"
 
797
      mv -b "$old" "$old.dpkg-old"
845
798
    fi
846
799
  fi
847
800
 
848
801
  # Does old location exist, but is not a directory?
849
 
  if [ -e "$_old" ] && ! [ -d "$_old" ]; then
 
802
  if [ -e "$old" ] && ! [ -d "$old" ]; then
850
803
      # Back it up.
851
 
      warn "backing up non-directory $_old as $_old.dpkg-old"
852
 
      mv -b "$_old" "$_old.dpkg-old"
 
804
      warn "backing up non-directory $old as $old.dpkg-old"
 
805
      mv -b "$old" "$old.dpkg-old"
853
806
  fi
854
807
 
855
 
  observe "migrating $_old to $_new"
 
808
  observe "migrating $old to $new"
856
809
 
857
810
  # Is new location a symlink?
858
 
  if [ -L "$_new" ]; then
 
811
  if [ -L "$new" ]; then
859
812
    # Does it point the wrong way, i.e., back to where we're migrating from?
860
 
    if [ "$(readlink "$_new")" = "$_old" ]; then
 
813
    if [ "$(readlink "$new")" = "$old" ]; then
861
814
      # Get rid of it.
862
 
      observe "removing symbolic link $_new which points to $_old"
863
 
      rm "$_new"
 
815
      observe "removing symbolic link $new which points to $old"
 
816
      rm "$new"
864
817
    else
865
818
      # Back it up.
866
 
      warn "backing up symbolic link $_new as $_new.dpkg-old"
867
 
      mv -b "$_new" "$_new.dpkg-old"
 
819
      warn "backing up symbolic link $new as $new.dpkg-old"
 
820
      mv -b "$new" "$new.dpkg-old"
868
821
    fi
869
822
  fi
870
823
 
871
824
  # Does new location exist, but is not a directory?
872
 
  if [ -e "$_new" ] && ! [ -d "$_new" ]; then
873
 
    warn "backing up non-directory $_new as $_new.dpkg-old"
874
 
    mv -b "$_new" "$_new.dpkg-old"
 
825
  if [ -e "$new" ] && ! [ -d "$new" ]; then
 
826
    warn "backing up non-directory $new as $new.dpkg-old"
 
827
    mv -b "$new" "$new.dpkg-old"
875
828
  fi
876
829
 
877
830
  # Create new directory if it does not yet exist.
878
 
  if ! [ -e "$_new" ]; then
879
 
    observe "creating $_new"
880
 
    mkdir -p "$_new"
 
831
  if ! [ -e "$new" ]; then
 
832
    observe "creating $new"
 
833
    mkdir -p "$new"
881
834
  fi
882
835
 
883
836
  # Copy files in old location to new location.  Back up any filenames that
884
837
  # already exist in the new location with the extension ".dpkg-old".
885
 
  observe "copying files from $_old to $_new"
886
 
  if ! (cd "$_old" && cp -a -b -S ".dpkg-old" . "$_new"); then
887
 
    die "error(s) encountered while copying files from $_old to $_new"
 
838
  observe "copying files from $old to $new"
 
839
  if ! (cd "$old" && cp -a -b -S ".dpkg-old" . "$new"); then
 
840
    die "error(s) encountered while copying files from $old to $new"
888
841
  fi
889
842
 
890
843
  # Remove files at old location.
891
 
  observe "removing $_old"
892
 
  rm -r "$_old"
 
844
  observe "removing $old"
 
845
  rm -r "$old"
893
846
 
894
847
  # Create symlink from old location to new location.
895
 
  make_symlink_sane "$_old" "$_new"
 
848
  make_symlink_sane "$old" "$new"
896
849
}
897
850
 
898
851
# vim:set ai et sw=2 ts=2 tw=80: