#!/bin/bash

# Copyright 2019, Cachengo, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

p_flag="";
print_usage() {
  printf "Use -p to push artifacts to the artifacts server";
}

while getopts 'p' flag; do
  case "${flag}" in
    p) p_flag="true" ;;
    *) print_usage
       exit 1 ;;
  esac
done

cd ./build
env GOOS=linux GOARCH=arm64 go build github.com/cachengo/cachengo-cli
mv cachengo-cli cachengo-cli_linux_aarch64
env GOOS=linux GOARCH=amd64 go build github.com/cachengo/cachengo-cli
mv cachengo-cli cachengo-cli_linux_x86_64
env GOOS=windows GOARCH=amd64 go build github.com/cachengo/cachengo-cli
mv cachengo-cli.exe cachengo-cli_windows_x86_64.exe
env GOOS=darwin GOARCH=amd64 go build github.com/cachengo/cachengo-cli
mv cachengo-cli cachengo-cli_darwin_x86_64

if [ "$p_flag" = "true" ];
then
  scp -r '../build' shippable@artifacts.cachengo.com:~/cachengo-cli
fi
