Browse Source

Merge pull request #468 from oleorhagen/MEN-5594

feat: Install a bootstrap Artifact along with the client
automatic_bootstrap_artifact
oleorhagen 2 years ago
committed by GitHub
parent
commit
d91ecc9bd8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      mender-convert-modify
  2. 35
      mender-convert-package
  3. 33
      modules/versioncmp.sh

5
mender-convert-modify

@ -204,11 +204,6 @@ fi
run_and_log_cmd "echo 'device_type=${device_type}' > work/device_type" run_and_log_cmd "echo 'device_type=${device_type}' > work/device_type"
run_and_log_cmd "sudo install -m 0444 work/device_type work/rootfs/data/mender/" run_and_log_cmd "sudo install -m 0444 work/device_type work/rootfs/data/mender/"
if [ "${MENDER_CLIENT_INSTALL}" = "y" ]; then
run_and_log_cmd "echo 'artifact_name=${MENDER_ARTIFACT_NAME}' \
| sudo tee work/rootfs/etc/mender/artifact_info"
fi
log_info "Creating state scripts version file." log_info "Creating state scripts version file."
case "${MENDER_CLIENT_VERSION}" in case "${MENDER_CLIENT_VERSION}" in
1*) VERSION_STRING='2' ;; 1*) VERSION_STRING='2' ;;

35
mender-convert-package

@ -39,6 +39,7 @@ echo "Running $(basename $0): $@"
source modules/bootstrap.sh source modules/bootstrap.sh
source modules/disk.sh source modules/disk.sh
source modules/testscfg.sh source modules/testscfg.sh
source modules/versioncmp.sh
# The mender_convert_config is always used and provides all the defaults # The mender_convert_config is always used and provides all the defaults
declare -a configs=("configs/mender_convert_config") declare -a configs=("configs/mender_convert_config")
@ -199,11 +200,19 @@ else
log_fatal "Could not determine root file-system type. Aborting..." log_fatal "Could not determine root file-system type. Aborting..."
fi fi
disk_create_file_system_from_folder "work/rootfs/data/" "work/data.img" \ # NOTE: Since the data partition has a dependency on the rootfs.img checksum
"${data_part_sectors}" "${image_fs_type}" # when writing the bootstrap Artifact we have to move the datadir out of the
# way, and write the rootfs image first.
# Clear this area as it will be contained in the data.img run_and_log_cmd "mv --force work/rootfs/data work/data"
sudo rm -rf work/rootfs/data/*
if [[ "${MENDER_CLIENT_INSTALL}" == y ]]; then
# If the client version is less than 3.4, then log a warning
if ! miminum_required_version "3.4.0" "${MENDER_CLIENT_VERSION}"; then
log_warn "You are now installing a Mender client which does not support the " \
"bootstrap Artifact present in the image. This means that updates will not " \
"work, and your image is impossible to update"
fi
fi
disk_create_file_system_from_folder "work/rootfs/" "work/rootfs.img" \ disk_create_file_system_from_folder "work/rootfs/" "work/rootfs.img" \
"${rootfs_image_sectors}" "${image_fs_type}" "${rootfs_image_sectors}" "${image_fs_type}"
@ -211,6 +220,22 @@ disk_create_file_system_from_folder "work/rootfs/" "work/rootfs.img" \
log_info "Copying root filesystem image to deploy directory" log_info "Copying root filesystem image to deploy directory"
run_and_log_cmd "cp --sparse=always work/rootfs.img deploy/${image_name}.${image_fs_type}" run_and_log_cmd "cp --sparse=always work/rootfs.img deploy/${image_name}.${image_fs_type}"
# Add the bootstrap Artifact to the data.img before packaging
# the data image
log_info "Installing the bootstrap Artifact"
rootfs_img_checksum=$(sha256sum work/rootfs.img | cut -d ' ' -f1)
run_and_log_cmd "mender-artifact write bootstrap-artifact \
--artifact-name "${MENDER_ARTIFACT_NAME}" \
--no-progress \
--device-type "${device_type}" \
--provides rootfs-image.version:"${MENDER_ARTIFACT_NAME}" \
--provides rootfs-image.checksum:${rootfs_img_checksum} \
--output-path work/data/mender/bootstrap.mender"
disk_create_file_system_from_folder "work/data/" "work/data.img" \
"${data_part_sectors}" "${image_fs_type}"
run_and_log_cmd "rm -rf work/data"
if [ "${MENDER_CLIENT_INSTALL}" != "y" ]; then if [ "${MENDER_CLIENT_INSTALL}" != "y" ]; then
log_warn "Generating Artifact with no Mender client in it; not suitable for deployment" log_warn "Generating Artifact with no Mender client in it; not suitable for deployment"
fi fi

33
modules/versioncmp.sh

@ -0,0 +1,33 @@
# Copyright 2022 Northern.tech AS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
source modules/log.sh
source modules/probe.sh .
# Compare the version of a string to a given minimum version requirement
#
# NOTE: Also works for 'master', in that sort does sort it correctly by accident.
# The same goes for all other branches/names, which are not semver.
#
# $1 - Minimum required version
# $2 - Version string
#
# @return - bool
#
function minimum_required_version() {
if [[ $# -ne 2 ]]; then
log_fatal "minimum_required_version() requires two parameters"
fi
[[ "$1" == "$(printf "$1\n$2" | sort --version-sort | head --lines 1)" ]]
}
Loading…
Cancel
Save