This patch enables the feature to call install_xpkg in the targetinstall stage
of any rule. This way it is possible to install external ipkgs into the targets
rootfilesystem.

The next example describes an simple usecase with two packages in local_src.

PACKAGES-$(EXAMPLERULE_IPKGS) += examplerule-ipkgs
EXAMPLERULE_IPKGS_VERSION       := 1.0
EXAMPLERULE_IPKGS       := examplerule-ipkgs-$(EXAMPLERULE_IPKGS_VERSION)
EXAMPLERULE_IPKGS_URL   := 
file://$(PTXDIST_WORKSPACE)/local_src/$(EXAMPLERULE_IPKGS)

EXAMPLERULE_IPKGS_FILES := \
        example1-package_1.1.3_armhf.ipk \
        example2-package_0.3.3_armhf.ipk

define rmsuffix
$(shell echo $(1) | sed 's-^\([0-9a-zA-Z\-].*\)_\([a-zA-Z.0-9].*\)_.*-\1-g')
endef

$(STATEDIR)/examplerule.targetinstall:
        @$(call targetinfo)
        @$(foreach ipkg, $(EXAMPLERULE_IPKGS_FILES), \
                $(call install_xpkg, $(call rmsuffix, $(ipkg)), \
                        $(EXAMPLERULE_IPKGS_URL)/$(ipkg));)
        @$(call touch)

Signed-off-by: Michael Grzeschik <m.grzesc...@pengutronix.de>
---
 rules/post/ptxd_make_xpkg_install.make |  33 ++++++++++
 scripts/lib/ptxd_make_xpkg_install.sh  | 111 +++++++++++++++++++++++++++++++++
 2 files changed, 144 insertions(+)
 create mode 100644 rules/post/ptxd_make_xpkg_install.make
 create mode 100644 scripts/lib/ptxd_make_xpkg_install.sh

diff --git a/rules/post/ptxd_make_xpkg_install.make 
b/rules/post/ptxd_make_xpkg_install.make
new file mode 100644
index 000000000..397961aab
--- /dev/null
+++ b/rules/post/ptxd_make_xpkg_install.make
@@ -0,0 +1,33 @@
+# -*-makefile-*-
+#
+# Copyright (C) 2018 by Michael Grzeschik <m...@pengutronix.de>
+#
+# See CREDITS for details about who has contributed to this project.
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+#
+# install_finish
+#
+# finishes packet creation
+#
+# $1: packet label
+#
+install_xpkg = \
+       $(call xpkg/install, $(1), $(2))
+
+#
+# xpkg/install
+#
+# installs packet
+#
+# $1: xpkg label
+#
+xpkg/install = \
+       $(call xpkg/env, $(1))  \
+       pkg_xpkg_source='$(strip $(2))' \
+       ptxd_make_xpkg_install
+
+# vim: syntax=make
diff --git a/scripts/lib/ptxd_make_xpkg_install.sh 
b/scripts/lib/ptxd_make_xpkg_install.sh
new file mode 100644
index 000000000..f0367c5e1
--- /dev/null
+++ b/scripts/lib/ptxd_make_xpkg_install.sh
@@ -0,0 +1,111 @@
+#
+# ptxd_make_image_extract_ipkg_package - extract ipkg for later image 
generation
+#
+# in:
+# - $1                         ipkg to be extracted
+# - $2                         directory where ipkg are extracted
+# - $PTXDIST_IPKG_ARCH_STRING  ARCH variable for ipkg files
+#
+ptxd_make_image_extract_xpkg_package() {
+    # FIXME: consolidate "ptxd_install_setup_src"
+    local src="/etc/opkg/opkg.conf"
+    local xpkg_conf="$(mktemp ${PTXDIST_TEMPDIR}/XXXXXXXXXX_xpkg.conf)"
+    local ipkg="$1"
+    local work_dir="$2"
+    local -a list ptxd_reply
+    echo "option force_reinstall 1" > "${xpkg_conf}"
+    echo "option nodeps 1" >> "${xpkg_conf}"
+    echo "option volatile_cache 1" >> "${xpkg_conf}"
+    echo "option force_postinstall 1" >> "${xpkg_conf}"
+    list=( \
+       "${PTXDIST_WORKSPACE}/projectroot${PTXDIST_PLATFORMSUFFIX}${src}" \
+       "${PTXDIST_WORKSPACE}/projectroot${src}${PTXDIST_PLATFORMSUFFIX}" \
+       "${PTXDIST_WORKSPACE}/projectroot${src}" \
+       "${PTXDIST_TOPDIR}/projectroot${src}" \
+       )
+
+    if ! ptxd_get_path "${list[@]}"; then
+       local IFS="
+"
+       ptxd_bailout "
+unable to find '${src}'
+
+These location have been searched:
+${list[*]}
+"
+    fi
+
+#    rm -rf "${work_dir}" &&
+#    install -m 755 -d "${work_dir}" &&
+
+    ARCH="${PTXDIST_IPKG_ARCH_STRING}" \
+    SRC="" \
+    CHECKSIG="" \
+    CAPATH="" \
+    CAFILE="" \
+       ptxd_replace_magic "${ptxd_reply}" >> "${xpkg_conf}" &&
+
+    DESTDIR="${work_dir}" \
+       opkg -f "${xpkg_conf}" -o "${work_dir}" \
+       install "${ipkg}" &&
+
+   ptxd_install_fixup_timestamps "${work_dir}"
+}
+export -f ptxd_make_image_extract_xpkg_package
+
+ptxd_make_xpkg_install_impl() {
+    source="$1"
+    pkg_xpkg_tmp=""
+
+    ptxd_install_setup &&
+    for dir in "${dirs[@]}"; do
+       if [ -n "${dir}" ]; then
+           echo installing to ${dir}; \
+           ptxd_make_image_extract_xpkg_package \
+               "${source}" "${dir}" || break
+       fi
+    done
+}
+export -f ptxd_make_xpkg_install_impl
+
+#
+# function to install a generic package
+#
+ptxd_make_xpkg_install() {
+    ptxd_make_xpkg_init || return
+    local source="${pkg_xpkg_source//file:\/\//}"
+
+    #
+    # track "pkg name" to "xpkg filename" mapping
+    #
+    if [ -e "${pkg_xpkg_map}" ]; then
+       sed -i -e "/^${pkg_xpkg}$/d" "${pkg_xpkg_map}"
+    fi &&
+    echo "${pkg_xpkg}" >> "${pkg_xpkg_map}" || return
+
+    #
+    # license / currently not per package
+    #
+    echo -n "xpkg_install:     collecting license (${pkg_xpkg_license}) ... "
+    echo "${pkg_xpkg_license}" > "${pkg_xpkg_license_file}"
+    echo "done."
+
+    #
+    # remove old pkgs
+    # note: no version here, so we remove packages with old versions too
+    #
+    rm -f "${ptx_pkg_dir}/${pkg_xpkg}"_*"${PTXDIST_IPKG_ARCH_STRING}.ipk"
+
+    #
+    # copy to satisfy image creation
+    #
+    cp "${source}" "${ptx_pkg_dir}/"
+
+    #
+    # only created to satisfy image creation
+    #
+    touch ${pkg_xpkg_perms}
+
+    fakeroot ptxd_make_xpkg_install_impl ${source}
+}
+export -f ptxd_make_xpkg_install
-- 
2.15.1


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

Reply via email to