summaryrefslogtreecommitdiffstats
path: root/debian/udev.postinst
blob: 828fa63af6dc4144a2f53211483faea9d4bb5d84 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh

set -e

chrooted() {
  if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ];
  then
    # the devicenumber/inode pair of / is the same as that of /sbin/init's
    # root, so we're *not* in a chroot and hence return false.
    return 1
  fi
  echo "A chroot environment has been detected, udev not started."
  return 0
}

in_debootstrap() {
  # debootstrap --second-stage may be run in an emulator instead of a chroot,
  # we need to check for this special case because start-stop-daemon would
  # not be available. (#520742)
  if [ -d /debootstrap/ ]; then
    echo "Being installed by debootstrap, udev not started."
    return 0
  fi
  return 1
}

can_start_udevd() {
  if [ ! -d /sys/class/ ]; then
    echo "udev requires a mounted sysfs, not started."
    return 1
  fi
  return 0
}

enable_udev() {
  can_start_udevd || return 0
  invoke-rc.d udev start
}

upgrade_fixes() {
  :
}

update_hwdb() {
  systemd-hwdb --usr update || true
}

case "$1" in
    configure)
    # update/create hwdb before we (re)start udev
    update_hwdb

    # Add new system groups used by udev rules
    addgroup --quiet --system input
    addgroup --quiet --system sgx

    # Make /dev/kvm accessible to kvm group
    addgroup --quiet --system kvm

    # Make /dev/dri/renderD* accessible to render group
    addgroup --quiet --system render

    if [ -z "$2" ]; then # first install
      if ! chrooted && ! in_debootstrap; then
	enable_udev
      fi
    else # upgrades
      upgrade_fixes "$@"
      if ! chrooted; then
	if can_start_udevd; then
	  if [ -d /run/systemd/system ] ; then
	    systemctl daemon-reload || true
	  fi
	  invoke-rc.d udev restart
	fi
      fi
    fi
    ;;

    triggered)
    update_hwdb
    exit 0
    ;;
esac

#DEBHELPER#