dpkg.prerm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/sh
  2. # See deb-prerm(5).
  3. set -e
  4. ensure_no_triggers_noawait()
  5. {
  6. admindir=${DPKG_ADMINDIR:-/var/lib/dpkg}
  7. pkgadmindir=$admindir/info
  8. trig_noawait=$(find "$pkgadmindir" -name "*.triggers" -type f | \
  9. xargs -r grep -El "^(interest|activate)-(no)?await" | \
  10. sed -e 's,^.*/\([^/.:]\+\)[^/]\+$,\1,')
  11. # Abort if we cannot possibly downgrade
  12. if [ -n "$trig_noawait" ]; then
  13. cat <<- MSG
  14. dpkg: error: You have packages using the "interest-noawait" and/or
  15. "activate-noawait" trigger directives but the dpkg version that
  16. you're trying to downgrade to doesn't support them. Aborting
  17. downgrade.
  18. List of affected packages:
  19. $trig_noawait
  20. MSG
  21. exit 1
  22. fi
  23. bad_triggers_files=$(find "$admindir/triggers" -type f | \
  24. xargs -r grep -l "/noawait$" || true)
  25. if [ -n "$bad_triggers_files" ]; then
  26. cat <<- MSG
  27. dpkg: error: Some internal trigger files unexpectedly reference
  28. packages tagged with "/noawait" while their corresponding
  29. infodb files doesn't seem to contain any "interest-noawait"
  30. directive. Aborting the downgrade as those tags are not supported
  31. by the version you're trying to downgrade to.
  32. List of internal trigger files that are affected:
  33. $bad_triggers_files
  34. MSG
  35. exit 1
  36. fi
  37. }
  38. downgrade_multiarch_infodb()
  39. {
  40. admindir=${DPKG_ADMINDIR:-/var/lib/dpkg}
  41. pkgadmindir=$admindir/info
  42. triggersdir=$admindir/triggers
  43. coinst_pkgs="`ls "$pkgadmindir" | \
  44. sed -n -e 's/^\([^:]\+:[^.]\+\)\..*$/\1/p' | sort -u | \
  45. cut -d: -f1 | uniq -d`"
  46. # Abort if we cannot possibly downgrade
  47. if [ -n "$coinst_pkgs" ]; then
  48. cat <<- MSG
  49. dpkg: error: You have more than one architecture instance for some
  50. installed 'Multi-Arch: same' packages, to be able to downgrade dpkg
  51. you will need to have only one instance installed per package.
  52. List of co-installed packages:
  53. $coinst_pkgs
  54. MSG
  55. exit 1
  56. fi
  57. bad_dep_pkgs=$(dpkg-query -f '${Package}\t${Depends} ${Recommends} ${Suggests} ${Enhances} ${Conflicts} ${Replaces} ${Breaks}\n' -W | \
  58. grep ":any" | cut -f1 | sort -u)
  59. if [ -n "$bad_dep_pkgs" ]; then
  60. cat <<- MSG
  61. dpkg: error: Some installed packages have multiarch dependencies that
  62. the old dpkg won't parse. You should get rid of them (or downgrade
  63. them to versions without those dependencies) before proceeding with
  64. dpkg's downgrade.
  65. List of affected packages:
  66. $bad_dep_pkgs
  67. MSG
  68. exit 1
  69. fi
  70. dep_fields='Depends|Recommends|Suggests|Enhances|Conflicts|Replaces|Breaks'
  71. if grep -qE "^($dep_fields):.*:any" $admindir/available; then
  72. cat <<- MSG
  73. dpkg: error: Some available packages have multiarch dependencies that
  74. the old dpkg won't parse. You should clear this file before proceeding
  75. with dpkg's downgrade, with:
  76. # dpkg --clear-avail
  77. MSG
  78. exit 1
  79. fi
  80. file_triggers_pkgs="`sed -n -e 's/^[^ ]\+ \([^:]\+\):[^.]\+$/\1/p' \
  81. $triggersdir/File| sort -u`"
  82. if [ -n "$file_triggers_pkgs" ]; then
  83. cat <<-MSG
  84. dpkg: error: The triggers database contains arch-qualified package
  85. names that the old dpkg won't parse. You should get rid of them (or
  86. downgrade them to a non Multi-Arch: same version) before proceeding
  87. with dpkg's downgrade.
  88. List of affected packages:
  89. $file_triggers_pkgs
  90. MSG
  91. exit 1
  92. fi
  93. echo "Downgrading the multiarch dpkg control files database ..."
  94. ls $pkgadmindir | grep : | while read oldfile; do
  95. # We first do a round of hardlinks to the new names, so that the db
  96. # will never be unusable for either of the dpkg versions.
  97. newfile=$(echo $oldfile | sed -e 's/:[^.]\+//')
  98. ln -f "$pkgadmindir/$oldfile" "$pkgadmindir/$newfile"
  99. done
  100. }
  101. case "$1" in
  102. upgrade)
  103. # Allow the downgrade only if no package is using the
  104. # (interest|activate)-noawait trigger directives
  105. if dpkg --compare-versions "$2" lt 1.16.1; then
  106. ensure_no_triggers_noawait
  107. fi
  108. # Downgrade the multiarch db to a “monoarch” db layout
  109. if dpkg --compare-versions "$2" lt 1.16.2; then
  110. downgrade_multiarch_infodb
  111. fi
  112. ;;
  113. remove|failed-upgrade|deconfigure)
  114. ;;
  115. *)
  116. echo "$0 called with unknown argument '$1'" 1>&2
  117. exit 1
  118. ;;
  119. esac
  120. #DEBHELPER#
  121. exit 0