apk-tools: implement compression of on-device scripts.tar

Default behavior for apk was to create an uncompressed scripts.tar
file.  Due to the structure of tar files, with fixed block
size and null padding, this file becomes very large on OpenWrt
installations where there are typically two scripts per package.
This could cause the raw tar file to easily grow to over 500KB,
whereas the compressed file is generally around 20-30KB.

When stored in the /rom partition of a squashfs device, the file
is compressed and this is not an issue.  But, as soon as you add
or delete a package, the scripts.tar file is fully expanded into
the /overlay partition and can cause issues on small-flash devices.

This issue was addressed in an upstream commit by detecting
whether the scripts.tar file is compressed (its name must be
exactly 'scripts.tar.gz'), and then retaining that compression by
reading/writing the file using a compressed stream.

This commit applies a cherrypicked patch for the upstream commit, and
compresses the scripts.tar during construction of the device rootfs.

Fixes: https://github.com/openwrt/openwrt/issues/17108
Link: 012cdcfdf9
Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/20795
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
Eric Fahlgren
2025-11-15 08:32:00 -08:00
committed by Robert Marko
parent dc420acc77
commit 5d85657f6d
3 changed files with 58 additions and 3 deletions

View File

@@ -78,7 +78,7 @@ define prepare_rootfs
cd $(1); \
if [ -n "$(CONFIG_USE_APK)" ]; then \
IPKG_POSTINST_PATH=./lib/apk/db/*.post-install; \
$(STAGING_DIR_HOST)/bin/tar -C ./lib/apk/db/ -xf ./lib/apk/db/scripts.tar --wildcards "*.post-install"; \
$(STAGING_DIR_HOST)/bin/tar -C ./lib/apk/db/ -xzf ./lib/apk/db/scripts.tar.gz --wildcards "*.post-install"; \
else \
IPKG_POSTINST_PATH=./usr/lib/opkg/info/*.postinst; \
fi; \
@@ -89,7 +89,7 @@ define prepare_rootfs
echo "postinst script $$script has failed with exit code $$ret" >&2; \
exit 1; \
fi; \
[ -n "$(CONFIG_USE_APK)" ] && $(STAGING_DIR_HOST)/bin/tar --delete -f ./lib/apk/db/scripts.tar $$(basename $$script); \
[ -n "$(CONFIG_USE_APK)" ] && $(STAGING_DIR_HOST)/bin/tar --delete -zf ./lib/apk/db/scripts.tar.gz $$(basename $$script); \
done; \
if [ -z "$(CONFIG_USE_APK)" ]; then \
$(if $(IB),,awk -i inplace \