enable-service.sh 1002 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/env bash

function usage() {
    echo "Usage: $0 [-s <service_name>]"
}

SERVICE=

# Get command line options
while getopts ":s:" opt; do
    case $opt in
12
        s)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
            SERVICE=$OPTARG
            ;;
        \?)
            echo "Invalid option: -$OPTARG" >&2
            usage
            exit 1
            ;;
        :)
            echo "Option -$OPTARG requires an argument." >&2
            usage
            exit 1
            ;;
    esac
done

28 29 30 31 32 33
if [ -z "$SERVICE" ]; then
    echo "\"SERVICE\" variable unset."
    usage
    exit 1
fi

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
INIT_SYSTEM=$(./get-init-system.sh)

# Enable service depending on which init system we are

case ${INIT_SYSTEM} in
    "systemd")
        echo "Enabling systemd service "${SERVICE}
        ;;
    "upstart")
        echo "Enabling upstart service "${SERVICE}
        ;;
    "sysv-init")
        echo "Enabling sysv-init service "${SERVICE}
        ;;
    "?")
        echo "Invalid init system detected." >&2
        exit 1
        ;;
esac