-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetIotHubConnectionString.sh
31 lines (24 loc) · 1.11 KB
/
setIotHubConnectionString.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
#!/bin/bash
device_name="MyDotnetDevice"
echo "Getting IoT Values values"
echo
iot_hub_name=$(az iot hub list --query "[].name" --output tsv)
iot_hub_name=$(echo "$iot_hub_name" | tr -d '\r')
echo "iot_hub_name:" $iot_hub_name
iot_hub_device=$(az iot hub device-identity list --hub-name $iot_hub_name --query "[?deviceId == '$device_name'].deviceId")
iot_hub_device=$(echo "$iot_hub_device" | tr -d '\r')
echo "iot_hub_device:" $iot_hub_device
if [[ $iot_hub_device == *"$device_name"* ]]; then
echo "Device exists"
else
echo "Create Device"
az iot hub device-identity create --hub-name $iot_hub_name --device-id $device_name
fi
iot_hub_connection_string=$(az iot hub device-identity connection-string show --hub-name $iot_hub_name --device-id $device_name --query "connectionString")
iot_hub_connection_string=$(echo "$iot_hub_connection_string" | tr -d '\r')
echo "iot_hub_connection_string:" $iot_hub_connection_string
echo "Create appsettings.json"
echo
app_settings="{\"IoTHubConnectionString\": $iot_hub_connection_string}"
jq -n "$app_settings" > ./IoTDevice/appsettings.json
cat ./IoTDevice/appsettings.json