#!/bin/bash

sudo rm -rf /tmp/leopard
git clone --depth 1 https://gitea.lanyuanxiaoyao.com/lanyuanxiaoyao/leopard.git /tmp/leopard

docker run \
  --rm \
  -v /root/.m2:/root/.m2 \
  -v /tmp/leopard:/tmp/leopard \
  -w /tmp/leopard \
  maven:3.9.11-eclipse-temurin-17-alpine \
  mvn -pl leopard-server clean package -D skipTests

docker run \
  --rm \
  -v /root/.pnpm-store:/root/.pnpm-store \
  -v /tmp/leopard:/tmp/leopard \
  -w /tmp/leopard/leopard-web \
  guergeiro/pnpm:22-10-alpine \
  /bin/sh -c "pnpm install && pnpm build"

sudo chown -R ubuntu:ubuntu /tmp/leopard

mv /tmp/leopard/leopard-server/target/leopard-server-1.0.0.jar /home/ubuntu/app/leopard-server-1.0.0.jar

bash /home/ubuntu/app/stop.sh
bash /home/ubuntu/app/start.sh
