#!/bin/sh

export PATH=/opt/lnxall_app/bin:/opt/lnxall_app/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin

TDengine_install() {
	cd /opt/lnxall_app
	[ ! -d /etc/taos ] && mkdir -p /etc/taos
	if [ ! -f platspec/taosd.service ] ; then
		: no need to install
		return 0
	fi

	if [ -f app/config/taos.cfg ] ; then
		diff -q app/config/taos.cfg /etc/taos/taos.cfg >/dev/null 2>/dev/null
		[ $? -ne 0 ] && cp -v -f app/config/taos.cfg /etc/taos/taos.cfg
	fi

	local tfile=/usr/lib/systemd/system/taosd.service
	diff -q platspec/taosd.service ${tfile} >/dev/null 2>/dev/null
	if [ $? -ne 0 ] ; then
		cp -v -f platspec/taosd.service ${tfile}
		systemctl daemon-reload
	fi
	systemctl enable taosd.service
	systemctl restart taosd.service
	return 0
}

TDengine_install
exit $?
