#!/bin/sh

service_disable() {
    service="$1"
    if [ systemd = "$BOOTSYSTEM" ] \
	&& [ -f /lib/systemd/system/${service}.service ] ; then
	systemctl disable ${service}.service
    else
        update-rc.d $service disable || true
    fi
}

if grep -q systemd /sbin/init ; then
    BOOTSYSTEM=systemd
else
    BOOTSYSTEM=sysvinit
fi

# Use systemd compliant systemctl.
# Remove unused dm services if ldm is used.
if [ -z "$DEFAULT_DISPLAY_MANAGER" ]; then
    for service in \
        lightdm \
        kdm \
        gdm3 \
      ; do
        service_disable $service
    done
fi

# For Debian Edu diskless workstations (i.e. ltsp fat clients).
if boolean_is_true "$LTSP_FATCLIENT" && [ -z "$DEFAULT_DISPLAY_MANAGER" ]; then
    # Remove autofs to let sshfs mount home dir (LDM is used).
    service_disable autofs
fi

# Remove useless services for thin clients.
if ! boolean_is_true "$LTSP_FATCLIENT" ; then
    for service in \
        cups-browsed \
        anacron \
        avahi-daemon \
        autofs \
        bluetooth \
        inetd \
        rpcbind \
        ntp \
        nfs-common \
        nslcd \
        nscd \
        timidity \
        minidlna \
        lirc \
      ; do
        service_disable $service
    done
fi
