2018-04-27 20:22:26 +03:00
|
|
|
#!/bin/bash -e
|
2018-04-27 22:42:18 +03:00
|
|
|
# Set defaultValues for optional args
|
|
|
|
artifactsStagingDirectory='.'
|
|
|
|
createUIDefFile='createUIDefinition.json'
|
|
|
|
|
2018-04-27 20:22:26 +03:00
|
|
|
while getopts "a:l:s:f:g" opt; do
|
|
|
|
case $opt in
|
|
|
|
a)
|
2018-04-27 22:42:18 +03:00
|
|
|
artifactsStagingDirectory=$OPTARG #the folder for the createUIDefinition.json file
|
2018-04-27 20:22:26 +03:00
|
|
|
;;
|
|
|
|
l)
|
|
|
|
storageLocation=$OPTARG #location for the staging storage account if it needs to be created
|
|
|
|
;;
|
|
|
|
f)
|
2018-04-27 22:42:18 +03:00
|
|
|
createUIDefFile=$OPTARG
|
2018-04-27 20:22:26 +03:00
|
|
|
;;
|
|
|
|
g)
|
|
|
|
gov='false'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2018-04-29 19:01:43 +03:00
|
|
|
|
2018-10-19 19:46:26 +03:00
|
|
|
#you must be logged into azure before running this script - run "az login"
|
2018-04-27 20:22:26 +03:00
|
|
|
subscriptionId=$( az account show -o json | jq -r '.id' )
|
2019-12-11 21:26:42 +03:00
|
|
|
subscriptionId="${subscriptionId//-/}"
|
2018-04-27 20:22:26 +03:00
|
|
|
subscriptionId="${subscriptionId:0:19}"
|
|
|
|
artifactsStorageAccountName="stage$subscriptionId"
|
2019-12-11 21:26:42 +03:00
|
|
|
artifactsResourceGroupName="ARM_Deploy_Staging"
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
echo "Checking for storage account..."
|
2018-04-27 20:22:26 +03:00
|
|
|
if [[ -z $( az storage account list -o json | jq -r '.[].name | select(. == '\"$artifactsStorageAccountName\"')' ) ]]
|
|
|
|
then
|
2019-12-11 21:26:42 +03:00
|
|
|
if [[ -z $storageLocation ]]
|
2018-04-27 20:22:26 +03:00
|
|
|
then
|
|
|
|
echo "-l (storageLocation) must be specified when storageAccount needs to be created, usually on first run for a subscription."
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-04-27 22:42:18 +03:00
|
|
|
echo "Creating storage account..."
|
2018-04-27 20:22:26 +03:00
|
|
|
az group create -n "$artifactsResourceGroupName" -l "$storageLocation"
|
|
|
|
az storage account create -l "$storageLocation" --sku "Standard_LRS" -g "$artifactsResourceGroupName" -n "$artifactsStorageAccountName" 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
artifactsStorageContainerName="createuidef-stageartifacts"
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
artifactsStorageAccountKey=$( az storage account keys list -g "$artifactsResourceGroupName" -n "$artifactsStorageAccountName" -o json | jq -r '.[0].value' )
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
az storage container create -n "$artifactsStorageContainerName" --account-name "$artifactsStorageAccountName" --account-key "$artifactsStorageAccountKey" >/dev/null 2>&1
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
uiDefFilePath="$artifactsStagingDirectory/$createUIDefFile"
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
az storage blob upload -f "$uiDefFilePath" --container $artifactsStorageContainerName -n $createUIDefFile --account-name $artifactsStorageAccountName >/dev/null
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
# Get a 4-hour SAS Token for the artifacts container. Fall back to OSX date syntax if Linux syntax fails.
|
|
|
|
plusFourHoursUtc=$(date -u -v+4H +%Y-%m-%dT%H:%MZ 2>/dev/null) || plusFourHoursUtc=$(date -u --date "$dte 4 hour" +%Y-%m-%dT%H:%MZ)
|
|
|
|
sasToken=$( az storage container generate-sas -n "$artifactsStorageContainerName" --permissions r --expiry "$plusFourHoursUtc" --account-name "$artifactsStorageAccountName" --account-key "$artifactsStorageAccountKey" -o json | sed 's/"//g')
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
blobEndpoint=$( az storage account show -n "$artifactsStorageAccountName" -g "$artifactsResourceGroupName" -o json | jq -r '.primaryEndpoints.blob' )
|
|
|
|
createUIDefUrl=$blobEndpoint$artifactsStorageContainerName/$createUIDefFile?$sasToken
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
createUIDefUrlEncoded=$(printf %s "$createUIDefUrl" | jq -s -R -r @uri)
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2019-12-11 21:26:42 +03:00
|
|
|
if [[ $gov ]]
|
2018-04-29 19:01:43 +03:00
|
|
|
then
|
2019-10-07 23:26:34 +03:00
|
|
|
target="https://portal.azure.us/#blade/Microsoft_Azure_Compute/CreateMultiVmWizardBlade/internal_bladeCallId/anything/internal_bladeCallerParams/{"\""providerConfig"\"":{"\""createUiDefinition"\"":"\""$createUIDefUrlEncoded"\""}}"
|
2018-04-29 19:01:43 +03:00
|
|
|
else
|
2019-10-07 23:26:34 +03:00
|
|
|
target="https://portal.azure.com/#blade/Microsoft_Azure_Compute/CreateMultiVmWizardBlade/internal_bladeCallId/anything/internal_bladeCallerParams/{"\""providerConfig"\"":{"\""createUiDefinition"\"":"\""$createUIDefUrlEncoded"\""}}"
|
2018-04-29 19:01:43 +03:00
|
|
|
fi
|
2018-04-27 20:22:26 +03:00
|
|
|
|
2018-04-27 22:42:18 +03:00
|
|
|
echo "Launch browser with this URL:"
|
|
|
|
echo
|
|
|
|
echo $target
|
2019-12-11 21:26:42 +03:00
|
|
|
echo
|
2018-04-29 19:01:43 +03:00
|
|
|
|
|
|
|
#note chrome will not launch with the encoded url no idea why - copy/paste works (or safari)
|
|
|
|
python -mwebbrowser $target
|