|
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 | 1 | define Package/$(PKG_NAME)/preinst |
8 | 2 | #!/bin/bash |
| 3 | +# Run only in imagebuilder/sdk, exit if executed on the target device or buildroot |
9 | 4 | [ -z "$${IPKG_INSTROOT}" ] && exit 0 |
10 | 5 | [ -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 |
12 | 7 | echo "########################################################################## Inside package $(PKG_NAME) preinst" |
13 | 8 | echo "########################################################################## Backup original files" |
14 | 9 | cp $${TOPDIR}/Makefile $${TOPDIR}/Makefile.orig |
15 | 10 | 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 | + |
16 | 16 | echo "########################################################################## Determine make's target" |
17 | 17 | cmdline_args=$$(cat /proc/*/cmdline | tr -d '\0' | head -n 1) |
18 | 18 | make_target=$$(echo "$${cmdline_args}" | grep -q makemanifest && echo 'manifest' || echo 'image') |
19 | 19 | echo "make_target: $${make_target}" |
20 | 20 |
|
| 21 | +echo "########################################################################## Check if a re-run is needed" |
| 22 | +need_rerun=0 |
| 23 | + |
21 | 24 | if [ -n "$(PKG_CONFIGS)" ]; then |
22 | 25 | $(Package/$(PKG_NAME)/preinst_pkg_configs) |
| 26 | +echo "########################################################################## pkg_configs: end" |
23 | 27 | fi |
| 28 | + |
24 | 29 | if [ -n "$(PKG_CONFLICTS)" ]; then |
25 | 30 | $(Package/$(PKG_NAME)/preinst_pkg_conflicts) |
| 31 | +echo "########################################################################## pkg_conflicts: end" |
26 | 32 | fi |
27 | 33 |
|
| 34 | + |
28 | 35 | echo "########################################################################## Add a target that restore original files and kill parent process" |
29 | 36 | cat << EOF >> $${TOPDIR}/Makefile |
30 | 37 | fail_target: |
31 | 38 | mv $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile |
32 | 39 | mv $${TOPDIR}/.config.orig $${TOPDIR}/.config |
| 40 | + mv $${TOPDIR}/include/rootfs.mk.orig $${TOPDIR}/include/rootfs.mk |
33 | 41 | 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 |
35 | 43 | EOF |
36 | 44 |
|
37 | 45 | 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} |
40 | 48 | make fail_target |
41 | 49 | else |
42 | 50 | 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 |
46 | 54 | fi |
| 55 | + |
47 | 56 | endef |
48 | 57 |
|
49 | 58 | ifneq ($(PKG_CONFIGS),) |
50 | | -include ../../_hacks/_pkg_configs.mk |
| 59 | +include ../../_hacks/_preinst_pkg_configs.mk |
51 | 60 | endif |
52 | 61 |
|
53 | 62 | ifneq ($(PKG_CONFLICTS),) |
54 | | -include ../../_hacks/_pkg_conflicts.mk |
| 63 | +include ../../_hacks/_preinst_pkg_conflicts.mk |
55 | 64 | endif |
0 commit comments