summaryrefslogtreecommitdiffstats
path: root/lib/package/2.sh
blob: 3e7bc0a136444703ae2cc27ae7843d0912565239 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# Functions for retrieving metadata from packages in SPF 2.0
#
# Copyright (C) 2012, 2019 Patrick McDermott
#
# This file is part of opkbuild.
#
# opkbuild is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# opkbuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with opkbuild.  If not, see <http://www.gnu.org/licenses/>.

_OB_SOURCE_FIELDS_REQUIRED_2='Maintainer'
_OB_SOURCE_FIELDS_OPTIONAL_2='Build-Depends Homepage'
_OB_BINARY_FIELDS_REQUIRED_2='Architecture Platform Description'
_OB_BINARY_FIELDS_OPTIONAL_2='Section Essential Depends Recommends Suggests '\
'Pre-Depends Conflicts Provides Replaces'

_ob_source_substvars_set_2=false

_ob_parse_package_metadata_2()
{
	local pkg=
	local sect=

	ob_parse_control "${_ob_package_dir}/control" _ob_srcfield_2 '' \
		"${_OB_SOURCE_FIELDS_REQUIRED_2}" \
		"${_OB_SOURCE_FIELDS_OPTIONAL_2}"
	ob_parse_changelog "${_ob_package_dir}/changelog" _ob_change_2

	for pkg in $(ob_get_binary_packages); do
		ob_parse_control "${_ob_package_dir}/${pkg}.pkg/control" \
			_ob_binfield_2 "${pkg}" \
			"${_OB_BINARY_FIELDS_REQUIRED_2}" \
			"${_OB_BINARY_FIELDS_OPTIONAL_2}"
		sect="$(ob_get_binary_parameter "${pkg}" 'Section')"
		if ! ob_validate_section "${sect}"; then
			_ob_warn_msg 'bad_section' "${pkg}" "${sect}"
			continue
		fi
	done

	return 0
}

_ob_get_binary_packages_2()
{
	local pkgs=
	local pkg_control=

	for pkg_control in "${_ob_package_dir}/"*'.pkg/control'; do

		if [ ! -f "${pkg_control}" ]; then
			continue
		fi

		pkg_control="${pkg_control%.pkg/control}"
		pkg_control="${pkg_control##*/}"

		ob_validate_binary_name "${pkg_control}"

		pkgs="${pkgs} ${pkg_control}"

	done

	_ob_set_binary_packages "${pkgs}"

	return 0
}

_ob_srcfield_2()
{
	local name="${1}"
	local value="${2}"
	local user_data="${3}"
	shift 3 || _ob_abort

	_ob_set_source_parameter "${name}" "${value}"

	return 0
}

_ob_change_2()
{
	local source="${1}"
	local version="${2}"
	local distribution="${3}"
	local changes="${4}"
	local maintainer="${5}"
	local date="${6}"
	shift 6 || _ob_abort

	_ob_set_source_parameter Source "${source}"
	_ob_set_source_parameter Version "${version}"
	_ob_set_source_parameter Distribution "${distribution}"
	_ob_set_source_parameter Changes "${changes}"
	_ob_set_source_parameter Uploader "${maintainer}"
	_ob_set_source_parameter Date "${date}"

	# Parse only the first changelog entry.
	return 1
}

_ob_binfield_2()
{
	local name="${1}"
	local value="${2}"
	local pkg="${3}"
	shift 3 || _ob_abort

	_ob_set_binary_parameter "${pkg}" "${name}" "${value}"

	return 0
}

_ob_get_doc_package_2()
{
	local pkg=
	local doc_pkg=

	for pkg in $(ob_get_binary_packages); do
		if [ -r "${_ob_package_dir}/${pkg}.pkg/docs" ]; then
			if [ -n "${doc_pkg}" ]; then
				return 1
			fi
			doc_pkg="${pkg}"
		fi
	done

	if [ -z "${doc_pkg}" ]; then
		return 1
	fi

	printf '%s' "${doc_pkg}"

	return 0
}

_ob_get_doc_files_2()
{
	local doc_pkg=

	doc_pkg="$(_ob_get_doc_package_2)"

	cat <<-EOF
		../copyright
		../changelog changelog.dist
		../README README.dist
		EOF
	cat -- "${_ob_package_dir}/${doc_pkg}.pkg/docs"

	return 0
}

_ob_source_substvar_2()
{
	local name="${1}"
	local value="${2}"
	local user_data="${3}"
	shift 3 || _ob_abort

	ob_set_source_substvar "${name}" "${value}"

	return 0
}

_ob_binary_substvar_2()
{
	local name="${1}"
	local value="${2}"
	local pkg="${3}"
	shift 3 || _ob_abort

	ob_set_binary_substvar "${name}" "${value}" "${pkg}"

	return 0
}

_ob_set_package_substvars_2()
{
	local pkg="${1}"
	shift 1 || _ob_abort

	if ! ${_ob_source_substvars_set_2}; then
		if [ -f "${_ob_package_dir}/substvars" ]; then
			ob_parse_control "${_ob_package_dir}/substvars" \
				_ob_source_substvar_2 ''
		fi

		ob_set_source_substvar 'Source-Version' \
			"$(ob_get_source_parameter 'Version')"
		ob_set_source_substvar 'Binary-Version' \
			"$(ob_get_source_parameter 'Version')"
		ob_set_source_substvar 'Host-Arch' "${OPK_HOST_ARCH}"
		ob_set_source_substvar 'Host-Plat' "${OPK_HOST_PLAT}"

		_ob_source_substvars_set_2=true
	fi

	if [ -f "${pkg}.substvars" ]; then
		ob_parse_control "${pkg}.substvars" \
			_ob_binary_substvar_2 "${pkg}"
	fi

	return 0
}