#!/bin/bash
# 2024-12

[ $(id -u) -eq 0 ] || echo "需要用root用户操作!"
[ $(id -u) -eq 0 ] || exit 4;

#获取脚本根目录，并设为只读
readonly INITDIR=$(cd $(dirname $0); dirname "$PWD")

echo "正在安装TDengine"

systemctl stop taosd taosadapter 
[ -f /usr/bin/rmtaos ]  && /usr/bin/rmtaos  
 mv /var/lib/taos /tmp/var-taos`date +%F%T` 
 mv /etc/taos/taos.cfg /tmp/taos.cfg`date +%F%T` 
 mv /usr/local/taos /tmp/taos`date +%F%T` 
 \rm -f /var/log/taos	

[ -f /usr/bin/rmtaostools ] && /usr/bin/rmtaostools

#安装
cd $INITDIR/file/tdengine/TDengine-server-3.0.7.1/ 
./install.sh -e no 
systemctl start taosd taosadapter 
systemctl enable taosd taosadapter 
systemctl status taosd taosadapter 
sleep 45;
netstat -lnpt | grep  ":6030"  && netstat -lnpt | grep  ":6041" && \
{ echo "TDengine安装完成"; sleep 45; $INITDIR/sh/taos-init-sql.sh;} || \
{ echo "TDengine安装异常，注意检查"; exit 2;} 



