-
Notifications
You must be signed in to change notification settings - Fork 19
/
get-marketplace-offer.sh
executable file
·61 lines (57 loc) · 2.22 KB
/
get-marketplace-offer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Exit if any of the intermediate steps fail
set -e
# Default values for arguments
publisher="fortinet"
location="canadacentral"
offer="fortiweb"
sku="payg"
plan="$sku"
version="latest"
# Loop through arguments and process them based on switch
while [[ "$#" -gt 0 ]]; do
case "$1" in
-p|--publisher) # Handle the publisher switch
publisher="$2"
shift 2
;;
-l|--location) # Handle the location switch
location="$2"
shift 2
;;
-f|--offer) # Handle the offer switch
offer="$2"
shift 2
;;
--sku) # Handle the SKU switch
sku="$2"
plan="$2" # Sets plan to the same value as sku unless explicitly set later
shift 2
;;
--plan) # Handle the plan switch, independent of SKU if needed
plan="$2"
shift 2
;;
--version) # Handle the version switch
version="$2"
shift 2
;;
-h|--help) # Handle help switch
echo "Usage: $0 [--publisher ${publisher}] [--location ${location}] [--offer (fortigate|fortiweb)] [--plan or --sku (payg|byol|fortiflex)] [--version ${version}]"
exit 0
;;
*) # Handle unknown option
echo "Unknown option: $1"
echo "Try '$0 --help' for more information."
exit 1
;;
esac
done
if [[ "${publisher}" == "fortinet" && "${sku}" != *"pay"* ]]; then
az vm image list --publisher "${publisher}" --location "${location}" --all -o json --query "sort_by([?contains(offer, '${offer}') && !contains(sku, '${sku}')], &version)[-1]"
elif [[ "${publisher}" == "fortinet" ]]; then
az vm image list --publisher "${publisher}" --location "${location}" --all -o json --query "sort_by([?contains(offer, '${offer}') && contains(sku, '${sku}')], &version)[-1]"
else
az vm image list --publisher "${publisher}" --location "${location}" --all -o json --query "sort_by([?contains(offer, '${offer}')"
az vm image list --publisher "${publisher}" --location "${location}" --sku "22_04-lts-gen2" --offer "0001-com-ubuntu-server-jammy" --all -o json --query "sort_by(@, &version)[-1]"
fi