#!/bin/bash


if [ ! -d "/data/deploy" ]; then
  sudo mkdir -p "/data/deploy"
  echo "目录 /data/deploy 已创建。"
fi
sudo mkdir /data/deploy/base
sudo chmod 777 -R /data/
sudo chown -R ubuntu:ubuntu /data/
if [[ $hostname =~ "ECR" || $hostname =~ "BCR" ]] ; then
	sudo dpkg -i /data/deploy/offshore-digital-desktop_1.0.3.250624_amd64.de
	sudo dpkg -i /data/deploy/offshore-smart-desktop_1.0.3.250624_amd64.deb
fi

if [[ $hostname =~ "ECR" || $hostname =~ "Backup" ]]; then
	sudo mkdir -p /data/logs
	sudo mkdir -p /data/excel
	sudo mkdir -p /data/mysql
	sudo mkdir -p /data/tdengine
	sudo cp /data/deploy/sg-offshore-core-1.0-SNAPSHOT.jar /data/deploy/
	sudo curl -u sg:Mg3wg%3A17 http://183.250.156.66:8081/install_DS/compose.yml -o /data/deploy/base/compose.yml
	sudo curl -u sg:Mg3wg%3A17 http://183.250.156.66:8081/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
	sudo chmod 755 /usr/local/bin/docker-compose
	sudo mkdir /data/nginx/conf.d
	sudo chown -R ubuntu:ubuntu /data/{nginx,logs,excel,mysql,tdengine}
	sudo chmod -R 777 /data/nginx
	sudo curl -u sg:Mg3wg%3A17 http://183.250.156.66:8081/install_DS/default.conf -o /data/nginx/conf.d/default.conf
	#关闭本机nginx服务
	sudo systemctl stop nginx
	sudo systemctl disable nginx
	#配置海图
	sudo curl -u sg:Mg3wg%3A17 http://183.250.156.66:8081/install_DS/sg_offshore.tar.gz -o /data/sg_offshore.tar.gz
	sudo cd /data
	sudo tar -zxvf sg_offshore.tar.gz
	sudo chmod 777 -R /data/
	sudo chown ubuntu:ubuntu -R /data/
	docker-compose -f /data/deploy/base/compose.yml up -d
fi
