Can a state script access update information?

Hi,
We’re running a service which would need to access some data from the update, such as the future version.
Is there a way to access this in a state script before rebooting? Environment variables during state scripts or reading a file (json or so) would be great as it’s easily readble.

In the worst case, I could get the version by opening /etc/mender/artifact_info of the other partition

Not directly. However, if you’re using Yocto you can autogenerate a state script which contains the value of MENDER_ARTIFACT_NAME and store it somewhere for the bigger script to read. Something aka:

do_compile_append() {
    cat > ${WORKDIR}/00_ArtifactInstall_Enter <<EOF
#!/bin/sh
echo ${MENDER_ARTIFACT_NAME} > /tmp/new-artifact-name
EOF
    install -m 755 ${WORKDIR}/00_ArtifactInstall_Enter ${MENDER_STATE_SCRIPTS_DIR}
}

Btw, the /etc/mender/artifact_info is not guaranteed to work in 2.0.0 and beyond, because it stores this info in the database instead. If you use rootfs updates only, it will usually coincide, but not when using update modules.

I’m not using the 2.0 yet but that’s good to know. Is this example available in the documentation? I think it would be great to access some metadata during the update