summaryrefslogtreecommitdiffstats
path: root/lib/package/2.sh
blob: 745369f00a30ecaa5f70c8db6f8554358b11a2f8 (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
# opkbuild
# lib/package/2
# Functions for retrieving metadata from packages in SPF 2.0.
#
# Copyright (C) 2012 Patrick "P. J." McDermott
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

[ -n "${_OB_PACKAGE_2_SM}" ] && return 0
_OB_PACKAGE_2_SM='true'

ob_use control
ob_use changelog

_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='Essential Depends Recommends Suggests '\
'Pre-Depends Conflicts Provides Replaces'
_OB_CURRENT_PACKAGE_2=

_ob_parse_package_metadata_2()
{
	_ob_local _obppm2_pkg

	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 _obppm2_pkg in $(ob_get_binary_packages); do
		_OB_CURRENT_PACKAGE_2="${_obppm2_pkg}"
		ob_parse_control "${_OB_PACKAGE_DIR}/${_obppm2_pkg}.pkg/control" \
			_ob_binfield_2 \
			"${_OB_BINARY_FIELDS_REQUIRED_2}" "${_OB_BINARY_FIELDS_OPTIONAL_2}"
	done

	_ob_return 0
	return ${?}
}

_ob_get_binary_packages_2()
{
	_ob_local _obgbp2_pkgs _obgbp2_pkg_control

	for _obgbp2_pkg_control in "${_OB_PACKAGE_DIR}/"*'.pkg/control'; do

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

		ob_validate_binary_name "${_obgbp2_pkg_control}"

		_obgbp2_pkgs="${_obgbp2_pkgs} ${_obgbp2_pkg_control}"

	done

	_ob_set_binary_packages "${_obgbp2_pkgs}"

	_ob_return 0
	return ${?}
}

_ob_srcfield_2()
{
	_ob_local

	_ob_set_source_parameter "${OB_CONTROL_NAME}" "${OB_CONTROL_VALUE}"

	_ob_return 0
	return ${?}
}

_ob_change_2()
{
	_ob_local

	_ob_set_source_parameter Source "${OB_CHANGELOG_SOURCE}"
	_ob_set_source_parameter Version "${OB_CHANGELOG_VERSION}"
	_ob_set_source_parameter Distribution "${OB_CHANGELOG_DISTRIBUTION}"
	_ob_set_source_parameter Changes "${OB_CHANGELOG_CHANGES}"
	_ob_set_source_parameter Uploader "${OB_CHANGELOG_MAINTAINER}"
	_ob_set_source_parameter Date "${OB_CHANGELOG_DATE}"

	# Parse only the first changelog entry.
	_ob_return 1
	return ${?}
}

_ob_binfield_2()
{
	_ob_local

	_ob_set_binary_parameter "${_OB_CURRENT_PACKAGE_2}" "${OB_CONTROL_NAME}" \
		"${OB_CONTROL_VALUE}"

	_ob_return 0
	return ${?}
}

_ob_get_doc_package_2()
{
	_ob_local _obgdp2_pkg _obgdp2_doc_pkg

	for _obgdp2_pkg in $(ob_get_binary_packages); do
		if [ -r "${_OB_PACKAGE_DIR}/${_obgdp2_pkg}.pkg/docs" ]; then
			if [ -n "${_obgdp2_doc_pkg}" ]; then
				_ob_return 1
				return ${?}
			fi
			_obgdp2_doc_pkg="${_obgdp2_pkg}"
		fi
	done

	if [ -z "${_obgdp2_doc_pkg}" ]; then
		_ob_return 1
		return ${?}
	fi

	echo "${_obgdp2_doc_pkg}"

	_ob_return 0
	return ${?}
}

_ob_get_doc_files_2()
{
	_ob_local _obgdf2_doc_pkg

	_obgdf2_doc_pkg="$(_ob_get_doc_package_2)"

	if [ ${?} -ne 0 ]; then
		_ob_return 1
		return ${?}
	fi

	cat <<EOF
../copyright
../changelog changelog.dist
../README README.dist
EOF
	cat "${_OB_PACKAGE_DIR}/${_obgdf2_doc_pkg}.pkg/docs"

	_ob_return 0
	return ${?}
}