#!/bin/bash

# dpns - docker pull & save
#
# Authors:
#   Thomas Liske <thomas@fiasko-nw.net>
#
# Copyright Holder:
#   2018 - 2020 (C) Thomas Liske [https://github.com/liske/dpns]
#
# License:
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this package; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

DPNS_COMPOSES=()
. ${0%run}load

if [ "${#DPNS_COMPOSES[*]}" = "0" ]; then
  echo "Empty compose list."
  exit 0
fi

for dn in ${DPNS_COMPOSES[*]}; do
    if [ -d "$dn" ]; then
        cd "$dn" && docker-compose up -d
    else
        cf=$(basename $dn)
        dn=$(dirname $dn)
        cd "$dn" && docker-compose -f "$cf" up -d
    fi
done
