summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_image_genimage.sh
blob: dd1e47412acd3d16cf05bd24b85dc00a6ee016e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
# Copyright (C) 2012 by Michael Olbrich <m.olbrich@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.
#

#
# find and prepare the config file and any includes
#
# returns:
# 0 if a config file and all includes are ready
# 1 otherwise
#
# array "genimage_configs" contains all config files starting with the
# requested file
#
ptxd_make_image_genimage_config() {
    local cfg tmp inc
    local -a includes
    ptxd_get_alternative config/images "${1}" || ptxd_bailout "could not find config file ${1}"
    cfg="${ptxd_reply}"
    tmp="${PTXDIST_TEMPDIR}/$(basename "${1}")"

    eval \
	"${image_env}" \
	IMAGE="$(basename "${image_image}")" \
	ptxd_replace_magic "${cfg}" > "${tmp}" &&

    genimage_configs[${#genimage_configs[@]}]="${tmp}" &&
    echo "${image_image}: \$(call genimage/config, ${1})" >> "${pkg_genimage_deps}"

    includes=( $(sed -n "s/.*\<include(['\"]\(.*\)['\"]).*/\1/p" "${tmp}") ) &&
    sed  -i "s:\(.*\<include(['\"]\)\(.*\)\(['\"]).*\):\1${PTXDIST_TEMPDIR}/\2\3:" "${tmp}" &&
    for inc in "${includes[@]}"; do
        ptxd_make_image_genimage_config "${inc}"
    done
}
export -f ptxd_make_image_genimage_config

#
# extract ipkg an generate a tgz image
#
ptxd_make_image_genimage_impl() {
    local tmpdir config file
    local -a genimage_configs
    tmpdir="$(mktemp -d "${PTXDIST_TEMPDIR}/genimage.XXXXXX")"

    ptxd_make_image_init &&
    pkg_genimage_deps="${ptx_state_dir}/${pkg_pkg}.deps" &&
    rm -f "${pkg_genimage_deps}" &&
    ptxd_make_image_genimage_config "${1}" &&

    rm -rf "${pkg_dir}" &&
    mkdir -p "${pkg_dir}" &&
    for file in ${image_files}; do
	ptxd_make_extract_archive "${file}" "${pkg_dir}"
    done &&
    if [ -n "${image_pkgs}" ]; then
	ptxd_get_ipkg_files ${image_pkgs} &&
	ptxd_make_image_extract_xpkg_files "${pkg_dir}"
    fi &&

    ptxd_eval \
	"${image_env}" \
	genimage \
	--loglevel $((PTXDIST_VERBOSE+1)) \
	--rootpath "${pkg_dir}" \
	--tmppath "${tmpdir}" \
	--outputpath "$(dirname "${image_image}")" \
	--inputpath "${ptx_image_dir}" \
	--config "${genimage_configs}" &&

    rm -r "${pkg_dir}"
}
export -f ptxd_make_image_genimage_impl

ptxd_make_image_genimage() {
    fakeroot ptxd_make_image_genimage_impl "${1}"
}
export -f ptxd_make_image_genimage