Mender-convert - Include state scripts in the artifact

Hi,

I couldn’t find any further documentation on this topic and trial and error is taking me a long time because mender-convert takes quite a while to create a new image version:

What is the correct approach to embedding state scripts in a mender-convert artifact?

I have a state script called: ArtifactReboot_Leave_00_verify-modem-up and I need to deploy this with my update artifact.

It is correct to place the script in /etc/mender/scripts (So: /etc/mender/scripts/ArtifactReboot_Leave_00_verify-modem-up would be the path of the script)? Do I need anything else? I found a post the says some version file is required? What is the correct format for this file?

Any help would be greatly appreciated.

Hi @c3ntry you include root filesystem scripts in /etc/mender/scripts via the overlay but Artifact scripts need to be added into the artifact when mender-artifact is invoked. You can see docs about the different types of scripts here.

To add Artifact scripts with mender-convert, you need to override the mender_create_artifact function with one of your own that adds the appropriate ‘–script value’ options. For reference, the default function is here.

Basically you create your own config file and then add an extra –config my-custom-config to your invocation of mender-convert. The custom config file would look something like:

mender_create_artifact() {
  local -r device_type="${1}"
  local -r artifact_name="${2}"
  local -r image_name="${3}"

  mender_artifact=deploy/${image_name}.mender
  log_info "Writing Mender artifact to: ${mender_artifact}"
  log_info "This can take up to 20 minutes depending on which compression method is used"

  run_and_log_cmd "mender-artifact --compression ${MENDER_ARTIFACT_COMPRESSION} \
      write rootfs-image \
      --file work/rootfs.img \
      --output-path ${mender_artifact} \
      --artifact-name ${artifact_name} \
      --script <full-path-to>/ArtifactReboot_Leave_00_verify-modem-up \
      --device-type ${device_type}"
}

The version file is created automatically by the mender-convert-modify portion of mender-convert.

Drew

1 Like