#!/bin/bash

set -e

VOLUME_OR_PATH=$1
COMPONENT=$2

if [[ -z ${VOLUME_OR_PATH} || -z ${COMPONENT} ]]; then
    echo "Usage: $0 volume-or-path component"
    exit 1;
fi

if [ -z $4 ]; then
    CMD=""
else
    CMD=$4
fi


docker build -t upload-debs \
        -f upload-debs.Dockerfile \
        --build-arg USER_NAME=${USER} \
        --build-arg USER_ID=`id -u` .

docker run \
    -i \
    -u `id -u` \
    --rm \
    -v ${VOLUME_OR_PATH}:/debs \
    -v ~/.ssh/id_rsa.repo.evernym.com:/home/${USER}/.ssh/id_rsa.repo.evernym.com \
    -v ~/.ssh/id_rsa.repo.sovrin.org:/home/${USER}/.ssh/id_rsa.repo.sovrin.org  \
    -e COMPONENT=$COMPONENT \
    upload-debs $CMD
