The package to update a Thing device contains scripts that are run on the gateway where the Thing device is connected.

To enable package script development, VMware Pulse IoTC Agent runs the package scripts with the TARGET_THINGS environment variable. This environment variable contains the space-separated Thing IDs that the campaign targets for updates.

Base on these Thing IDs, you as a script developer can obtain the required properties from the VMware Pulse IoTC Agent's iotc-agent-cli command-line tool.

Sample Campaign Script

This following sample script provides information about updating the IP cameras that are connected to a gateway:
#!/usr/bin/env bash
if [ -z "$TARGET_THINGS" ];
then
    echo "No cameras are provided"
    exit 0
fi
 
# convert target thing ids to array
camera_ids=("$TARGET_THINGS")
 
for camera_id in "${camera_ids[@]}"
do
    echo "Updating IP camera with device ID=$camera_id"
 
    # Get the required thing properties
    camera_ip=`/opt/vmware/iotc-agent/bin/iotc-agent-cli get-properties --device-id="$camera_id" --type=custom --property-name="IP"`
    # The get operation might fail, so appropriate error handling can be added here.
    camera_ip_successfully_retrieved=$?
    echo "Camera IP: $camera_ip"
    curl http://${camera_ip}/cgi/UpdateFirmware filename=firmware.bin
    update_result=$?
     
    if [ 0 -ne $update_result ]
    then
        failed_updates+=("$camera_id")
    fi
done
 
if [ ${#failed_updates[@]} -ne 0 ];
then
    echo "The update failed for: ${failed_updates[@]}"
    exit 1
fi
echo "Successful"
exit 0
In this example, camera_ip=`/opt/vmware/iotc-agent/bin/iotc-agent-cli get-properties --device-id="$camera_id" --type=custom --property-name="IP"` gets the required properties of the IP camera such as IP address using the IP camera ID.

curl http://${camera_ip}/cgi/UpdateFirmware filename=firmware.bin sends the firmware updates to the IP cameras from the location mentioned in the script.

The following part of the script describes the error handling information when an update fails for one of the IP cameras:
if [ 0 -ne $update_result ]
    then
        failed_updates+=("$camera_id")
    fi
done
 
if [ ${#failed_updates[@]} -ne 0 ];
then
    echo "The update failed for: ${failed_updates[@]}"
    exit 1
fi