Skip to content

Commit 0dd45b6

Browse files
committed
hacks: reorganize a index with preinst and postinst
1 parent 00364cf commit 0dd45b6

6 files changed

Lines changed: 47 additions & 20 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ Supported hacks:
2323
- `_hacks/pkg_configs`: Define a list of configs to be modified in PKG_CONFIGS.
2424
- `_hacks/pkg_conflicts`: Define a list of packages to be removed in PKG_CONFLICTS.
2525

26-
To use the defined PKG_CONFIGS or PKG_CONFLICTS include the preinst defined in `_hacks/preinst.mk` that will trigger a new build with the defined modifications, like in the example below:
27-
26+
Warn: Usable safely with imagebuilder-docker.
2827
Warn: To use it with asu, the server must support this hack.
2928
Currently the asu server https://sysupgrade.antennine.org supports it:
3029
- do not returning errors if the main build was killed after the second build completes
3130
- prepending packages that starts with 'profile-' at the beginning of the packages list (to use it with the firmware-selector)
3231
- checking the manifest from a file printed in BIN_DIR/manifest instead from STDOUT
32+
33+
To use the defined PKG_CONFIGS or PKG_CONFLICTS include the preinst defined in `_hacks/index.mk` that will trigger a new build with the defined modifications, like in the example below:
3334
```
3435
include $(TOPDIR)/rules.mk
3536
@@ -42,9 +43,9 @@ PKG_CONFLICTS:=\
4243
PROFILE_DEPENDS:=\
4344
+profile-libremesh-suggested-packages
4445
45-
include ../../_hacks/preinst.mk
46+
include ../../_hacks/index.mk
4647
include ../../profile.mk
4748
4849
# call BuildPackage - OpenWrt buildroot signature
4950
50-
```
51+
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ done
2929

3030
echo "########################################################################## pkg_conflicts: Add PKG_CONFLICTS to be removed in the main Makefile"
3131
sed -i 's|\($$(USER_PACKAGES)\) \($$(BUILD_PACKAGES)\)|\1 $(PKG_CONFLICTS) \2|' $${TOPDIR}/Makefile
32-
echo "########################################################################## Prevent unnecessary opkg/apk update in the main Makefile"
32+
echo "########################################################################## pkg_conflicts: Prevent unnecessary opkg/apk update in the main Makefile"
3333
sed -i '/update/d' $${TOPDIR}/Makefile
3434
if [ "$${make_target}" = "manifest" ]; then
3535
echo "########################################################################## pkg_conflicts: make manifest: use the BIN_DIR of asu if available"

_hacks/index.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include $(TOPDIR)/rules.mk
2+
3+
PROFILE_NAME=$(notdir ${CURDIR})
4+
PROFILE_COMMUNITY=$(lastword $(filter-out $(PROFILE_NAME),$(subst /, ,$(CURDIR))))
5+
PKG_NAME:=profile-$(PROFILE_COMMUNITY)-$(PROFILE_NAME)
6+
7+
include ../../_hacks/preinst.mk
8+
include ../../_hacks/postinst.mk

_hacks/postinst.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
define Package/$(PKG_NAME)/postinst
2+
#!/bin/bash
3+
# Run only in imagebuilder/sdk, exit if executed on the target device or buildroot
4+
[ -z "$${IPKG_INSTROOT}" ] && exit 0
5+
[ -f "$${TOPDIR}/version" ] && exit 0
6+
grep -q IB_MODIFIED_BY_$(PKG_NAME)_preinst $${TOPDIR}/Makefile || exit 0
7+
echo "########################################################################## Inside package $(PKG_NAME) postinst"
8+
9+
endef

_hacks/preinst.mk

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,64 @@
1-
include $(TOPDIR)/rules.mk
2-
3-
PROFILE_NAME=$(notdir ${CURDIR})
4-
PROFILE_COMMUNITY=$(lastword $(filter-out $(PROFILE_NAME),$(subst /, ,$(CURDIR))))
5-
PKG_NAME:=profile-$(PROFILE_COMMUNITY)-$(PROFILE_NAME)
6-
71
define Package/$(PKG_NAME)/preinst
82
#!/bin/bash
3+
# Run only in imagebuilder/sdk, exit if executed on the target device or buildroot
94
[ -z "$${IPKG_INSTROOT}" ] && exit 0
105
[ -f "$${TOPDIR}/version" ] && exit 0
11-
grep -q IB_MODIFIED_BY_$(PKG_NAME) $${TOPDIR}/Makefile && exit 0
6+
grep -q IB_MODIFIED_BY_$(PKG_NAME)_preinst $${TOPDIR}/Makefile && exit 0
127
echo "########################################################################## Inside package $(PKG_NAME) preinst"
138
echo "########################################################################## Backup original files"
149
cp $${TOPDIR}/Makefile $${TOPDIR}/Makefile.orig
1510
cp $${TOPDIR}/.config $${TOPDIR}/.config.orig
11+
cp $${TOPDIR}/include/rootfs.mk $${TOPDIR}/include/rootfs.mk.orig
12+
13+
echo "########################################################################## Ensure postinst-pkg are executed"
14+
sed -i 's|\(IPKG_POSTINST_PATH=\).*|\1./usr/lib/opkg/info/\*\.postinst\*; \\|' $${TOPDIR}/include/rootfs.mk
15+
1616
echo "########################################################################## Determine make's target"
1717
cmdline_args=$$(cat /proc/*/cmdline | tr -d '\0' | head -n 1)
1818
make_target=$$(echo "$${cmdline_args}" | grep -q makemanifest && echo 'manifest' || echo 'image')
1919
echo "make_target: $${make_target}"
2020

21+
echo "########################################################################## Check if a re-run is needed"
22+
need_rerun=0
23+
2124
if [ -n "$(PKG_CONFIGS)" ]; then
2225
$(Package/$(PKG_NAME)/preinst_pkg_configs)
26+
echo "########################################################################## pkg_configs: end"
2327
fi
28+
2429
if [ -n "$(PKG_CONFLICTS)" ]; then
2530
$(Package/$(PKG_NAME)/preinst_pkg_conflicts)
31+
echo "########################################################################## pkg_conflicts: end"
2632
fi
2733

34+
2835
echo "########################################################################## Add a target that restore original files and kill parent process"
2936
cat << EOF >> $${TOPDIR}/Makefile
3037
fail_target:
3138
mv $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile
3239
mv $${TOPDIR}/.config.orig $${TOPDIR}/.config
40+
mv $${TOPDIR}/include/rootfs.mk.orig $${TOPDIR}/include/rootfs.mk
3341
kill $$(ls -l /proc/*/exe | grep make | sed 's|.*/proc/\(.*\)/exe.*|\1|' | tr '\n' ' ' )
34-
# IB_MODIFIED_BY_$(PKG_NAME)
42+
# IB_MODIFIED_BY_$(PKG_NAME)_preinst
3543
EOF
3644

3745
if [ $${need_rerun} = 1 ]; then
38-
echo "########################################################################## Re-run make ${make_target} with the untouched MAKEFLAGS"
39-
make $${make_target}
46+
echo "########################################################################## Re-run make $${make_target} with the untouched MAKEFLAGS"
47+
make $${make_target}
4048
make fail_target
4149
else
4250
echo "########################################################################## Restore original files and continue build without hack"
43-
mv $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile
44-
mv $${TOPDIR}/.config.orig $${TOPDIR}/.config
45-
exit 0
51+
mv $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile 2>/dev/null
52+
mv $${TOPDIR}/.config.orig $${TOPDIR}/.config 2>/dev/null
53+
mv $${TOPDIR}/include/rootfs.mk.orig $${TOPDIR}/include/rootfs.mk 2>/dev/null
4654
fi
55+
4756
endef
4857

4958
ifneq ($(PKG_CONFIGS),)
50-
include ../../_hacks/_pkg_configs.mk
59+
include ../../_hacks/_preinst_pkg_configs.mk
5160
endif
5261

5362
ifneq ($(PKG_CONFLICTS),)
54-
include ../../_hacks/_pkg_conflicts.mk
63+
include ../../_hacks/_preinst_pkg_conflicts.mk
5564
endif

0 commit comments

Comments
 (0)