#!/bin/bash

# get all running docker container names
containers=$(sudo docker ps | awk '{if(NR>1) print $NF}')

# loop through all containers

if [ "$1" == "stop" ] ; then
	for container in $containers
	do
    if [ "$container" != "borgmatic" ] ; then
      docker stop "$container"  
    fi
	done
else
	for container in $containers
	do
    if [ "$container" != "borgmatic" ] ; then
      RESTART_POLICY=docker inspect -f "{{ .HostConfig.RestartPolicy }}" "$container" #always, on-failure, unless-stopped, no
      if [ "$RESTART_POLICY" != "{no 0}" ] ; then
        docker start "$container"
      fi
    fi
	done
fi;