Last active
December 10, 2019 11:29
-
-
Save mirzak/d77ca35cc39d844e1715e77df998ecb7 to your computer and use it in GitHub Desktop.
Qt Creator - Mender script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A simple script | |
set -e | |
MENDER_SERVER_URL="https://docker.mender.io" | |
# NOTE! You need to provide your authentication set here that you are using in the Demo enviroment. | |
MENDER_SERVER_USER="" | |
MENDER_SERVER_PASS="" | |
function usage() { | |
cat << EOF | |
Usage: $0 [options] | |
Options: | |
-f, --file - Path to file to use as payload in Mender Artifact (single-file) | |
-u, --upload - Upload generated Mender Artifact to server | |
-r, --rootfs - Root filesystem image to use as base | |
EOF | |
} | |
function mender_server_login() { | |
echo "This operation requires you to login to the server (once)" | |
echo "JWT will be cached in: .mender_jwt" | |
JWT=$(curl --insecure -X POST -u ${MENDER_SERVER_USER}:${MENDER_SERVER_PASS} ${MENDER_SERVER_URL}/api/management/v1/useradm/auth/login) | |
echo -n "${JWT}" > .mender_jwt | |
} | |
function mender_server_upload() { | |
if [ ! -e .mender_jwt ]; then | |
mender_server_login | |
fi | |
JWT=$(cat .mender_jwt) | |
SIZE=`ls -l ${ARTIFACT_NAME}.mender | cut -d" " -f5` | |
curl --insecure -X POST -s -H "Authorization: Bearer $JWT" -F "size=$SIZE" -F "artifact=@${ARTIFACT_NAME}.mender" ${MENDER_SERVER_URL}/api/management/v1/deployments/artifacts | |
} | |
while (( "$#" )); do | |
case "$1" in | |
-f | --file) | |
APPLICATION_BINARY_NAME="$2" | |
shift 2 | |
;; | |
-u | --upload) | |
UPLOAD_TO_SERVER="true" | |
shift 1 | |
;; | |
-r | --rootfs) | |
ROOTFS_IMAGE="$2" | |
shift 2 | |
;; | |
*) | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
if [ -z "${APPLICATION_BINARY_NAME}" ]; then | |
usage | |
exit 1 | |
fi | |
if [ ! -e "${APPLICATION_BINARY_NAME}" ]; then | |
echo "File not found: ${PWD}/${APPLICATION_BINARY_NAME}" | |
fi | |
if [ ! -f single-file-artifact-gen ]; then | |
wget https://raw.githubusercontent.com/mendersoftware/mender/master/support/modules-artifact-gen/single-file-artifact-gen | |
chmod +x single-file-artifact-gen | |
fi | |
ARTIFACT_NAME="wearable-$(date --iso-8601=seconds)" | |
DEVICE_TYPE="colibri-imx7-emmc" | |
DEST_DIR="/usr/share/examples/quickcontrols2/wearable/" | |
if [ -n "${ROOTFS_IMAGE}" ]; then | |
sudo mount -o loop ${ROOTFS_IMAGE} /mnt | |
sudo mkdir -p /mnt/${DEST_DIR} | |
sudo cp ${APPLICATION_BINARY_NAME} /mnt/${DEST_DIR}/${APPLICATION_BINARY_NAME} | |
sudo umount /mnt | |
mender-artifact write rootfs-image \ | |
-n ${ARTIFACT_NAME} \ | |
-t colibri-imx7-emmc \ | |
-o ${ARTIFACT_NAME}.mender \ | |
--file ${ROOTFS_IMAGE} | |
else | |
./single-file-artifact-gen \ | |
-n ${ARTIFACT_NAME} \ | |
-t colibri-imx7-emmc \ | |
-d ${DEST_DIR} \ | |
-o ${ARTIFACT_NAME}.mender \ | |
${APPLICATION_BINARY_NAME} | |
fi | |
if [ "${UPLOAD_TO_SERVER}" == "true" ]; then | |
echo "Upload to server enabled..." | |
mender_server_upload | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment