summaryrefslogtreecommitdiff
path: root/setup-devd.in
blob: 722546398c3faeb2e84442796d641cabf0925c6a (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh -e

PREFIX=@PREFIX@

: ${LIBDIR=$PREFIX/lib}
. "$LIBDIR/libalpine.sh"

prog="${0##*/}"

usage () {
	cat <<EOF
usage: setup-devd [ -h ] [ -C ] [ mdev | mdevd | udev ]

Set up the device manager.

Options:
  -h  Show this help
  -C  Perform a coldplug after starting the device manager.

The optional argument tells setup-devd what device manager to use.
mdev (from busybox) is the default.
mdevd is standalone, compatible with mdev, more efficient.
udev (from eudev) is the complex, full-featured one.
Without an argument, the choice is prompted interactively.

EOF
	exit $1
}

disable_mdev () {
	if rc-service --exists mdev ; then
		rc-service --ifstarted --quiet mdev stop
		rc-update delete --quiet mdev sysinit || :
	fi
}

enable_mdev () {
	# mdev openrc script is provided by busybox-initscripts which is assumed
	# to be there
	rc-update add --quiet mdev sysinit
	rc-service mdev --ifstopped start
}

disable_mdevd () {
	if rc-service --exists mdevd ; then
		rc-service --ifstarted --quiet mdevd stop
		rc-update delete --quiet mdevd-init sysinit 2>/dev/null || :
		rc-update delete --quiet mdevd sysinit 2>/dev/null || :
	fi
}

enable_mdevd () {
	$MOCK apk add --quiet mdevd mdevd-openrc
	rc-update add --quiet mdevd sysinit
	rc-update add --quiet mdevd-init sysinit
	rc-service --ifstopped mdevd start
	if "$1" ; then
		rc-service mdevd-init start
	fi
}

disable_udev () {
	if rc-service --exists udev ; then
		rc-service --ifstopped --quiet udev-postmount stop
		rc-service --ifstarted --quiet udev stop
		rc-update delete --quiet udev-postmount default 2>/dev/null || :
		rc-update delete --quiet udev-settle sysinit 2>/dev/null || :
		rc-update delete --quiet udev-trigger sysinit 2>/dev/null || :
		rc-update delete --quiet udev sysinit 2>/dev/null || :
	fi
}

enable_udev () {
	$MOCK apk add --quiet eudev udev-init-scripts udev-init-scripts-openrc
	rc-update add --quiet udev sysinit
	rc-update add --quiet udev-trigger sysinit
	rc-update add --quiet udev-settle sysinit
	rc-update add --quiet udev-postmount default
	rc-service --ifstopped udev start
	rc-service --ifstopped udev-trigger start
	rc-service --ifstopped udev-settle start
	rc-service --ifstopped udev-postmount start
}

coldplug=false
while getopts "hC" opt ; do
	case $opt in
		h) usage 0;;
		C) coldplug=true ;;
		'?') usage 1 >&2;;
	esac
done
shift $((OPTIND - 1))
devd="$1"
if test -n "$devd" ; then
	interactive=false
else
	interactive=true
fi

until isin "$devd" mdev mdevd udev ; do
	ask "What program should manage /dev? [mdev|mdevd|udev]" mdev
	devd="$resp"
done

if "$interactive" ; then
	if ask_yesno "Scan the hardware to populate /dev? [y|n] (Say yes if you're running this script for the first time.)" n ; then
		coldplug=true
	else
		coldplug=false
	fi
fi

case "$devd" in
	mdev)  disable_mdevd ; disable_udev ; enable_mdev $coldplug ;;
	mdevd) disable_mdev ; disable_udev ; enable_mdevd $coldplug ;;
	udev)  disable_mdev ; disable_mdevd ; enable_udev $coldplug ;;
esac