#!/bin/bash set -e set -x flags="" print_help() { echo " Pleroma Maintenance Script Usage: $0 [action] Actions: build Rebuild the pleroma container purge Remove the pleroma container and all build caches start / up Start pleroma and sibling services stop / down Stop pleroma and sibling services restart Executes #stop and #start respectively. status / ps Show the current container status logs Show the current container logs enter Enter the pleroma container for debugging/maintenance " } render_template() { m4 $flags docker-compose.m4 | awk 'NF' } docker_compose() { render_template | docker-compose -f - "$@" } load_env() { if [[ ! -f .env ]]; then echo "Please create a .env file first" echo "(Copy .env.dist to .env for a template)" exit 1 fi while read -r line; do if [[ "$line" == \#* ]] || [[ -z "$line" ]]; then continue; fi export "${line?}" flags="-D__${line?} $flags" done < .env } action__start() { docker_compose up --remove-orphans -d; } action__up() { action__start; } action__stop() { docker_compose down; } action__down() { action__stop; } action__restart() { action__stop; action__start; } action__logs() { docker_compose logs -f; } action__build() { docker_compose build --build-arg __BUST_CACHE="$(date +%s)" server; } action__enter() { docker_compose exec server ash; } action__status() { docker_compose ps; } action__ps() { action__status; } action__debug() { render_template; } action__lint() { render_template | jq; } if [[ -z "$1" ]]; then print_help exit 1 fi load_env actions=(build update purge start up stop down restart logs enter status ps debug lint) if [[ ${actions[*]} =~ ${1} ]]; then "action__${1}" else print_help exit 1 fi