#!/bin/sh set -e DOCKER_IMAGE_NAME=device-image-shell OUTPUT_DIR="$(pwd)/output" show_usage() { echo "Usage:" echo "$0 " } if [ "$#" -ne 3 ]; then echo "ERROR: 3 parameters required." show_usage exit 1 fi ROOTFS_INPUT_FILE=$1 ARTIFACT_NAME=$2 DEVICE_TYPE=$3 if [ ! -f "$ROOTFS_INPUT_FILE" ]; then echo "ERROR: File passed as first argument is not accessible." echo "Got ROOTFS_INPUT_FILE=\"$ROOTFS_INPUT_FILE\"" show_usage exit 1 fi mkdir -p $OUTPUT_DIR ROOTFS_INPUT_FILE_NAME="$(basename -- $ROOTFS_INPUT_FILE)" ROOTFS_INPUT_FILE_EXTENSION="${ROOTFS_INPUT_FILE_NAME##*.}" ROOTFS_OUTPUT_FILE_NAME="$ARTIFACT_NAME.$ROOTFS_INPUT_FILE_EXTENSION" echo "Copying rootfs input file..." rsync -h --progress $ROOTFS_INPUT_FILE $OUTPUT_DIR/$ROOTFS_OUTPUT_FILE_NAME docker run \ -ti \ --privileged=true \ --mount type=bind,source=$OUTPUT_DIR,target=/root_images \ $DOCKER_IMAGE_NAME $ROOTFS_OUTPUT_FILE_NAME $ARTIFACT_NAME $DEVICE_TYPE # Output Artifact gets root owner and group, change to current logged in CURRENT_USER=$(id -u -n) CURRENT_GROUP=$(id -g -n) echo "Changing ownership of Mender Artifact (may ask you to authenticate)" sudo chown $CURRENT_USER:$CURRENT_GROUP $OUTPUT_DIR/$ARTIFACT_NAME.mender echo "Image generation complete!" /bin/echo -e "The new root file system is at:\n\t$OUTPUT_DIR/$ROOTFS_OUTPUT_FILE_NAME" /bin/echo -e "The new Mender Artifact you can upload to your Mender server to deploy to your devices is at:\ \n\t$OUTPUT_DIR/$ARTIFACT_NAME.mender"