diff mbox series

[2/2] package/mender: add support for update modules

Message ID 20200418212643.2743304-2-aduskett@gmail.com
State New
Headers show
Series [1/2] package/mender: set the default script version to 3 | expand

Commit Message

Adam Duskett April 18, 2020, 9:26 p.m. UTC
From: Adam Duskett <Aduskett@gmail.com>

Mender has support for performing other types of updates other than just
overwriting the rootfs partition that isn't currently in use on the target.

Some of the default provided modules provide support for:
  - Updating a docker container.
  - Running a script.
  - Installing an RPM.
  - Overwriting a directory.
  - Updating a single-file.

The single-file update module is used by upstream for onboarding a new device
to a server, and this fails with Buildroot devices because the modules are
currently not installed.

Install the directory, script, and single-file modules by default, and
install the docker or rpm script if their respective packages are selected.

Also provide a patch that removes bashisms from the docker and single-file
modules.

Signed-off-by: Adam Duskett <Aduskett@gmail.com>
---
 ...ashisms-in-the-update-module-scripts.patch | 71 +++++++++++++++++++
 package/mender/mender.mk                      |  7 ++
 2 files changed, 78 insertions(+)
 create mode 100644 package/mender/0001-remove-bashisms-in-the-update-module-scripts.patch
diff mbox series

Patch

diff --git a/package/mender/0001-remove-bashisms-in-the-update-module-scripts.patch b/package/mender/0001-remove-bashisms-in-the-update-module-scripts.patch
new file mode 100644
index 0000000000..b5194f7bf9
--- /dev/null
+++ b/package/mender/0001-remove-bashisms-in-the-update-module-scripts.patch
@@ -0,0 +1,71 @@ 
+From 7027a47b46b646090f1351ecb156992b60416690 Mon Sep 17 00:00:00 2001
+From: Adam Duskett <Aduskett@gmail.com>
+Date: Sat, 18 Apr 2020 13:56:31 -0700
+Subject: [PATCH] Remove bashisms in the update module scripts
+
+The only update module to actually have any bashisms was the docker module,
+and the bashisms were trivial to remove.
+
+Changes to docker:
+  - Change any [[ ]] call to [ ]
+  - Quote any shell calls in [ -n ]
+  - Change the shebang from #!/bin/bash to #!/bin/sh
+
+Changes to single-file:
+  - Change the shebang from #!/bin/bash to #!/bin/sh
+  - No other bashisms are currently present in the file.
+
+Upstream-status: Pending
+https://github.com/mendersoftware/mender/pull/524
+
+Signed-off-by: Adam Duskett <Aduskett@gmail.com>
+---
+ support/modules/docker      | 10 +++++-----
+ support/modules/single-file |  2 +-
+ 2 files changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/support/modules/docker b/support/modules/docker
+index 941be09..07ea174 100755
+--- a/support/modules/docker
++++ b/support/modules/docker
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ 
+ set -e
+ 
+@@ -19,7 +19,7 @@ case "$STATE" in
+ 
+     ArtifactInstall)
+         docker ps -q > $prev_containers_file
+-        [[ -n $(cat $prev_containers_file) ]] && docker stop $(cat $prev_containers_file)
++        [ -n "$(cat $prev_containers_file)" ] && docker stop $(cat $prev_containers_file)
+         for container in $(jq -r ".containers[]" "$FILES"/header/meta-data); do
+             docker pull $container
+             docker run -dt $container
+@@ -27,9 +27,9 @@ case "$STATE" in
+         ;;
+ 
+     ArtifactRollback)
+-        [[ -f $prev_containers_file ]] || exit 1
+-        [[ -n  "$(docker ps -q)" ]] && docker stop $(docker ps -q)
+-        [[ -n $(cat $prev_containers_file) ]] && docker start $(cat $prev_containers_file)
++        [ -f $prev_containers_file ] || exit 1
++        [ -n  "$(docker ps -q)" ] && docker stop $(docker ps -q)
++        [ -n "$(cat $prev_containers_file)" ] && docker start $(cat $prev_containers_file)
+         ;;
+ esac
+ 
+diff --git a/support/modules/single-file b/support/modules/single-file
+index d1d9f40..ed1868b 100755
+--- a/support/modules/single-file
++++ b/support/modules/single-file
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ 
+ set -e
+ 
+-- 
+2.25.2
+
diff --git a/package/mender/mender.mk b/package/mender/mender.mk
index e1ca976797..be169ad213 100644
--- a/package/mender/mender.mk
+++ b/package/mender/mender.mk
@@ -39,6 +39,9 @@  MENDER_DEPENDENCIES = xz
 
 MENDER_LDFLAGS = -X main.Version=$(MENDER_VERSION)
 
+MENDER_UPDATE_MODULES_FILES = directory script single-file
+MENDER_UPDATE_MODULES_FILES += $(if $(BR2_PACKAGE_DOCKER_CLI),docker)
+MENDER_UPDATE_MODULES_FILES +=  $(if $(BR2_PACKAGE_RPM),rpm)
 define MENDER_INSTALL_CONFIG_FILES
 	$(INSTALL) -d -m 755 $(TARGET_DIR)/etc/mender/scripts
 	echo -n "3" > $(TARGET_DIR)/etc/mender/scripts/version
@@ -63,6 +66,10 @@  define MENDER_INSTALL_CONFIG_FILES
 
 	mkdir -p $(TARGET_DIR)/var/lib
 	ln -snf /var/run/mender $(TARGET_DIR)/var/lib/mender
+	$(foreach f,$(MENDER_UPDATE_MODULES_FILES), \
+		$(INSTALL) -D -m 0755 $(@D)/support/modules/$(notdir $(f)) \
+			$(TARGET_DIR)/usr/share/mender/modules/v3/$(notdir $(f))
+	)
 endef
 
 MENDER_POST_INSTALL_TARGET_HOOKS += MENDER_INSTALL_CONFIG_FILES