service_disable() {
    service="$1"
    if [ -f /lib/systemd/system/${service}.service ] ; then
        if [ systemd = "$BOOTSYSTEM" ] ; then
	    systemctl disable ${service}.service
        else
            service $service disable || true
        fi
    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 \
        gdm3 \
        sddm \
      ; 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
    # Ensure /etc/environment is set correctly.
    /usr/share/debian-edu-config/tools/update-proxy-from-wpad
    # Allow logged in users to mount removable media (like USB sticks); needed
    # because LDM doesn't write utemp/wtemp entries. Remove if #913774 is fixed.
    patch /usr/share/polkit-1/actions/org.freedesktop.UDisks2.policy /usr/share/debian-edu-config/udisks2.patch
fi

# Remove useless services for thin clients (in addition to LTSP defaults).
if ! boolean_is_true "$LTSP_FATCLIENT" ; then
    for service in \
        autofs \
        fetch-ldap-cert \
        firefox-ldapconf \
        minidlna \
        ntp \
        nslcd \
        nscd \
        rsync \
        timidity \
      ; do
        service_disable $service
    done
    if [ -f /etc/cron.d/desktop-autoloader ] ; then
        rm /etc/cron.d/desktop-autoloader
    fi
fi


