Last active
December 15, 2018 14:59
-
-
Save immanuelpotter/b909ab3ca93f62b3bec84ba0ba265877 to your computer and use it in GitHub Desktop.
Signing an Azure VHD to share on the marketplace.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RESOURCE_GROUP="$1" | |
OS_DISK="$2" | |
err_and_exit(){ | |
if [[ -z "$RESOURCE_GROUP" || -z "$OS_DISK" ]] ; then | |
echo "Supply the Resource Group as argument 1. Supply the VHD image argument 2, including full path in blob storage." | |
fi | |
} | |
main(){ | |
err_and_exit | |
CONNECTION_STRING=$(az storage account show-connection-string --name ${RESOURCE_GROUP} | awk '{print $2}' | tr -d '\n') | |
az storage blob list --container-name system --connection-string ${CONNECTION_STRING} >/dev/null || exit 92 | |
if [[ "$?" -eq 0 ]] ; then | |
SAS="$(az storage container generate-sas --name system \ | |
--permissions rl --expiry $(date -d '+30 days' +%Y-%m-%dT%H:%M:%SZ) | |
--start "$(date -d '-1 days' +%Y-%m-%dT%H:%M:%SZ)" | |
--connection-string ${CONNECTION_STRING} | tr -d '"')" | |
fi | |
FULL_STRING="${OS_DISK}?${SAS}" | |
curl -I 'https://${RESOURCE_GROUP}.blob.core.windows.net/'${OS_DISK}'?'${SAS} 2>/dev/null || exit 53 | |
echo $FULL_STRING > marketplace-sas.txt | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment