#!/bin/bash
#
# Securely sends a file or standard input to a SSDT web server.
# e.g:
#     capture.sh | send.sh -   # sends log files to ssdt server for the current project
#     send.sh docker-compose.yml  # sends the compose file
#
source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"

file=${1?"Usage: $0 filename [name]\n specify the filename relative to the current directory or - for stdin.\noptionally specify a short name (default to base directory)"}
if [ "$file" != "-" ]
then
   file="/tmp/${file}"
fi
name=${2:-$(basename $PWD)}
source=$(hostname)

docker run -i -v $SSDT_HOME:/ssdt -v ${PWD}:/tmp --rm docker.ssdt-ohio.org/ssdt-utils \
   curl -F source=$source -F name=$name -F file=@$file https://upload.ssdt-ohio.org/upload
