Debian Codegraph @

debian/extra/systemd-sysv-install

raw
1 #!/bin/sh
2 # This script is called by "systemctl enable/disable" when the given unit is a
3 # SysV init.d script. It needs to call the distribution's mechanism for
4 # enabling/disabling those, such as chkconfig, update-rc.d, or similar. This
5 # can optionally take a --root argument for enabling a SysV init script
6 # in a chroot or similar.
7 set -eu
8
9 usage() {
10 echo "Usage: $0 [--root=path] enable|disable|is-enabled <sysv script name>" >&2
11 exit 1
12 }
13
14 ROOT=
15
16 # parse options
17 eval set -- "$(getopt -o r: --long root: -- "$@")"
18 while true; do
19 case "$1" in
20 -r|--root)
21 ROOT="$2"
22 shift 2 ;;
23 --) shift ; break ;;
24 *) usage ;;
25 esac
26 done
27
28 NAME="${2:-}"
29
30 run() {
31 if [ -n "$ROOT" ] && [ "$ROOT" != "/" ]; then
32 _SKIP_SYSTEMD_NATIVE=1 chroot "$ROOT" /usr/sbin/update-rc.d "$@"
33 else
34 _SKIP_SYSTEMD_NATIVE=1 /usr/sbin/update-rc.d "$@"
35 fi
36 }
37
38 [ -n "$NAME" ] || usage
39
40 case "$1" in
41 enable)
42 # call the command to enable SysV init script $NAME here..
43 run "$NAME" defaults
44 run "$NAME" enable
45 ;;
46 disable)
47 run "$NAME" defaults
48 run "$NAME" disable
49 ;;
50 is-enabled)
51 # exit with 0 if $NAME is enabled, non-zero if it is disabled
52 ls "$ROOT"/etc/rc[S5].d/S??"$NAME" >/dev/null 2>&1
53 ;;
54 *)
55 usage ;;
56 esac