summaryrefslogtreecommitdiffstats
path: root/debian/usr-is-merged.preinst
blob: 9cb62280f37076bf1950543adee71abe3322265e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh -e

is_merged() {
  local directories="/bin /sbin /lib"
  for dir in $directories; do
    [ -e "$DPKG_ROOT$dir" ] || continue
    [ "$(readlink -f "$DPKG_ROOT$dir")" = "$DPKG_ROOT/usr$dir" ] || return 1
  done

  # Avoid an exact match, as the target might vary depending on the tool
  # building the image. For example, systemd-nspawn links /lib64 to
  # /usr/lib/aarch64-linux-gnu on arm64, while on amd64 debootstrap links it to
  # /usr/lib64 and doesn't create it at all on arm64.
  # See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1019575
  local arch_directories="/lib64 /lib32 /libo32 /libx32"
  for dir in $arch_directories; do
    [ -e "$DPKG_ROOT$dir" ] || continue
    case "$(readlink -f "$DPKG_ROOT$dir")" in
        "$DPKG_ROOT/usr/lib"*) ;;
        *) return 1;;
    esac
  done

  return 0
}

fail_if_unmerged() {
  if is_merged; then return; fi

  cat << END


******************************************************************************
*
* The usr-is-merged package cannot be installed because this system does
* not have a merged /usr.
*
* Please install the usrmerge package to convert this system to merged-/usr.
*
* For more information please read https://wiki.debian.org/UsrMerge.
*
******************************************************************************


END
  exit 1
}

case "$1" in
    install|upgrade)
    fail_if_unmerged
    ;;
esac

#DEBHELPER#