#!/bin/sh

set -e

BASE_URL=https://packages.netxms.org/
FILE_NAME=netxms-release-latest.deb

WD=`mktemp -d`
trap "rm -rf $WD" EXIT

C=$(which curl || true)
W=$(which wget || true)

if [ ! -z $C ]; then
	$C -so $WD/$FILE_NAME $BASE_URL$FILE_NAME
else
	if [ ! -z $W ]; then
		$W -qO $WD/$FILE_NAME $BASE_URL$FILE_NAME
	else
		echo "Can't find wget or cURL."
		echo "Download \"$BASE_URL$FILE_NAME\", then install with \"dpkg -i $FILE_NAME\""
		exit 1
	fi
fi

dpkg -l lsb-release >/dev/null 2>/dev/null || apt-get install -y lsb-release
dpkg -i $WD/$FILE_NAME
apt-get update

echo NetXMS package source installed.
