summaryrefslogtreecommitdiffstats
path: root/src/include.sh
blob: 0c27f603cb67cdf2ab6bc76e8c699a3e4553a149 (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
# pro-archman
# src/include.sh
# Functions for including changes
#
# Copyright (C) 2013, 2014  Patrick McDermott
#
# This file is part of the ProteanOS Archive Manager.
#
# The ProteanOS Archive Manager 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.
#
# The ProteanOS Archive Manager 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 the ProteanOS Archive Manager.  If not, see
# <http://www.gnu.org/licenses/>.

_INCLUDE_CHANGES_FIELDS='Format Source Binary Version Architecture Platform
Distribution Maintainer Changed-By Date Description Changes Files'

_include_format=
_include_source=
_include_version=
_include_distribution=
_include_files=

_include_changes_field()
{
	local name="${1}"
	local value="${2}"
	shift 2

	case "${name}" in
		'Format')
			_include_format="${value}"
			;;
		'Source')
			_include_source="${value}"
			;;
		'Version')
			_include_version="${value}"
			;;
		'Distribution')
			_include_distribution="${value}"
			;;
		'Files')
			_include_files="${value}"
			;;
	esac
}

include_changes()
{
	local changes="${1}"
	shift 1
	local chan=
	local dist=
	local source=
	local srcver=
	local script=
	local bvaps=
	local binver=
	local arch=
	local plat=
	local old_ver=
	local files=
	local size=
	local sect=
	local file=
	local pkg=
	local pool_file=

	if ! parse_control "${changes}" _include_changes_field \
			"${_INCLUDE_CHANGES_FIELDS}" ''; then
		error 2 "$(get_msg 'include_invalid_changes')" "${changes}"
	fi
	if [ "x${_include_format}" != 'x1.0' ]; then
		error 2 "$(get_msg 'include_unknown_changes_format')" \
			"${changes}" "${_include_format}"
	fi
	chan="${conf_incoming_channel}"
	dist="${_include_distribution}"
	source="${_include_source}"
	srcver="${_include_version}"

	info "$(get_msg 'include_including')" "${source}" "${srcver}" \
		"${chan}" "${dist}"

	if [ "x${_include_files}" = 'x' ]; then
		warn "$(get_msg 'include_no_files')"
		return 0
	fi

	# List of (binver, arch, plat) tuples to be checked later.
	script='s/[0-9][0-9]* [^ ][^ ]* [^_]*_\([^_]*\)'
	script="${script}"'_\([^_]*\)_\([^_]*\)\.opk/\1 \2 \3/p'
	bvaps="$(printf '%s\n' "${_include_files}" | \
		sed -n "${script}" | LC_COLLATE='C' sort | uniq)"

	# Pre-inclusion database sanity checks and updates: check for an
	# existing version of the package in the suite.
	old_ver="$(db_get_srcver "${chan}" "${dist}" "${source}")"
	if [ "x${old_ver}" = 'x' ]; then
		# New package.
		db_set_srcver "${chan}" "${dist}" "${source}" "${srcver}"
	elif [ "x${old_ver}" != "x${_include_version}" ]; then
		# New source version.  Remove the old source package from the
		# suite.
		remove_source_from_suite "${chan}" "${dist}" "${source}"
		db_set_srcver "${chan}" "${dist}" "${source}" "${srcver}"
	else
		# Same source version.  Hopefully different binary version,
		# architecture, and/or platform.  Make sure such "bvap" tuples
		# are new.
		while read -r binver arch plat; do
			old_ver="$(db_get_binver "${chan}" "${dist}" \
				"${arch}" "${plat}" "${source}")"
			if [ "x${old_ver}" = "x${binver}" ]; then
				error 2 "$(get_msg 'include_bvap_exists')" \
					"${binver}" "${arch}" "${plat}"
			fi
		done 0<<-EOF
			${bvaps}
			EOF
	fi

	# For each (binver, arch, plat) tuple in the package changes:
	#   * Remove old binary packages of the same arch and plat from the
	#     suite.
	#   * Set the new binary version of packages of the arch and plat in the
	#     suite.
	#   * Set the reference count for the tuple to 1.
	# This is done separately from the next loop because it must be done
	# exactly once for each bvap tuple.  The next loop can hit any given
	# bvap tuple multiple times.
	while read -r binver arch plat; do
		old_ver="$(db_get_binver "${chan}" "${dist}" \
			"${arch}" "${plat}" "${source}")"
		if [ "x${old_ver}" != 'x' ]; then
			remove_packages_from_suite_archplat "${chan}" \
				"${dist}" "${arch}" "${plat}" "${source}"
		fi
		db_set_binver "${chan}" "${dist}" "${arch}" "${plat}" \
			"${source}" "${binver}"
		db_inc_references "${arch}" "${plat}" "${source}" "${binver}" \
			1>/dev/null
	done 0<<-EOF
		${bvaps}
		EOF

	# Include each binary package.
	files=''
	while read -r size sect file; do
		if [ "x${file##[ 	]}" = 'x' ]; then
			continue
		fi
		IFS='_' read -r pkg binver arch plat 0<<-EOF
			${file%.opk}
			EOF
		db_add_package "${arch}" "${plat}" "${source}" "${binver}" \
			"${size}" "${sect}" "${pkg}"
		pool_file="pool/$(hash_name "${source}")/${source}"
		pool_file="${pool_file}/${pkg}_${binver}_${arch}_${plat}.opk"
		file="$(dirname -- "${changes}")/${file}"
		files="${files} ${file}"
		cp -p -- "${file}" "${base_dir}/${pool_file}"
		feed_add_package "${chan}" "${dist}" "${arch}" "${plat}" \
			"${sect}" "${pkg}" "${size}" "${pool_file}"
	done 0<<-EOF
		${_include_files}
		EOF

	printf '%s\n' ${files}
	return 0
}