From 1fe672ec65d1cca9b9a685966dc93238b6f638b6 Mon Sep 17 00:00:00 2001 From: Mikael Torp-Holte Date: Wed, 28 Sep 2022 10:36:46 +0200 Subject: [PATCH 1/2] fix: apply mender.conf demo params after applying overlays Changelog: Supplying configs/mender_convert_demo_config as a --config parameter to mender-convert will add/override polling interval parameters on top of a mender.conf file found in the overlays. Ticket: MEN-5109 Signed-off-by: Mikael Torp-Holte --- configs/mender_convert_demo_config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/mender_convert_demo_config b/configs/mender_convert_demo_config index 20f93ca..e7ccb50 100644 --- a/configs/mender_convert_demo_config +++ b/configs/mender_convert_demo_config @@ -32,4 +32,4 @@ EOF log_warn "New mender.conf contents: $(cat work/rootfs/etc/mender/mender.conf)" } -PLATFORM_MODIFY_HOOKS+=(enable_demo_configuration_in_file) +OVERLAY_MODIFY_HOOKS+=(enable_demo_configuration_in_file) From e075e0caaa286605487cad4f0559c76d1af4bc02 Mon Sep 17 00:00:00 2001 From: Mikael Torp-Holte Date: Thu, 29 Sep 2022 17:18:06 +0200 Subject: [PATCH 2/2] fix: bootstrap scripts to generate mender.conf in /etc/mender Changelog: User must now supply the overlay generated by a bootstrap script to mender-convert with the --overlay option in order for the scripts to take effect. Additionally, the bootstrap scripts may now be called from any directory. BREAKING CHANGE: see changelog Ticket: MEN-5109 Signed-off-by: Mikael Torp-Holte --- configs/mender_convert_demo_config | 2 +- mender-convert-modify | 9 --------- scripts/bootstrap-rootfs-overlay-demo-server.sh | 11 ++--------- .../bootstrap-rootfs-overlay-hosted-server.sh | 12 +++--------- ...bootstrap-rootfs-overlay-production-server.sh | 16 +++++----------- 5 files changed, 11 insertions(+), 39 deletions(-) diff --git a/configs/mender_convert_demo_config b/configs/mender_convert_demo_config index e7ccb50..d366dba 100644 --- a/configs/mender_convert_demo_config +++ b/configs/mender_convert_demo_config @@ -9,7 +9,7 @@ enable_demo_configuration_in_file() { run_and_log_cmd "mkdir -p work/rootfs/etc/mender" if [ ! -f work/rootfs/etc/mender/mender.conf ]; then - log_error "No Mender configuration file found in the work folder." + log_error 'No Mender configuration file found in the work folder. Either run a bootstrap script and pass the output directory as an overlay to mender-convert, or pass your own overlay with an $OVERLAY/etc/mender/mender.conf file.' exit 1 fi diff --git a/mender-convert-modify b/mender-convert-modify index 68e95d3..ae0efc7 100755 --- a/mender-convert-modify +++ b/mender-convert-modify @@ -190,15 +190,6 @@ EOF run_and_log_cmd "sudo cp work/mender.conf.data work/rootfs/data/mender/mender.conf" run_and_log_cmd "sudo chmod 600 work/rootfs/data/mender/mender.conf" -if [ -f input/resources/mender.conf ]; then - log_info "Installing the local mender.conf file" - run_and_log_cmd "mkdir -p work/rootfs/etc/mender" - run_and_log_cmd "cp input/resources/mender.conf work/rootfs/etc/mender" - run_and_log_cmd "sudo chmod 600 work/rootfs/etc/mender/mender.conf" -else - log_warn "No mender.conf file found in input/resources. Have you remembered to run the bootstrap script?" -fi - if [ -z "${MENDER_DEVICE_TYPE}" ]; then # Observed systems who do not have this file, e.g images generated with mkosi if [ -f work/rootfs/etc/hostname ]; then diff --git a/scripts/bootstrap-rootfs-overlay-demo-server.sh b/scripts/bootstrap-rootfs-overlay-demo-server.sh index ba98590..352186d 100755 --- a/scripts/bootstrap-rootfs-overlay-demo-server.sh +++ b/scripts/bootstrap-rootfs-overlay-demo-server.sh @@ -16,12 +16,6 @@ # Exit if any command exits with a non-zero exit status. set -o errexit -root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd) -if [ "${root_dir}" != "${PWD}" ]; then - echo "You must execute $(basename $0) from the root directory: ${root_dir}" - exit 1 -fi - server_ip="" output_dir="" while (("$#")); do @@ -57,8 +51,7 @@ if [ -e ${output_dir} ]; then fi mkdir -p ${output_dir}/etc/mender -mkdir -p ${root_dir}/input/resources -cat <<- EOF > ${root_dir}/input/resources/mender.conf +cat <<- EOF > ${output_dir}/etc/mender/mender.conf { "ServerURL": "https://docker.mender.io", "ServerCertificate": "/etc/mender/server.crt" @@ -80,4 +73,4 @@ wget -q "https://raw.githubusercontent.com/mendersoftware/mender/master/support/ sudo chown -R 0 ${output_dir} sudo chgrp -R 0 ${output_dir} -echo "Configuration file for using Demo Mender Server written to: ${root_dir}/input/resources/mender.conf" +echo "Configuration file for using Demo Mender Server written to: ${output_dir}/etc/mender/mender.conf" diff --git a/scripts/bootstrap-rootfs-overlay-hosted-server.sh b/scripts/bootstrap-rootfs-overlay-hosted-server.sh index b110c8b..7ec44d2 100755 --- a/scripts/bootstrap-rootfs-overlay-hosted-server.sh +++ b/scripts/bootstrap-rootfs-overlay-hosted-server.sh @@ -16,12 +16,6 @@ # Exit if any command exits with a non-zero exit status. set -o errexit -root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd) -if [ "${root_dir}" != "${PWD}" ]; then - echo "You must execute $(basename $0) from the root directory: ${root_dir}" - exit 1 -fi - tenant_token="" output_dir="" while (("$#")); do @@ -56,8 +50,8 @@ if [ -e ${output_dir} ]; then sudo chown -R $(id -u) ${output_dir} sudo chgrp -R $(id -g) ${output_dir} fi -mkdir -p ${root_dir}/input/resources -cat <<- EOF > ${root_dir}/input/resources/mender.conf +mkdir -p ${output_dir}/etc/mender +cat <<- EOF > ${output_dir}/etc/mender/mender.conf { "ServerURL": "https://hosted.mender.io/", "TenantToken": "${tenant_token}" @@ -67,4 +61,4 @@ EOF sudo chown -R 0 ${output_dir} sudo chgrp -R 0 ${output_dir} -echo "Configuration file for using Hosted Mender written to: ${root_dir}/input/resources/mender.conf" +echo "Configuration file for using Hosted Mender written to: ${output_dir}/etc/mender/mender.conf" diff --git a/scripts/bootstrap-rootfs-overlay-production-server.sh b/scripts/bootstrap-rootfs-overlay-production-server.sh index 77b1b13..807e4d1 100755 --- a/scripts/bootstrap-rootfs-overlay-production-server.sh +++ b/scripts/bootstrap-rootfs-overlay-production-server.sh @@ -16,12 +16,6 @@ # Exit if any command exits with a non-zero exit status. set -o errexit -root_dir=$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd) -if [ "${root_dir}" != "${PWD}" ]; then - echo "You must execute $(basename $0) from the root directory: ${root_dir}" - exit 1 -fi - server_url="" output_dir="" while (("$#")); do @@ -61,24 +55,24 @@ if [ -e ${output_dir} ]; then sudo chgrp -R $(id -g) ${output_dir} fi -mkdir -p ${root_dir}/input/resources -cat <<- EOF > ${root_dir}/input/resources/mender.conf +mkdir -p ${output_dir}/etc/mender +cat <<- EOF > ${output_dir}/etc/mender/mender.conf { "ServerURL": "${server_url}", EOF if [ -n "${server_cert}" ]; then - cat <<- EOF >> ${root_dir}/input/resources/mender.conf + cat <<- EOF >> ${output_dir}/etc/mender/mender.conf "ServerCertificate": "/etc/mender/server.crt" EOF cp -f "${server_cert}" ${output_dir}/etc/mender/server.crt fi -cat <<- EOF >> ${root_dir}/input/resources/mender.conf +cat <<- EOF >> ${output_dir}/etc/mender/mender.conf } EOF sudo chown -R 0 ${output_dir} sudo chgrp -R 0 ${output_dir} -echo "Configuration file for using Production Mender Server written to: ${root_dir}/input/resources/mender.conf" +echo "Configuration file for using Production Mender Server written to: ${output_dir}/etc/mender/mender.conf"