From: Michael Tremer Date: Wed, 10 Jul 2024 16:54:33 +0000 (+0000) Subject: core-updates: Refactor how we package the archive X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a185cb7e8d1723844ec724dccfb3f163666feca;p=people%2Fms%2Fipfire-2.x.git core-updates: Refactor how we package the archive Signed-off-by: Michael Tremer --- diff --git a/lfs/Config b/lfs/Config index 92622e98e..eead89b5c 100644 --- a/lfs/Config +++ b/lfs/Config @@ -338,6 +338,12 @@ define B2SUM [ "$($@_BLAKE2)" = "$$(b2sum $(DIR_DL)/$@ | awk '{ print $$1 }')" ] && echo "$@ checksum OK" endef +# The filename of the package file +PACKAGE_FILENAME = $(PROG)-$(VER)-$(RELEASE).ipfire + +# The filename of the meta file +META_FILENAME = meta-$(PROG) + # Takes one rootfile or a directory and will return a list of all included files COLLECT_FILES = \ BUILD_ARCH="$(BUILD_ARCH)" \ @@ -364,10 +370,15 @@ __FILES_OUT = \ $(TAR_OPTIONS) \ --directory="$(1)" +__WRITE_ROOTFILE = tee $(1) + # Copies all files on a rootfile into the given directory define COPY_FILES # Copy all files from $(1) to $(2) - $(call COLLECT_FILES,$(1)) | $(call __FILES_IN) | $(call __FILES_OUT,$(2)) + $(call COLLECT_FILES,$(1)) | \ + $(if $(3),$(call __WRITE_ROOTFILE,$(3)) |) \ + $(call __FILES_IN) | \ + $(call __FILES_OUT,$(2)) # Strip everything, except a few things $(DIR_SRC)/src/stripper $(2) \ @@ -391,6 +402,39 @@ __COMPRESS = \ COMPRESS_XZ = $(call __COMPRESS,$(1),$(2),xz $(XZ_OPT)) COMPRESS_ZSTD = $(call __COMPRESS,$(1),$(2),zstd $(ZSTD_OPT)) +# Command to create a Pakfire package +define CREATE_PACKAGE + # Compress the package + tar \ + --create \ + --format=pax \ + --no-acls \ + --no-xattrs \ + --directory="$(1)" \ + --file="$(2)" \ + --transform="s@^\./@@" \ + . +endef + +# Returns the filesize in bytes +PACKAGE_SIZE = stat --format=%s $(1) + +# Creates the meta file for a Pakfire package +define CREATE_META + # Clear/create the file + : > $(2) + + # Write payload + echo "Name: $(PROG)" >> $(2) + echo "Summary: $(SUMMARY)" >> $(2) + echo "ProgVersion: $(VER)" >> $(2) + echo "Release: $(RELEASE)" >> $(2) + echo "Size: $(call PACKAGE_SIZE,$(1))" >> $(2) + echo "Dependencies: $(DEPS)" >> $(2) + echo "File: $(PROG)-$(VER)-$(RELEASE).ipfire" >> $(2) + echo "Services: $(SERVICES)" >> $(2) +endef + # Helper function to make sure that we have all sorts of mountpoints in the images CREATE_MOUNTPOINTS = mkdir -pv $(1)/dev $(1)/proc $(1)/sys diff --git a/lfs/core-updates b/lfs/core-updates index e726392fe..6b56f0cff 100644 --- a/lfs/core-updates +++ b/lfs/core-updates @@ -24,17 +24,22 @@ include Config -VER = ipfire - THISAPP = core-updates TARGET = $(DIR_INFO)/$(THISAPP) +PROG = core-upgrade +VER = $(VERSION) +RELEASE = $(CORE) + +SUMMARY = IPFire Core Update $(CORE) + +ARCHIVE_DIR = /tmp/archive +ARCHIVE_TMP = $(ARCHIVE_DIR)/.tmp + ############################################################################### # Top-level Rules ############################################################################### -install : $(TARGET) - check : download : @@ -45,56 +50,37 @@ b2 : # Installation Details ############################################################################### -CORE = $(patsubst $(DIR_SRC)/config/rootfiles/%,%,$(wildcard $(DIR_SRC)/config/rootfiles/core/*)) +.PHONY: +install: + @rm -rf $(ARCHIVE_DIR) && mkdir -pv $(ARCHIVE_DIR) $(ARCHIVE_TMP) -$(TARGET) : $(CORE) + # Generate the archive and write out the rootfile + $(call COPY_FILES, \ + $(DIR_SRC)/config/rootfiles/core/$(CORE)/filelists,$(ARCHIVE_TMP), \ + $(ARCHIVE_DIR)/ROOTFILES \ + ) -.PHONY: -core/%: - rm -rf /install/packages/package /tmp/* - mkdir -p /install/packages/package - - #Generate ROOTFILES from filelists - BUILD_ARCH=$(BUILD_ARCH) BUILDTARGET=$(BUILDTARGET) KVER=$(KVER) \ - $(DIR_SRC)/src/scripts/archive.files \ - $(DIR_SRC)/config/rootfiles/$@/filelists \ - $(DIR_SRC)/config/rootfiles/$@/files \ - $(DIR_SRC)/config/rootfiles/$@/files.$(BUILD_ARCH) \ - > /tmp/ROOTFILES.tmp - - #remove excluded files from ROOTFILES - grep -f $(DIR_SRC)/config/rootfiles/$@/exclude -v /tmp/ROOTFILES.tmp > /tmp/ROOTFILES - rm -rf /tmp/ROOTFILES.tmp - - #Change KVER to Kernelversion - sed -e "s/KVER/$(KVER)/g" -i /tmp/ROOTFILES - - #Remove doubled files with tar/untar/tar to save space - tar $(TAR_OPTIONS) -c --exclude='proc/*' --exclude='tmp/ROOTFILES' --exclude='__pycache__' --exclude='#*' --exclude='dev/pts/*' \ - --exclude-from=$(DIR_SRC)/config/rootfiles/$@/exclude \ - -C / --files-from=/tmp/ROOTFILES -f /$(SNAME).tar - mv -f /tmp/ROOTFILES /install/packages/package/ROOTFILES - tar $(TAR_OPTIONS) -p --numeric-owner -x -C /tmp -f /$(SNAME).tar - rm -f /$(SNAME).tar - cd /tmp && XZ_OPT="$(XZ_OPT)" tar $(TAR_OPTIONS) -cJf /install/packages/package/files.tar.xz $(TAR_OPTIONS) * && rm -rf * - cat /install/packages/package/ROOTFILES | grep -v "#" > /install/packages/package/ROOTFILES.tmp - rm /install/packages/package/ROOTFILES - mv /install/packages/package/ROOTFILES.tmp /install/packages/package/ROOTFILES - - #build package - cp -f $(DIR_SRC)/config/rootfiles/$@/update.sh /install/packages/package - chmod 755 /install/packages/package/update.sh - #Change xxxKVERxxx to Kernelversion - sed -e "s/xxxKVERxxx/$(KVER)/g" -i /install/packages/package/update.sh - - cd /install/packages/package && tar cf ../core-upgrade-$(VERSION)-$$(basename $@).ipfire \ - update.sh files.tar.xz ROOTFILES - rm -rf /install/packages/package - sed -e "s/NAME/core-upgrade/g" \ - -e "s/SUMMARY/IPFire Core Update/g" \ - -e "s/VER/$(VERSION)/g" \ - -e "s/RELEASE/$$(basename $@)/g" \ - -e "s/DEPS/$(DEPS)/g" \ - -e "s/SIZE/`ls -l \/install\/packages\/core-upgrade-$(VERSION)-$$(basename $@).ipfire | awk '{ print $$5 }'`/g" \ - -e "s/SERVICES//g" \ - < /usr/src/src/pakfire/meta > /install/packages/meta-core-upgrade-$$(basename $@) + # Create the archive + $(call COMPRESS_XZ,$(ARCHIVE_TMP),$(ARCHIVE_DIR)/files.tar.xz) + + # Remove the temporary files + rm -rf $(ARCHIVE_TMP) + + # Install update scripts + cd $(DIR_SRC) && install -v -m 744 config/rootfiles/core/$(CORE)/update.sh \ + $(ARCHIVE_DIR)/update.sh + + # Replace the kernel version + sed -e "s/xxxKVERxxx/$(KVER)/g" -i $(ARCHIVE_DIR)/update.sh + + # Create the package + $(call CREATE_PACKAGE,$(ARCHIVE_DIR),$(PACKAGES_DIR)/$(PACKAGE_FILENAME)) + + # Write the meta file + $(call CREATE_META, \ + $(PACKAGES_DIR)/$(PACKAGE_FILENAME), \ + $(PACKAGES_DIR)/$(META_FILENAME) \ + ) + + # Cleanup + @rm -rf $(ARCHIVE_DIR)