#!/bin/bash
# This file was autogenerated by node-deb 0.10.7
# Only difference is deb-systemd-invoke stop instead of systemctl stop
set -e
set -o pipefail

declare -r init_type='systemd'
declare -r service_name='unifi-innerspace'

if [[ "$init_type" == 'auto' || "$init_type" == 'systemd' || "$init_type" == 'upstart' || "$init_type" == 'sysv' ]]; then
  if hash systemctl 2> /dev/null; then
    systemctl disable "$service_name.service" && \
    deb-systemd-invoke stop "$service_name.service" || \
    echo "$service_name wasn't even running!"
  elif hash service 2> /dev/null; then
    service "$service_name" stop || echo "$service_name wasn't even running!"
  elif hash stop 2> /dev/null; then
    stop "$service_name" || echo "$service_name wasn't even running!"
  elif hash update-rc.d 2> /dev/null; then
    {
      update-rc.d "$service_name" remove && \
      "/etc/init.d/$service_name" stop
    } || "$service_name wasn't even running!"
  else
    echo "Your system does not appear to use upstart, systemd or sysv, so $service_name could not be stopped"
    echo 'Unless these systems were removed since install, no processes have been left running'
  fi
fi

rm -rf "/usr/share/$service_name/app/node_modules"
