build: fix possible issue with kmod package having multiple AutoLoad's

This commit contains the following changes

 - Use local shell var where appliable
 - The $(sort $$$$$$$$mods) call will have no expected effect
 - Avoid EEXIST when creating symlinks in /etc/modules-boot.d/
 - Avoid duplicate arguments for insert_modules() in postinst-pkg

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
This commit is contained in:
Yousong Zhou 2017-05-27 10:22:02 +08:00
parent 7142cb45b4
commit 546e20e836

View File

@ -97,15 +97,16 @@ define ModuleAutoLoad
$(SH_FUNC) \ $(SH_FUNC) \
export modules=; \ export modules=; \
probe_module() { \ probe_module() { \
mods="$$$$$$$$1"; \ local mods="$$$$$$$$1"; \
boot="$$$$$$$$2"; \ local boot="$$$$$$$$2"; \
local mod; \
shift 2; \ shift 2; \
for mod in $(sort $$$$$$$$mods); do \ for mod in $$$$$$$$mods; do \
mkdir -p $(2)/etc/modules.d; \ mkdir -p $(2)/etc/modules.d; \
echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$(1); \ echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$(1); \
done; \ done; \
if [ -e $(2)/etc/modules.d/$(1) ]; then \ if [ -e $(2)/etc/modules.d/$(1) ]; then \
if [ "$$$$$$$$boot" = "1" ]; then \ if [ "$$$$$$$$boot" = "1" -a ! -e $(2)/etc/modules-boot.d/$(1) ]; then \
mkdir -p $(2)/etc/modules-boot.d; \ mkdir -p $(2)/etc/modules-boot.d; \
ln -s ../modules.d/$(1) $(2)/etc/modules-boot.d/; \ ln -s ../modules.d/$(1) $(2)/etc/modules-boot.d/; \
fi; \ fi; \
@ -113,16 +114,17 @@ define ModuleAutoLoad
fi; \ fi; \
}; \ }; \
add_module() { \ add_module() { \
priority="$$$$$$$$1"; \ local priority="$$$$$$$$1"; \
mods="$$$$$$$$2"; \ local mods="$$$$$$$$2"; \
boot="$$$$$$$$3"; \ local boot="$$$$$$$$3"; \
local mod; \
shift 3; \ shift 3; \
for mod in $(sort $$$$$$$$mods); do \ for mod in $$$$$$$$mods; do \
mkdir -p $(2)/etc/modules.d; \ mkdir -p $(2)/etc/modules.d; \
echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$$$$$$$$priority-$(1); \ echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$$$$$$$$priority-$(1); \
done; \ done; \
if [ -e $(2)/etc/modules.d/$$$$$$$$priority-$(1) ]; then \ if [ -e $(2)/etc/modules.d/$$$$$$$$priority-$(1) ]; then \
if [ "$$$$$$$$boot" = "1" ]; then \ if [ "$$$$$$$$boot" = "1" -a ! -e $(2)/etc/modules-boot.d/$$$$$$$$priority-$(1) ]; then \
mkdir -p $(2)/etc/modules-boot.d; \ mkdir -p $(2)/etc/modules-boot.d; \
ln -s ../modules.d/$$$$$$$$priority-$(1) $(2)/etc/modules-boot.d/; \ ln -s ../modules.d/$$$$$$$$priority-$(1) $(2)/etc/modules-boot.d/; \
fi; \ fi; \
@ -131,6 +133,7 @@ define ModuleAutoLoad
}; \ }; \
$(3) \ $(3) \
if [ -n "$$$$$$$$modules" ]; then \ if [ -n "$$$$$$$$modules" ]; then \
modules="$$$$$$$$(echo "$$$$$$$$modules" | tr ' ' '\n' | sort | uniq | paste -s -d' ')"; \
mkdir -p $(2)/etc/modules.d; \ mkdir -p $(2)/etc/modules.d; \
mkdir -p $(2)/CONTROL; \ mkdir -p $(2)/CONTROL; \
echo "#!/bin/sh" > $(2)/CONTROL/postinst-pkg; \ echo "#!/bin/sh" > $(2)/CONTROL/postinst-pkg; \