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