#!/usr/bin/env bash
set -Eeuo pipefail
cd "${BASH_SOURCE%/*}/"

yellow "Ubuntu maintenence..."
ssh "$TLD" sudo apt-get update
ssh "$TLD" sudo apt-get upgrade -y
ssh "$TLD" sudo apt-get install -y docker-compose
ssh "$TLD" sudo apt-get autoremove -y
green "Done.\n"

yellow "Copy over files..."
ssh "$TLD" mkdir -p /home/vps/
envsubst < docker-compose.yaml > docker-compose.yaml.fd
scp docker-compose.yaml.fd "$TLD":/home/vps/docker-compose.yaml
rm docker-compose.yaml.fd
green "Done.\n"

yellow "Restart docker-compose"
ssh "$TLD" "cd /home/vps/ && docker-compose down"
ssh "$TLD" "cd /home/vps/ && docker-compose up -d"
green "Done.\n"
