Installation Helper Script

The following script automates enrolment of Edge Agent on Debian. It should be run as root so that it has permission to run Edge Agent processes as the eauser and eagateway users.

Note: The script does not modify the system time; enrollment may fail if the clock is not set correctly.
#!/bin/bash

set -e

ENROLL_INPUT="/var/lib/edge-agent/config/enrollment-input.json"
ENROLL_OUTPUT="/var/lib/edge-agent/config/enrollment-output.json"

if [ ! -f $ENROLL_OUTPUT ]; then
   if [ ! -f $ENROLL_INPUT ] || jq -e 'any(.[]; . == "")' $ENROLL_INPUT; then
      printf "First, make sure you have created your device on Edge Manager, "
      printf "and note the 'Device ID' and 'Secret' you used.\n\n"

      read -p "Enter the enrollment URL:" url
      read -p "Enter the device ID:" ID
      read -p "Enter the device secret:" secret

      url="$url" ID="$ID" secret="$secret" jq -n \
         '{deviceId: env.ID, sharedSecret: env.secret, enrollmentUrl: env.url}' \
         > $ENROLL_INPUT
   fi

   echo "Attempting device enrollment..."
   if ! su eauser -s /bin/bash -c "/opt/edge-agent/edge-agent-enrollment $ENROLL_INPUT"; then
      echo "Enrollment failed"
      exit 1
   fi
   echo "Enrollment succeeded"
fi

echo "Edge Agent is enrolled"