[2/2] deb to snap: recurse down to find the real kernel image package, and chek its version

Message ID 1509472953-32368-3-git-send-email-paolo.pisati@canonical.com
State New
Headers show
Series
  • deb to snap: use the kernel version from the
Related show

Commit Message

Paolo Pisati Oct. 31, 2017, 6:02 p.m.
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
---
 Makefile | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Comments

Andy Whitcroft Nov. 14, 2017, 12:38 p.m. | #1
On Tue, Oct 31, 2017 at 07:02:33PM +0100, Paolo Pisati wrote:
> Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
> ---
>  Makefile | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index dad3156..2bb8a89 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -11,6 +11,7 @@ endif
>  # rewriting variables passed from the outside environment doesn't work in LP,
>  # so use KERNELDEB as a temporary local variable to hold the kernel pkg name
>  KERNELDEB := $(KERNEL)
> +KERNELPRE := linux-image-4

This 4 here likely should be something taken from the version we are
looking for?  Perhaps the whole ABI?

>  # linux-pc-image is a meta package used to indicate either
>  # linux-signed-image-generic or linux-image-generic, depending on the building
> @@ -18,6 +19,7 @@ KERNELDEB := $(KERNEL)
>  ifneq (,$(findstring linux-pc-image,$(KERNELDEB)))
>  ifneq (,$(findstring amd64,$(DPKG_ARCH)))
>  KERNELDEB := $(subst linux-pc-image,linux-signed-image-generic,$(KERNELDEB))
> +KERNELPRE := linux-signed-image-4

and here.

>  else ifneq (,$(findstring i386,$(DPKG_ARCH)))
>  KERNELDEB := $(subst linux-pc-image,linux-image-generic,$(KERNELDEB))
>  else
> @@ -44,6 +46,7 @@ Pin-Priority: 700
>  endef
>  export APTPREF
>  
> +versioncheck: KIMGDEB = $(shell chroot chroot apt-cache depends $(KERNELDEB) | awk '/$(KERNELPRE)/ {print $$2}')
>  install : KVERS = $(shell ls -1 chroot/boot/vmlinuz-*| tail -1 |sed 's/^.*vmlinuz-//;s/.efi.signed$$//')
>  
>  all:
> @@ -68,7 +71,7 @@ all:
>  	umount chroot/sys
>  	umount chroot/proc
>  
> -install:
> +install: versioncheck
>  	mkdir -p $(DESTDIR)/lib $(DESTDIR)/meta $(DESTDIR)/firmware $(DESTDIR)/modules
>  	if [ -f chroot/boot/vmlinu?-*.signed ]; then \
>  	  mv chroot/boot/vmlinu?-*.signed $(DESTDIR)/kernel.img; \
> @@ -115,3 +118,16 @@ install:
>  	cd $(DESTDIR); ln -s kernel.img vmlinuz-$(KVERS)
>  	cd $(DESTDIR); ln -s kernel.img vmlinuz
>  	cd $(DESTDIR); ln -s initrd.img initrd.img-$(KVERS)
> +
> +versioncheck:
> +	{ \
> +	set -e; \
> +	echo $(KIMGDEB); \
> +	KIMGVER="$$(dpkg --root=chroot -l | awk '/$(KIMGDEB)/ {print $$3}')"; \
> +	echo $$KIMGVER; \
> +	[ ! $$KIMGVER ] && echo "Unable to extract KIMGVER, exit" && exit 1; \
> +	if [ $$KIMGVER != $(SNAPCRAFT_PROJECT_VERSION) ]; then \
> +	  echo "Version mismatch:\nInstalled: $$KIMGVER Requested: $(SNAPCRAFT_PROJECT_VERSION)"; \
> +	  exit 1; \
> +	fi; \
> +	}

Otherwise it looks fine.

-apw

Patch

diff --git a/Makefile b/Makefile
index dad3156..2bb8a89 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@  endif
 # rewriting variables passed from the outside environment doesn't work in LP,
 # so use KERNELDEB as a temporary local variable to hold the kernel pkg name
 KERNELDEB := $(KERNEL)
+KERNELPRE := linux-image-4
 
 # linux-pc-image is a meta package used to indicate either
 # linux-signed-image-generic or linux-image-generic, depending on the building
@@ -18,6 +19,7 @@  KERNELDEB := $(KERNEL)
 ifneq (,$(findstring linux-pc-image,$(KERNELDEB)))
 ifneq (,$(findstring amd64,$(DPKG_ARCH)))
 KERNELDEB := $(subst linux-pc-image,linux-signed-image-generic,$(KERNELDEB))
+KERNELPRE := linux-signed-image-4
 else ifneq (,$(findstring i386,$(DPKG_ARCH)))
 KERNELDEB := $(subst linux-pc-image,linux-image-generic,$(KERNELDEB))
 else
@@ -44,6 +46,7 @@  Pin-Priority: 700
 endef
 export APTPREF
 
+versioncheck: KIMGDEB = $(shell chroot chroot apt-cache depends $(KERNELDEB) | awk '/$(KERNELPRE)/ {print $$2}')
 install : KVERS = $(shell ls -1 chroot/boot/vmlinuz-*| tail -1 |sed 's/^.*vmlinuz-//;s/.efi.signed$$//')
 
 all:
@@ -68,7 +71,7 @@  all:
 	umount chroot/sys
 	umount chroot/proc
 
-install:
+install: versioncheck
 	mkdir -p $(DESTDIR)/lib $(DESTDIR)/meta $(DESTDIR)/firmware $(DESTDIR)/modules
 	if [ -f chroot/boot/vmlinu?-*.signed ]; then \
 	  mv chroot/boot/vmlinu?-*.signed $(DESTDIR)/kernel.img; \
@@ -115,3 +118,16 @@  install:
 	cd $(DESTDIR); ln -s kernel.img vmlinuz-$(KVERS)
 	cd $(DESTDIR); ln -s kernel.img vmlinuz
 	cd $(DESTDIR); ln -s initrd.img initrd.img-$(KVERS)
+
+versioncheck:
+	{ \
+	set -e; \
+	echo $(KIMGDEB); \
+	KIMGVER="$$(dpkg --root=chroot -l | awk '/$(KIMGDEB)/ {print $$3}')"; \
+	echo $$KIMGVER; \
+	[ ! $$KIMGVER ] && echo "Unable to extract KIMGVER, exit" && exit 1; \
+	if [ $$KIMGVER != $(SNAPCRAFT_PROJECT_VERSION) ]; then \
+	  echo "Version mismatch:\nInstalled: $$KIMGVER Requested: $(SNAPCRAFT_PROJECT_VERSION)"; \
+	  exit 1; \
+	fi; \
+	}