#!/bin/bash

#  Copyright (c) 2016, Oracle and/or its affiliates.  All rights reserved.
#  
#  This software is dual-licensed to you under the MIT License (MIT) and
#  the Universal Permissive License (UPL).  See the LICENSE file in the root
#  directory for license terms.  You may choose either license, or both.
#  

if [[ "$1" == '--help' || "$1" == '-h' ]]
	then
	echo "get-activation-policy usage: ./get-activation-policy ACTIVATION_TOKEN ACTIVATION_ID IOTSERVER PORT"
	exit 0
fi

echo "============================================================================================"
echo "Step 4: Get activation policy"
echo "Acquiring activation policy..."
if [ -n "$ACCESS_TOKEN" ] && [ -n "$ACTIVATION_ID" ] && [ -n "$IOTSERVER" ] && [ -n "$PORT" ]
then
	echo -e "\ncURL command: "
	echo -e "curl -H \"Accept:application/json\" -H \"Authorization: Bearer $ACCESS_TOKEN\" -H \"X-ActivationId: $ACTIVATION_ID\" \"$IOTSERVER:$PORT/iot/api/v2/activation/policy?OSName=Windows+7&OSVersion=6.1\""
	echo -e "\nResponse: "
	curl -H "Accept:application/json" -H "Authorization: Bearer $ACCESS_TOKEN" -H "X-ActivationId: $ACTIVATION_ID" "$IOTSERVER:$PORT/iot/api/v2/activation/policy?OSName=Windows+7&OSVersion=6.1"
elif [ $# -eq 4 ]
then
	echo -e "\ncURL command: "
	echo -e "curl -H \"Accept:application/json\" -H \"Authorization: Bearer $1\" -H \"X-ActivationId: $2\" \"$3:$4/iot/api/v2/activation/policy?OSName=Windows+7&OSVersion=6.1\""
	echo -e "\nResponse: "
	curl -H "Accept:application/json" -H "Authorization: Bearer $1" -H "X-ActivationId: $2" "$3:$4/iot/api/v2/activation/policy?OSName=Windows+7&OSVersion=6.1"
else
	echo "get-activation-policy usage: ./get-activation-policy ACTIVATION_TOKEN ACTIVATION_ID IOTSERVER PORT"
	exit 1
fi
echo


