| 1 |
#!/bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
is_fs() { |
| 5 |
local fs_type |
| 6 |
fs_type="$(stat --file-system --format=%T "$2" 2> /dev/null)" |
| 7 |
|
| 8 |
if [ "$fs_type" = "$1" ]; then return 0; fi |
| 9 |
return 1 |
| 10 |
} |
| 11 |
|
| 12 |
is_merged() { |
| 13 |
local directories="/bin /sbin /lib" |
| 14 |
for dir in $directories; do |
| 15 |
[ -e "$dir" ] || continue |
| 16 |
[ "$(readlink -f "$dir")" = "/usr$dir" ] || return 1 |
| 17 |
done |
| 18 |
|
| 19 |
# Avoid an exact match, as the target might vary depending on the tool |
| 20 |
# building the image. For example, systemd-nspawn links /lib64 to |
| 21 |
# /usr/lib/aarch64-linux-gnu on arm64, while on amd64 debootstrap links it to |
| 22 |
# /usr/lib64 and doesn't create it at all on arm64. |
| 23 |
# See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1019575 |
| 24 |
local arch_directories="/lib64 /lib32 /libo32 /libx32" |
| 25 |
for dir in $arch_directories; do |
| 26 |
[ -e "$dir" ] || continue |
| 27 |
case "$(readlink -f "$dir")" in |
| 28 |
"/usr/lib"*) ;; |
| 29 |
*) return 1;; |
| 30 |
esac |
| 31 |
done |
| 32 |
|
| 33 |
return 0 |
| 34 |
} |
| 35 |
|
| 36 |
maybe_convert() { |
| 37 |
# do not try to run the program if the system has already been converted |
| 38 |
if is_merged; then return; fi |
| 39 |
|
| 40 |
if is_fs nfs / || is_fs nfs /usr; then |
| 41 |
cat << 'END' >&2 |
| 42 |
|
| 43 |
Warning: NFS detected, /usr/lib/usrmerge/convert-usrmerge will not be run |
| 44 |
automatically. See #842145 for details. |
| 45 |
|
| 46 |
END |
| 47 |
return 1 |
| 48 |
fi |
| 49 |
|
| 50 |
/usr/lib/usrmerge/convert-usrmerge || return $? |
| 51 |
|
| 52 |
if which update-shells > /dev/null; then |
| 53 |
update-shells |
| 54 |
fi |
| 55 |
/usr/lib/usrmerge/convert-etc-shells || return $? |
| 56 |
} |
| 57 |
|
| 58 |
cleanup_biarch_dirs() { |
| 59 |
dpkg --compare-versions "$2" lt "36~" || return 0 |
| 60 |
|
| 61 |
# bootstrapping or earlier conversions may have created empty biarch |
| 62 |
# directories and links. glibc 2.35-4 or later will create them if needed, |
| 63 |
# so clean up the unused (and unowned) ones |
| 64 |
local arch_directories="/lib64 /lib32 /libo32 /libx32" |
| 65 |
for dir in $arch_directories; do |
| 66 |
[ -e "$dir" ] || continue |
| 67 |
if ! dpkg-query -S $dir >/dev/null 2>&1; then |
| 68 |
rm -v $dir |
| 69 |
if [ -e /usr$dir ] && ! dpkg-query -S /usr$dir >/dev/null 2>&1 ; then |
| 70 |
rmdir --ignore-fail-on-non-empty -v /usr$dir |
| 71 |
fi |
| 72 |
fi |
| 73 |
done |
| 74 |
} |
| 75 |
|
| 76 |
case "$1" in |
| 77 |
configure) |
| 78 |
# skipping the conversion is not supported anymore |
| 79 |
if [ -e /etc/unsupported-skip-usrmerge-conversion ] && \ |
| 80 |
grep -q 'this system will not be supported in the future' \ |
| 81 |
/etc/unsupported-skip-usrmerge-conversion; then |
| 82 |
echo "E: /etc/unsupported-skip-usrmerge-conversion exists." >&2 |
| 83 |
exit 1 |
| 84 |
else |
| 85 |
maybe_convert "$@" || { echo "E: usrmerge failed." >&2; exit 1; } |
| 86 |
cleanup_biarch_dirs |
| 87 |
fi |
| 88 |
;; |
| 89 |
esac |
| 90 |
|
| 91 |
#DEBHELPER# |
| 92 |
|