#!/bin/bash INSTALL_DIR="${PWD}" # Check system requirements: Git, Node & NPM EXC_GIT="$(/usr/bin/which git)" if [ -z "$EXC_GIT" ]; then echo "[ERROR] Missing required system dependency 'git'." >&2 echo "Please install using \"apt install git\"" >&2 exit 1 fi EXC_DOCKER="$(/usr/bin/which docker)" if [ -z "$EXC_DOCKER" ]; then echo "[ERROR] Missing required system dependency 'docker'." >&2 echo "Please install using the official documentation." >&2 exit 1 fi GCC_CONFIG_DIR="${INSTALL_DIR}/google-cloud" FCM_ACCOUNT_JSON="${GCC_CONFIG_DIR}/firebase-adminsdk.json" if [ ! -d "$GCC_CONFIG_DIR" ]; then echo "[ERROR] Missing required google cloud key files. Please prepare directory 'google-cloud' in install directory." >&2 exit 1 fi if [ ! -f "$FCM_ACCOUNT_JSON" ]; then echo "[ERROR] Missing required Firebase Admin SDK key file. Please provide this file as 'google-cloud/firebase-adminsdk.json' in order to install." >&2 exit 1 fi # exit on error exit codes set -e TMPFOLDER="/tmp/hbbq/monitoring/$(date +'%Y%m%d%H%M%S')" echo "[INSTALL] Cloning entire project into temp folder $TMPFOLDER" mkdir -p "$TMPFOLDER" git clone https://gogs.hostbbq.com/hostbbq/hostbbq-monitoring.git "$TMPFOLDER" cd "$TMPFOLDER" echo "[INSTALL] Cloning submodules ..." git submodule init git submodule update if [[ -f "$INSTALL_DIR/.env" ]]; then export $(cat "$INSTALL_DIR/.env" | xargs) fi if [[ ! -d "$PWD/$DATA_DIR" ]]; then mkdir "$PWD/$DATA_DIR" fi if [[ ! -d "$PWD/$DB_DIR" ]]; then mkdir "$PWD/$DB_DIR" fi docker compose -f server.docker-compose.yml build echo "[INSTALL] Installing server application" if [ -d "$INSTALL_DIR/dist" ]; then rm -rf "$INSTALL_DIR/dist" fi if [ ! -f "$INSTALL_DIR/.env" ]; then cp -v ".env.default" "$INSTALL_DIR/.env" fi cp -v "server.docker-compose.yml" "$INSTALL_DIR/docker-compose.yml" cd "$INSTALL_DIR" DATA_VOLUME_DIR="$PWD/$DATA_DIR" \ DB_VOLUME_DIR="$PWD/$DB_DIR" \ COMPOSE_PROJECT_NAME="monitoring-server" \ docker compose up -d echo "[CLEANUP] Removing temp folder $TMPFOLDER" rm -rf "$TMPFOLDER" echo "[SUCCESS] HostBBQ Monitoring Server installed and activated successfully"