Files
Prospeccao_SeConectai/scripts/seconectaiescavador.install
T
2026-10-01 11:00:47 -03:00

48 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
REPO_URL="${REPO_URL:-https://producao-gitea.0jo7zj.easypanel.host/tiago/Prospeccao_SeConectai.git}"
INSTALL_DIR="${INSTALL_DIR:-/opt/Prospeccao_SeConectai}"
BRANCH="${BRANCH:-main}"
DOMAIN="${DOMAIN:-escavador.seconectai.com.br}"
if ! command -v git >/dev/null 2>&1; then
echo "Erro: git nao encontrado. Instale com: apt update && apt install -y git"
exit 1
fi
if ! command -v docker >/dev/null 2>&1; then
echo "Erro: Docker nao encontrado. Instale Docker antes de continuar."
exit 1
fi
mkdir -p "$(dirname "$INSTALL_DIR")"
if [[ -d "$INSTALL_DIR/.git" ]]; then
echo "Repositorio ja existe em $INSTALL_DIR. Sincronizando com o Gitea..."
git -C "$INSTALL_DIR" remote remove origin >/dev/null 2>&1 || true
git -C "$INSTALL_DIR" remote add origin "$REPO_URL"
git -C "$INSTALL_DIR" fetch origin "$BRANCH"
git -C "$INSTALL_DIR" checkout -B "$BRANCH" "origin/$BRANCH" -f
else
if [[ -e "$INSTALL_DIR" && -n "$(ls -A "$INSTALL_DIR" 2>/dev/null || true)" ]]; then
if [[ -f "$INSTALL_DIR/pom.xml" && -d "$INSTALL_DIR/frontend" ]]; then
echo "Projeto encontrado em $INSTALL_DIR sem .git. Conectando ao Gitea e atualizando..."
git -C "$INSTALL_DIR" init
git -C "$INSTALL_DIR" remote remove origin >/dev/null 2>&1 || true
git -C "$INSTALL_DIR" remote add origin "$REPO_URL"
git -C "$INSTALL_DIR" fetch origin "$BRANCH"
git -C "$INSTALL_DIR" checkout -B "$BRANCH" "origin/$BRANCH" -f
else
echo "Erro: $INSTALL_DIR ja existe e nao parece ser este projeto."
echo "Use outro INSTALL_DIR ou mova a pasta atual antes de instalar."
exit 1
fi
else
git clone --branch "$BRANCH" "$REPO_URL" "$INSTALL_DIR"
fi
fi
cd "$INSTALL_DIR"
DOMAIN="$DOMAIN" ./scripts/install-prod.sh