summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_xpkg_common.sh
blob: d93680ff75d2d67268b6f31bdfc5cb634dc36979 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
#
# Copyright (C) 2008, 2009, 2010 by Marc Kleine-Budde <mkl@pengutronix.de>
#
# For further information about the PTXdist project and license conditions
# see the README file.
#

#
# perm file separator changed to allow ':' in filenames
#
# $1: perm file path
#
ptxd_check_obsolete_perm() {
	while [ $# -gt 0 ]; do
		if test -s "${1}" && ! grep -q -P "\x1F" "${1}"; then
			ptxd_bailout "obsolete perm file detected, please run 'ptxdist clean root'"
		fi
		shift
	done
}
export -f ptxd_check_obsolete_perm

#
# change permissions and ownership of files and create device nodes.
# the paths specified in the permissions file are prefixed with the
# current working directory.
#
# typically used to create dev nodes in a fakeroot environment in the
# imageing process
#
# $1: permissions file
#
ptxd_dopermissions() {
	ptxd_check_obsolete_perm "${@}"
	gawk -f "${PTXDIST_LIB_DIR}/ptxd_lib_dopermissions.awk" "${@}"
}
export -f ptxd_dopermissions


#
# ptxd_do_xpkg_map - do the mapping from package name to xpkg name(s)
#
# in:
# ${@}	package name(s)
#
# out:
# ${ptxd_reply[@]}	array of xpkg names
#
# return:
# 0	if xpkg names are found
# 1	if no xpkg names are found
#
# ptxd_reply (array)
#
ptxd_do_xpkg_map() {
    local pkg
    for pkg in "${@}"; do
	if ! [[ " ${ptx_packages_selected} " =~ " ${pkg} " ]]; then
	    ptxd_bailout "${pkg} is not a package or not selected"
	fi
    done
    set -- "${@/#/${ptx_state_dir}/}"

    ptxd_reply=( $(cat "${@/%/.xpkg.map}" 2>/dev/null) )

    [ ${#ptxd_reply[@]} -ne 0 ]
}
export -f ptxd_do_xpkg_map


#
# initialize variables needed for packaging
#
ptxd_make_xpkg_init() {
    if [ -z "${pkg_xpkg}" ]; then
	ptxd_bailout "'pkg_xpkg' undefined"
    fi

    #
    # sanitize pkg_xpkg name
    #
    # replace "_" by "-"
    #
    pkg_xpkg="${pkg_xpkg//_/-}"

    #
    # sanitize pkg_version
    #
    # separate (alpha|beta|gamma|rc) with "~"
    # replace "_" by "."
    # replace "-" by "+"
    #
    if [ -z "${pkg_xpkg_version}" ]; then
	pkg_xpkg_version="$(sed -r 's/[~\.-]?(alpha|beta|gamma|rc|pre)/~\1/g' <<< ${pkg_version} | tr '_-' '.+')"
    fi
    if [ -z ${pkg_xpkg_version} ]; then
	ptxd_bailout "${FUNCNAME}: please define <PKG>_VERSION"
    fi

    ptxd_make_world_init || return

    # license
    pkg_license="${pkg_license:-unknown}"
    pkg_xpkg_license="${pkg_xpkg_license:-${pkg_license}}"
    pkg_xpkg_license_file="${ptx_state_dir}/${pkg_xpkg}.license"

    # packaging stuff
    pkg_xpkg_install_deps="${ptx_state_dir}/${pkg_xpkg}.deps"
    pkg_xpkg_perms="${ptx_state_dir}/${pkg_xpkg}.perms"
    pkg_xpkg_cmds="${ptx_state_dir}/${pkg_xpkg}.cmds"

    pkg_xpkg_tmp="${ptx_pkg_dir}/${pkg_xpkg}.tmp"
    pkg_xpkg_control_dir="${pkg_xpkg_tmp}/CONTROL"
    pkg_xpkg_control="${pkg_xpkg_control_dir}/control"
    pkg_xpkg_conffiles="${pkg_xpkg_control_dir}/conffiles"
    pkg_xpkg_dbg_tmp="${ptx_pkg_dir}/${pkg_xpkg}-dbgsym.tmp"
    pkg_xpkg_dbg_control_dir="${pkg_xpkg_dbg_tmp}/CONTROL"
    pkg_xpkg_dbg_control="${pkg_xpkg_dbg_control_dir}/control"
}
export -f ptxd_make_xpkg_init