#!/bin/bash
#
# Upload locally generated artifacts to cloudsmith. Assumes that  single
# *.xml and *.tar.gz are available.
#
# Usage:
#   local-upload [build directory]
#
#   *build-directory* is assumed to contain  upload.sh generated by the 
#   build
#
# Files:
#    ~/.config/local-build.rc
#       Used to populate environment, typically containing lines
#       like 'export CLOUDSMITH_API_KEY=xxxxx'. This file should be
#       protected from other users, normally 600. 
if [ -d /c ]; then  # windows
    config_file="$APPDATA/local-build.rc"
else
    config_file="~/.config/local-build.rc"
fi
if [[ -z  "$CLOUDSMITH_API_KEY" && ! -f "$config_file" ]]; then
    echo "Can't find configuration file $config_file Giving up"
    exit 1
else
    source $config_file
fi

if [ $# -eq 1 ]; then
    cd $1
    shift
fi
if [  $# -gt  0 ]; then
    echo "Usage: local-upload [build direcctory]"
    exit 1
fi

if [ -x upload.sh ]; then
    ./upload.sh
else
    echo "Cannot find upload.sh"
    exit 1
fi
