245
236
# analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
246
237
# Thanks to Randolph Chung for this clever hack.
250
241
while [ -n "$1" ]; do
251
242
reject_whitespace "$1"
253
244
message "Analyzing $1:"
254
for _f in $(echo "$1" | tr / \ ); do
255
if [ -e /$_g$_f ]; then
256
ls -dl /$_g$_f /$_g$_f.dpkg-* 2> /dev/null || true
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
259
message "/$_g$_f: nonexistent; directory contents of /$_g:"
250
message "/$g$f: nonexistent; directory contents of /$g:"
268
259
find_culprits () {
269
#local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
260
local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
272
263
reject_whitespace "$1"
273
264
message "Searching for overlapping packages..."
274
_dpkg_info_dir=/var/lib/dpkg/info
275
if [ -d $_dpkg_info_dir ]; then
276
if [ "$(echo $_dpkg_info_dir/*.list)" != "$_dpkg_info_dir/*.list" ]; then
277
_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 \
278
269
"(xbase-clients|x11-common|xfs|xlibs)")
279
if [ -n "$_possible_culprits" ]; then
280
_smoking_guns=$(grep -l "$1" $_possible_culprits || true)
281
if [ -n "$_smoking_guns" ]; then
282
_bad_packages=$(printf "\\n")
283
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
284
275
# too bad you can't nest parameter expansion voodoo
285
276
p=${f%*.list} # strip off the trailing ".list"
286
_package=${p##*/} # strip off the directories
287
_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")
290
281
The following packages appear to have file overlaps with the X.Org packages;
291
282
these packages are either very old, or in violation of Debian Policy. Try
292
283
upgrading each of these packages to the latest available version if possible:
298
289
of the Debian Policy manual.
302
message "The overlapping packages are: $_bad_packages"
293
message "The overlapping packages are: $bad_packages"
304
295
message "no overlaps found."
308
message "cannot search; no matches for $_dpkg_info_dir/*.list."
299
message "cannot search; no matches for $dpkg_info_dir/*.list."
311
message "cannot search; $_dpkg_info_dir does not exist."
302
message "cannot search; $dpkg_info_dir does not exist."
315
# we require a readlink command or shell function
316
if ! which readlink > /dev/null 2>&1; then
317
message "The readlink command was not found. Please install version" \
318
"1.13.1 or later of the debianutils package."
320
# returns what symlink in $1 actually points to
321
perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' "$1"
325
306
check_symlink () {
326
307
# syntax: check_symlink symlink
368
349
while [ -n "$1" ]; do
370
if [ -L "$_symlink" ]; then
371
if ! check_symlink "$_symlink"; then
372
observe "$_symlink symbolic link points to wrong location" \
373
"$(readlink "$_symlink"); removing"
351
if [ -L "$symlink" ]; then
352
if ! check_symlink "$symlink"; then
353
observe "$symlink symbolic link points to wrong location" \
354
"$(readlink "$symlink"); removing"
376
elif [ -e "$_symlink" ]; then
377
_errmsg="$_symlink exists and is not a symbolic link; this package cannot"
378
_errmsg="$_errmsg be installed until this"
379
if [ -f "$_symlink" ]; then
380
_errmsg="$_errmsg file"
381
elif [ -d "$_symlink" ]; then
382
_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"
384
_errmsg="$_errmsg thing"
365
errmsg="$errmsg thing"
386
_errmsg="$_errmsg is removed"
367
errmsg="$errmsg is removed"
409
390
while [ -n "$1" ]; do
412
if [ -L "$_symlink" ]; then
413
if ! check_symlink "$_symlink"; then
415
warn "$_symlink symbolic link points to wrong location" \
416
"$(readlink "$_symlink")"
393
if [ -L "$symlink" ]; then
394
if ! check_symlink "$symlink"; then
396
warn "$symlink symbolic link points to wrong location" \
397
"$(readlink "$symlink")"
418
elif [ -e "$_symlink" ]; then
420
warn "$_symlink is not a symbolic link"
399
elif [ -e "$symlink" ]; then
401
warn "$symlink is not a symbolic link"
423
warn "$_symlink symbolic link does not exist"
404
warn "$symlink symbolic link does not exist"
425
if [ -n "$_problem" ]; then
426
analyze_path "$_symlink" "$(readlink "$_symlink")"
427
find_culprits "$_symlink"
406
if [ -n "$problem" ]; then
407
analyze_path "$symlink" "$(readlink "$symlink")"
408
find_culprits "$symlink"
428
409
die "bad symbolic links on system"
448
429
reject_unlikely_path_chars "$UPDATECMDS"
449
430
reject_unlikely_path_chars "$FONTDIRS"
451
for _dir in $FONTDIRS; do
452
if [ -d "$_x_font_dir_prefix/$_dir" ]; then
453
for _cmd in $UPDATECMDS; do
454
if which "$_cmd" > /dev/null 2>&1; then
455
_shortcmd=${_cmd##*/}
456
observe "running $_shortcmd in $_dir font directory"
458
if [ "$_shortcmd" = "update-fonts-alias" ]; then
459
_cmd_opts=--x11r7-layout
461
if [ "$_shortcmd" = "update-fonts-dir" ]; then
462
_cmd_opts=--x11r7-layout
464
if [ "$_shortcmd" = "update-fonts-scale" ]; then
465
_cmd_opts=--x11r7-layout
467
$_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
437
observe "running $shortcmd in $dir font directory"
439
if [ "$shortcmd" = "update-fonts-alias" ]; then
440
cmd_opts=--x11r7-layout
442
if [ "$shortcmd" = "update-fonts-dir" ]; then
443
cmd_opts=--x11r7-layout
445
if [ "$shortcmd" = "update-fonts-scale" ]; then
446
cmd_opts=--x11r7-layout
448
$cmd $cmd_opts $dir || warn "$cmd $cmd_opts $dir" \
468
449
"failed; font directory data may not" \
471
warn "$_cmd not found; not updating corresponding $_dir font" \
452
warn "$cmd not found; not updating corresponding $dir font" \
476
warn "$_dir is not a directory; not updating font directory data"
457
warn "$dir is not a directory; not updating font directory data"
501
482
exit $SHELL_LIB_USAGE_ERROR
507
# does the _conffile even exist?
508
if [ -e "$_conffile" ]; then
488
# does the conffile even exist?
489
if [ -e "$conffile" ]; then
509
490
# calculate its checksum
510
_current_checksum=$(md5sum < "$_conffile" | sed 's/[[:space:]].*//')
491
current_checksum=$(md5sum < "$conffile" | sed 's/[[:space:]].*//')
511
492
# compare it to each supplied checksum
512
493
while [ -n "$1" ]; do
513
if [ "$_current_checksum" = "$1" ]; then
494
if [ "$current_checksum" = "$1" ]; then
514
495
# we found a match; move the confffile and stop looking
515
observe "preparing obsolete conffile $_conffile for removal"
516
mv "$_conffile" "$_conffile.$THIS_PACKAGE-tmp"
496
observe "preparing obsolete conffile $conffile for removal"
497
mv "$conffile" "$conffile.$THIS_PACKAGE-tmp"
505
remove_conffile_lookup () {
506
# syntax: remove_conffile_lookup package filename
508
# Lookup the md5sum of a conffile in dpkg's database, and prepare for removal
509
# if it matches the actual file's md5sum.
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.
514
local package conffile old_md5sum
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
526
if ! [ -e "$conffile" ]; then
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"
524
536
remove_conffile_commit () {
525
537
# syntax: remove_conffile_commit filename
538
550
exit $SHELL_LIB_USAGE_ERROR
543
555
# if the temporary file created by remove_conffile_prepare() exists, remove it
544
if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
545
observe "committing removal of obsolete conffile $_conffile"
546
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"
565
577
exit $SHELL_LIB_USAGE_ERROR
570
582
# if the temporary file created by remove_conffile_prepare() exists, move it
572
if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
573
observe "rolling back removal of obsolete conffile $_conffile"
574
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"
600
612
exit $SHELL_LIB_USAGE_ERROR
608
620
remove_conffile_prepare "$_oldconffile" "$@"
609
# If $_oldconffile still exists, then md5sums didn't match.
621
# If $oldconffile still exists, then md5sums didn't match.
610
622
# Copy it to new one.
611
if [ -f "$_oldconffile" ]; then
612
cp "$_oldconffile" "$_newconffile"
623
if [ -f "$oldconffile" ]; then
624
cp "$oldconffile" "$newconffile"
688
700
exit $SHELL_LIB_USAGE_ERROR
693
if [ ${_retval:-0} -ne 0 ]; then
694
observe "command \"$*\" exited with status $_retval"
698
register_x_lib_dir_with_ld_so () {
699
# syntax: register_x_lib_dir_with_ld_so
701
# Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
704
# Call this function from the postinst script of a package that places a
705
# shared library in /usr/X11R6/lib, before invoking ldconfig.
709
_dir="/usr/X11R6/lib"
710
_ldsoconf="/etc/ld.so.conf"
712
# is the line not already present?
713
if ! fgrep -qsx "$_dir" "$_ldsoconf"; then
714
observe "adding $_dir directory to $_ldsoconf"
715
echo "$_dir" >> "$_ldsoconf"
719
deregister_x_lib_dir_with_ld_so () {
720
# syntax: deregister_x_lib_dir_with_ld_so
722
# Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
723
# libraries, if and only if no shared libaries remain there.
725
# Call this function from the postrm script of a package that places a shared
726
# library in /usr/X11R6/lib, in the event "$1" is "remove", and before
729
#local dir ldsoconf fgrep_status cmp_status
731
_dir="/usr/X11R6/lib"
732
_ldsoconf="/etc/ld.so.conf"
734
# is the line present?
735
if fgrep -qsx "$_dir" "$_ldsoconf"; then
736
# are there any shared objects in the directory?
737
if [ "$(echo "$_dir"/lib*.so.*.*)" = "$_dir/lib*.so.*.*" ]; then
738
# glob expansion produced nothing, so no shared libraries are present
739
observe "removing $_dir directory from $_ldsoconf"
740
# rewrite the file (very carefully)
742
fgrep -svx "$_dir" "$_ldsoconf" > "$_ldsoconf.dpkg-tmp"
745
case $_fgrep_status in
746
0|1) ;; # we don't actually care if any lines matched or not
747
*) die "error reading \"$_ldsoconf\"; fgrep exited with status" \
751
cmp -s "$_ldsoconf.dpkg-tmp" "$_ldsoconf"
755
0) rm "$_ldsoconf.dpkg-tmp" ;; # files are identical
756
1) mv "$_ldsoconf.dpkg-tmp" "$_ldsoconf" ;; # files differ
757
*) die "error comparing \"$_ldsoconf.dpkg-tmp\" to \"$_ldsoconf\";" \
758
"cmp exited with status $_cmp_status" ;;
705
if [ ${retval:-0} -ne 0 ]; then
706
observe "command \"$*\" exited with status $retval"
788
734
# We could just use the positional parameters as-is, but that makes things
789
735
# harder to follow.
790
#local symlink target
795
if [ -L "$_symlink" ] && [ "$(readlink "$_symlink")" = "$_target" ]; then
796
observe "link from $_symlink to $_target already exists"
741
if [ -L "$symlink" ] && [ "$(readlink "$symlink")" = "$target" ]; then
742
observe "link from $symlink to $target already exists"
798
observe "creating symbolic link from $_symlink to $_target"
799
mkdir -p "${_target%/*}" "${_symlink%/*}"
800
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"
834
780
# We could just use the positional parameters as-is, but that makes things
835
781
# harder to follow.
841
787
# Is old location a symlink?
842
if [ -L "$_old" ]; then
788
if [ -L "$old" ]; then
843
789
# Does it already point to new location?
844
if [ "$(readlink "$_old")" = "$_new" ]; then
790
if [ "$(readlink "$old")" = "$new" ]; then
845
791
# Nothing to do; migration has already been done.
846
observe "migration of $_old to $_new already done"
792
observe "migration of $old to $new already done"
850
warn "backing up symbolic link $_old as $_old.dpkg-old"
851
mv -b "$_old" "$_old.dpkg-old"
796
warn "backing up symbolic link $old as $old.dpkg-old"
797
mv -b "$old" "$old.dpkg-old"
855
801
# Does old location exist, but is not a directory?
856
if [ -e "$_old" ] && ! [ -d "$_old" ]; then
802
if [ -e "$old" ] && ! [ -d "$old" ]; then
858
warn "backing up non-directory $_old as $_old.dpkg-old"
859
mv -b "$_old" "$_old.dpkg-old"
804
warn "backing up non-directory $old as $old.dpkg-old"
805
mv -b "$old" "$old.dpkg-old"
862
observe "migrating $_old to $_new"
808
observe "migrating $old to $new"
864
810
# Is new location a symlink?
865
if [ -L "$_new" ]; then
811
if [ -L "$new" ]; then
866
812
# Does it point the wrong way, i.e., back to where we're migrating from?
867
if [ "$(readlink "$_new")" = "$_old" ]; then
813
if [ "$(readlink "$new")" = "$old" ]; then
869
observe "removing symbolic link $_new which points to $_old"
815
observe "removing symbolic link $new which points to $old"
873
warn "backing up symbolic link $_new as $_new.dpkg-old"
874
mv -b "$_new" "$_new.dpkg-old"
819
warn "backing up symbolic link $new as $new.dpkg-old"
820
mv -b "$new" "$new.dpkg-old"
878
824
# Does new location exist, but is not a directory?
879
if [ -e "$_new" ] && ! [ -d "$_new" ]; then
880
warn "backing up non-directory $_new as $_new.dpkg-old"
881
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"
884
830
# Create new directory if it does not yet exist.
885
if ! [ -e "$_new" ]; then
886
observe "creating $_new"
831
if ! [ -e "$new" ]; then
832
observe "creating $new"
890
836
# Copy files in old location to new location. Back up any filenames that
891
837
# already exist in the new location with the extension ".dpkg-old".
892
observe "copying files from $_old to $_new"
893
if ! (cd "$_old" && cp -a -b -S ".dpkg-old" . "$_new"); then
894
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"
897
843
# Remove files at old location.
898
observe "removing $_old"
844
observe "removing $old"
901
847
# Create symlink from old location to new location.
902
make_symlink_sane "$_old" "$_new"
848
make_symlink_sane "$old" "$new"
905
851
# vim:set ai et sw=2 ts=2 tw=80: