forked from ralarcon/iothub-bc-dr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-deploy.sh
32 lines (22 loc) · 1.7 KB
/
build-deploy.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
#!/bin/bash
## This script builds the simulator and deploys it to the edge device
## It assumes that the edge device is already created and running
## Ensure that the env.vars.sh script is executable by running: chmod +x env.vars.sh
## Run the script by running: ./build-deploy.sh
source ${BASH_SOURCE%/*}/variables.sh
source ./IotDeviceSimulator/env.vars.sh
echo "Cleaning up simulator output folder."
rm -rf ./IotDeviceSimulator/output
echo "Cleaning up simulator folder on edge device."
VM_NAME=$(az vm list -g $RSG -d --query "[?starts_with(fqdns,'$VM_DNS_PREFIX')].name" -o tsv)
az vm run-command invoke -g $RSG -n $VM_NAME --command-id RunShellScript --scripts "rm -rf /home/azureUser/iot-device-simulator && mkdir /home/azureUser/iot-device-simulator && chown azureUser /home/azureUser/iot-device-simulator"
echo "Publish content."
dotnet publish ./IotDeviceSimulator/iot-device-simulator.csproj -c release -r linux-x64 --self-contained true --output ./IotDeviceSimulator/output
sed -i 's/##REPLACE_IOT_HUB_CONNSTR##/'$IOT_HUB_CONNSTR'/g' ./IotDeviceSimulator/output/run-simulator.sh
sed -i 's/##REPLACE_DEVICE_CONNSTR##/'$DEVICE_CONNSTR'/g' ./IotDeviceSimulator/output/run-simulator.sh
chmod +x ./IotDeviceSimulator/output/iot-device-simulator
echo "Copying simulator to edge device."
VM_FQDN=$(az vm show -d --resource-group $RSG --name $VM_NAME --query "fqdns" -o tsv)
scp -P 2223 -i ~/.ssh/$SSH_KEY_NAME -pr ./IotDeviceSimulator/output/* azureUser@$VM_FQDN:/home/azureUser/iot-device-simulator
echo "To run the simulator, run remotely the run-simulator.sh script with the following command:"
echo 'ssh -p 2223 -i ~/.ssh/$SSH_KEY_NAME azureUser@$VM_FQDN "cd /home/azureUser/iot-device-simulator/;./run-simulator.sh"'