Skip to content

Instantly share code, notes, and snippets.

@dinowang
Last active September 3, 2024 16:52
Show Gist options
  • Save dinowang/8a2818c6efea515f6cf5005dbfb54807 to your computer and use it in GitHub Desktop.
Save dinowang/8a2818c6efea515f6cf5005dbfb54807 to your computer and use it in GitHub Desktop.
_update-az-extensions() {
remote_versions=$(az extension list-available --query "[?installed].{name:name, version:version}")
local_versions=$(az extension list --query "[].{name:name, installed_version:version}")
versions=$(jq -n --argjson local "$local_versions" --argjson remote "$remote_versions" '
[$local, $remote] |
transpose |
map({
name: .[0].name,
installed_version: .[0].installed_version,
version: .[1].version
})
')
outdated=$(echo "$versions" | jq -r '.[] | select(.installed_version != .version) | .name')
if [ "$outdated" == "" ];
then
echo "No outdated azcli extensions found."
else
for name in $(echo "$outdated" | awk '{gsub(/\\r\\n/,RS)} 1'); do
echo az extension update --name "$name" --allow-preview true --verbose
az extension update --name "$name" --allow-preview true --verbose
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment