#!/bin/bash

if [ "$#" -ne "2" ]; then
    echo "Usage: update-repos <filename> <releasename1,releasename2,...>"
    echo "Example: update-repos internal-latest.deb trusty,xenial,jessie"
    echo if <filename> contains 'internal', will use 'conf-internal' for configuration,
    echo otherwise default to 'conf'
    exit 1
fi


CONFDIR="+b/conf"

if [[ $1 == *"internal"* ]]; then
  CONFDIR="+b/conf-internal"
  echo "Update-repos: Overriding default config; using internal/experimental configuration"
else
  echo "Update-repos: Packaging $1 for $2"
fi


cd /var/www/packages.swarmops.com

IFS=',' read -r -a distros <<< "$2"
unset IFS

for debianRelease in "${distros[@]}"
do
    echo "Publishing package for $debianRelease..."
    reprepro --component contrib --confdir $CONFDIR --ask-passphrase includedeb $debianRelease $1
done

cd /home/builder/swarmops/packaging

