#!/bin/sh

# 使用说明，用来提示输入参数
usage() {
	echo "Usage: sh 执行脚本.sh [port|base|modules|stop|rm]"
	exit 1
}

# 开启所需端口
port(){
	firewall-cmd --add-port=80/tcp --permanent
	firewall-cmd --add-port=8080/tcp --permanent
	firewall-cmd --add-port=8848/tcp --permanent
	firewall-cmd --add-port=9848/tcp --permanent
	firewall-cmd --add-port=9849/tcp --permanent
	firewall-cmd --add-port=6379/tcp --permanent
	firewall-cmd --add-port=3306/tcp --permanent
	firewall-cmd --add-port=9100/tcp --permanent
	firewall-cmd --add-port=9200/tcp --permanent
	firewall-cmd --add-port=9201/tcp --permanent
	firewall-cmd --add-port=9202/tcp --permanent
	firewall-cmd --add-port=9203/tcp --permanent
	firewall-cmd --add-port=9204/tcp --permanent
	firewall-cmd --add-port=9205/tcp --permanent
	firewall-cmd --add-port=9206/tcp --permanent
	firewall-cmd --add-port=9207/tcp --permanent
	firewall-cmd --add-port=9208/tcp --permanent
	firewall-cmd --add-port=9209/tcp --permanent
	firewall-cmd --add-port=9300/tcp --permanent
	service firewalld restart
}

# 启动基础环境（必须）
docker-compose build --no-cache ruoyi-mysql && docker-compose up -d ruoyi-mysql
docker-compose build --no-cache ruoyi-redis && docker-compose up -d ruoyi-redis
docker-compose build --no-cache ruoyi-nacos && docker-compose up -d ruoyi-nacos
docker-compose build --no-cache ruoyi-gateway && docker-compose up -d ruoyi-gateway
docker-compose build --no-cache ruoyi-nginx && docker-compose up -d ruoyi-nginx
docker-compose build --no-cache ruoyi-auth && docker-compose up -d ruoyi-auth
docker-compose build --no-cache ruoyi-modules-system && docker-compose up -d ruoyi-modules-system
docker-compose build --no-cache ruoyi-modules-gen && docker-compose up -d ruoyi-modules-gen
docker-compose build --no-cache ruoyi-modules-job && docker-compose up -d ruoyi-modules-job
docker-compose build --no-cache ruoyi-modules-file && docker-compose up -d ruoyi-modules-file
docker-compose build --no-cache ruoyi-visual-monitor && docker-compose up -d ruoyi-visual-monitor
docker-compose build --no-cache tuoheng-modules-approval && docker-compose up -d tuoheng-modules-approval
docker-compose build --no-cache tuoheng-modules-device && docker-compose up -d tuoheng-modules-device
docker-compose build --no-cache tuoheng-modules-airline && docker-compose up -d tuoheng-modules-airline
docker-compose build --no-cache tuoheng-modules-task && docker-compose up -d tuoheng-modules-task
docker-compose build --no-cache tuoheng-modules-fms && docker-compose up -d tuoheng-modules-fms
docker-compose build --no-cache tuoheng-modules-media && docker-compose up -d tuoheng-modules-media

# 关闭所有环境/模块
stop(){
	docker-compose stop
}

# 删除所有环境/模块
rm(){
	docker-compose rm
	docker-compose down
}

# 根据输入参数，选择执行对应方法，不输入则执行使用说明
case "$1" in
"port")
	port
;;
"base")
	base
;;
"modules")
	modules
;;
"stop")
	stop
;;
"rm")
	rm
;;
*)
	usage
;;
esac
