#!/usr/bin/env bash

if [ ! -f ".env" ]; then
    cp env.example .env
fi

if [ ! -z "$SXZ_HTTP_PORT" ] && [ ! -z "$CONTAINER_NAME" ]; then
    echo "存在全局变量"
    rm .env
    cat >>.env <<EOF
SXZ_HTTP_PORT=$SXZ_HTTP_PORT
CONTAINER_NAME=$CONTAINER_NAME
EOF

else

    echo "不存在全局变量"
    source .env
fi

echo "http_port: $SXZ_HTTP_PORT"
echo "container_name: $CONTAINER_NAME"

if [ "$(docker container inspect -f '{{.State.Status}}' $CONTAINER_NAME)" == "running" ]; then
    docker rm $CONTAINER_NAME -f
    docker-compose up -d
else
    docker-compose up -d
fi
