#!/bin/bash

pwd
PROJECT_NAME="examcloud-core-questions"

mkdir -p ~/packages
cp $PROJECT_NAME-starter/target/$PROJECT_NAME-distribution.zip ~/packages

if [ "deploy" == "$1" ]; then
  echo "deploy & restart..."
  mkdir -p ~/project/examcloud
  cp ~/packages/$PROJECT_NAME-distribution.zip ~/project/examcloud

  cd ~/project/examcloud
  rm -rf $PROJECT_NAME/lib
  rm -rf $PROJECT_NAME/config

  unzip -o -q $PROJECT_NAME-distribution.zip

  cd $PROJECT_NAME
  bash stop.sh
  BUILD_ID=DONTKILLME

  sleep 10s
  bash start.sh
  BUILD_ID=DONTKILLME
fi

echo "finished..."
