#!/bin/bash

BASEPATH=/opt
INSTALLPATH=$BASEPATH/MQTTnetServer

# Check if systemctl exists, does not exist in docker containers
SCTL=$(which systemctl >/dev/null; echo $?)
if [ "$SCTL" -eq "0" ]; then
    # Stop service before uninstalling
    systemctl stop mqttnet-server
fi

# Check if setcap exists, does not exist in docker containers
SCAP=$(which setcap >/dev/null; echo $?)
if [ "$SCAP" -eq "0" ]; then
    # Remove permission to open ports
    setcap CAP_NET_BIND_SERVICE=-eip $INSTALLPATH/MQTTnet.Server
fi