Description
The Script Update Module allows to execute any general purpose script or binary on the target device. A Mender Artifact containing one or more executables (usually scripts) is sent to the device, where the Update Module will execute these during the ArtifactInstall
state.
If multiple scripts are provided, they will be executed in alphabetical order on the device.
Example use-cases:
- Restart application into diagnostic mode
- Run diagnostics script
- Execute any other generic command
Specification
Module name | script |
Supports rollback | no |
Requires restart | no |
Artifact generation script | no |
Full operating system updater | no |
Source code | Update Module |
Maintainer | Community |
Please be aware that Mender Update modules are meant to update parts of the operating system and if not configured properly they could potentially delete parts or the complete operating system. Always inspect the code carefully and only test modules on a device that you can recover easily.
It is not recommended to install a Mender Artifact on your workstation
Prepare the device
This section describes how to setup your target device, i.e. the device to be updated. This will also be referred to as the device environment.
All commands outlined in this section should be run in the device environment.
Prerequisites
This update module has the following prerequisites for the device environment:
- Install the Mender client, version 2.0 or later
- Ensure the device has a Bash Unix shell
- How to install this depends on which OS you are running
Install the Update Module
Download the latest version of this Update Module by running:
mkdir -p /usr/share/mender/modules/v3 && wget -P /usr/share/mender/modules/v3 https://raw.githubusercontent.com/mendersoftware/mender/master/support/modules/script
Prepare the development environment on your workstation
This section describes how to set up your development environment on your workstation.
All commands outlined in this section should be run in the development environment.
Prerequisites
This Update Modules has the following prerequisites for the development environment:
- Install mender-artifact, version 3.1.0 or later
Create Mender Artifacts
The Artifact can be generated using mender-artifact
tool.
Create example content to deploy:
cat > my-script-1.sh << EOF
#!/bin/bash
echo "$(basename "$0") was executed on device!" > /tmp/my-script-1.txt
EOF
cat > my-script-2.sh << EOF
#!/bin/bash
echo "$(basename "$0") was executed on device!" > /tmp/my-script-2.txt
EOF
Now generate a Mender Artifact using the following command:
ARTIFACT_NAME="my-update-1.0"
DEVICE_TYPE="my-device-type"
OUTPUT_PATH="my-update-1.0.mender"
SHELL_SCRIPTS="my-script-1.sh my-script-2.sh"
mender-artifact write module-image -T script -n ${ARTIFACT_NAME} -t ${DEVICE_TYPE} -o ${OUTPUT_PATH} -f $(echo "$SHELL_SCRIPTS" | sed -e 's/ / -f /g')
-
ARTIFACT_NAME
- The name of the Mender Artifact -
DEVICE_TYPE
- The compatible device type of this Mender Artifact -
OUTPUT_PATH
- The path where to place the output Mender Artifact. This should always have a.mender
suffix -
SHELL_SCRIPTS
- The path to the script that you wish to deploy and execute on your device. NOTE that the extension does not matter.
You can either deploy this Artifact in managed mode with the Mender server (upload it under Releases in the server UI) or by using the Mender client only in Standalone deployments.
Artifact technical details
The Mender Artifact used by this Update Module has a payload with as many files as scripts are contained in the Artifact.
The Mender Artifact contents will look like:
Updates:
0:
Type: script
Provides: Nothing
Depends: Nothing
Metadata: Nothing
Files:
name: my-script-1.sh
size: 140
modified: 2019-03-05 18:34:43 +0100 CET
checksum: 065714b581785a2d7c83b684f0d5348031c5512f21863fed38197078cb3ef6e5
Files:
name: my-script-2.sh
size: 139
modified: 2019-03-05 18:34:54 +0100 CET
checksum: 9fca4ec0f65f960d1ac2dfd311e32070b62c26f35968c8002c16d39ccdb1330a