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.
243
241
while [ -n "$1" ]; do
244
242
reject_whitespace "$1"
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
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
252
message "/$_g$_f: nonexistent; directory contents of /$_g:"
250
message "/$g$f: nonexistent; directory contents of /$g:"
261
259
find_culprits () {
262
#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 \
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")
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.
295
message "The overlapping packages are: $_bad_packages"
293
message "The overlapping packages are: $bad_packages"
297
295
message "no overlaps found."
301
message "cannot search; no matches for $_dpkg_info_dir/*.list."
299
message "cannot search; no matches for $dpkg_info_dir/*.list."
304
message "cannot search; $_dpkg_info_dir does not exist."
302
message "cannot search; $dpkg_info_dir does not exist."
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."
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"
318
306
check_symlink () {
319
307
# syntax: check_symlink symlink
361
349
while [ -n "$1" ]; do
363
if [ -L "$_symlink" ]; then
364
if ! check_symlink "$_symlink"; then
365
observe "$_symlink symbolic link points to wrong location" \
366
"$(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"
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"
377
_errmsg="$_errmsg thing"
365
errmsg="$errmsg thing"
379
_errmsg="$_errmsg is removed"
367
errmsg="$errmsg is removed"
402
390
while [ -n "$1" ]; do
405
if [ -L "$_symlink" ]; then
406
if ! check_symlink "$_symlink"; then
408
warn "$_symlink symbolic link points to wrong location" \
409
"$(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")"
411
elif [ -e "$_symlink" ]; then
413
warn "$_symlink is not a symbolic link"
399
elif [ -e "$symlink" ]; then
401
warn "$symlink is not a symbolic link"
416
warn "$_symlink symbolic link does not exist"
404
warn "$symlink symbolic link does not exist"
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"
441
429
reject_unlikely_path_chars "$UPDATECMDS"
442
430
reject_unlikely_path_chars "$FONTDIRS"
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"
451
if [ "$_shortcmd" = "update-fonts-alias" ]; then
452
_cmd_opts=--x11r7-layout
454
if [ "$_shortcmd" = "update-fonts-dir" ]; then
455
_cmd_opts=--x11r7-layout
457
if [ "$_shortcmd" = "update-fonts-scale" ]; then
458
_cmd_opts=--x11r7-layout
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
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" \
461
449
"failed; font directory data may not" \
464
warn "$_cmd not found; not updating corresponding $_dir font" \
452
warn "$cmd not found; not updating corresponding $dir font" \
469
warn "$_dir is not a directory; not updating font directory data"
457
warn "$dir is not a directory; not updating font directory data"
494
482
exit $SHELL_LIB_USAGE_ERROR
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"
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"
517
536
remove_conffile_commit () {
518
537
# syntax: remove_conffile_commit filename
531
550
exit $SHELL_LIB_USAGE_ERROR
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"
558
577
exit $SHELL_LIB_USAGE_ERROR
563
582
# if the temporary file created by remove_conffile_prepare() exists, move it
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"
593
612
exit $SHELL_LIB_USAGE_ERROR
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"
681
700
exit $SHELL_LIB_USAGE_ERROR
686
if [ ${_retval:-0} -ne 0 ]; then
687
observe "command \"$*\" exited with status $_retval"
691
register_x_lib_dir_with_ld_so () {
692
# syntax: register_x_lib_dir_with_ld_so
694
# Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
697
# Call this function from the postinst script of a package that places a
698
# shared library in /usr/X11R6/lib, before invoking ldconfig.
702
_dir="/usr/X11R6/lib"
703
_ldsoconf="/etc/ld.so.conf"
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"
712
deregister_x_lib_dir_with_ld_so () {
713
# syntax: deregister_x_lib_dir_with_ld_so
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.
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
722
#local dir ldsoconf fgrep_status cmp_status
724
_dir="/usr/X11R6/lib"
725
_ldsoconf="/etc/ld.so.conf"
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)
735
fgrep -svx "$_dir" "$_ldsoconf" > "$_ldsoconf.dpkg-tmp"
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" \
744
cmp -s "$_ldsoconf.dpkg-tmp" "$_ldsoconf"
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" ;;
705
if [ ${retval:-0} -ne 0 ]; then
706
observe "command \"$*\" exited with status $retval"
781
734
# We could just use the positional parameters as-is, but that makes things
782
735
# harder to follow.
783
#local symlink target
788
if [ -L "$_symlink" ] && [ "$(readlink "$_symlink")" = "$_target" ]; then
789
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"
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"
827
780
# We could just use the positional parameters as-is, but that makes things
828
781
# harder to follow.
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"
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"
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
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"
855
observe "migrating $_old to $_new"
808
observe "migrating $old to $new"
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
862
observe "removing symbolic link $_new which points to $_old"
815
observe "removing symbolic link $new which points to $old"
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"
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"
877
830
# Create new directory if it does not yet exist.
878
if ! [ -e "$_new" ]; then
879
observe "creating $_new"
831
if ! [ -e "$new" ]; then
832
observe "creating $new"
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"
890
843
# Remove files at old location.
891
observe "removing $_old"
844
observe "removing $old"
894
847
# Create symlink from old location to new location.
895
make_symlink_sane "$_old" "$_new"
848
make_symlink_sane "$old" "$new"
898
851
# vim:set ai et sw=2 ts=2 tw=80: