This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
identify-archful-srpms
executable file
·226 lines (183 loc) · 6.96 KB
/
identify-archful-srpms
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
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
WORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $WORK_DIR/conf/config.inc
source $WORK_DIR/utils.inc
#####
# Variables
#####
# DIRS
# FILES/VARIABLES
# BINARY VARIABLES
# LIST VARIABLES
# ASSOCIATIVE ARRAY VARIABLES
declare -A MERGED_SOURCE_LIST
declare -A ARCHFUL_SOURCE_LIST
declare -A SRPM_DOWNLOADED_LIST
# merge_source_package_lists
#
# Loop through all architectures, merging the arch-specific buildroot source
# package lists
#
# The merged list of per-arch source package lists is saved as the keys of
# the global associate array MERGED_SOURCE_LIST, with the value for each key
# being meaningless.
merge_source_package_lists() {
local this_arch this_package
local data_dir timestamp_file src_pkgs_file
local timestamp
local -a src_pkgs_list
MERGED_SOURCE_LIST=()
for this_arch in ${ARCH_LIST[@]}
do
echo "Merging source package list for arch ${this_arch}..."
data_dir="${DATA_DIR_BASE}/${this_arch}/${NEW_DIR}"
timestamp_file="${data_dir}/${BR_TIMESTAMP_FILENAME}"
src_pkgs_file="${data_dir}/${BR_SOURCE_PKGNAMES_FILENAME}"
if [ ! -r "${timestamp_file}" ] ; then
errexit "Missing buildroot timestmap file for arch ${this_arch}: ${timestamp_file}"
fi
if [ ! -r "${src_pkgs_file}" ] ; then
errexit "Missing buildroot source package list file for arch ${this_arch}: ${src_pkgs_file}"
fi
timestamp=$(cat "${timestamp_file}")
mapfile -t src_pkgs_list < "${src_pkgs_file}"
if [ ${#src_pkgs_list[@]} -eq 0 ] ; then
errexit "No buildroot source packages listed in ${src_pkgs_file}."
fi
echo "Timestap is ${timestamp}."
echo "${#src_pkgs_list[@]} buildroot source packages for arch ${this_arch}."
for this_package in ${src_pkgs_list[@]}
do
MERGED_SOURCE_LIST[${this_package}]=1
done
# finish with this arch
done
echo "${#MERGED_SOURCE_LIST[@]} buildroot source packages for all architectures combined."
}
# download_source_rpms srpm_dir pkg1 pkg2 ...
# srpm_dir: directory into which source rpms should be downloaded
# pkg1 ...: list of base package names for which to download source rpms
download_source_rpms() {
local srpm_dir="$1"
local -a pkg_list=("${@:2}")
# pick first arch as forced arch for source download, since they're all the same
local src_dl_arch=${ARCH_LIST[0]}
echo "Downloading SRPMs."
local DNF_OPTIONS="--quiet --forcearch=${src_dl_arch} -c ${REPO_DIR}/${REPONAME}.${src_dl_arch}.repo ${DNF_OPTIONS_NOCONF_BASE}"
# add --skip-broken because source repo isn't always up to date with binary repos
DNF_OPTIONS="--skip-broken ${DNF_OPTIONS}"
dnf ${DNF_OPTIONS} download --downloaddir "${srpm_dir}" --source "${pkg_list[@]}"
}
# check_source_rpms srpm_dir
# srpm_dir: directory into which source rpms should be downloaded
#
# Check that all expected source packages have been downloaded, and remove
# any extraneous or obsolete source packages.
#
# While checking the source rpms, the global associate array
# SRPM_DOWNLOADED_LIST is constructed. The keys are the base package names
# for each source rpm file, with the corresponing value for each being the
# source rpm file path.
check_source_rpms() {
local srpm_dir="$1"
local srpm
local pkgname
local -a ordered_srpms
echo "Checking SRPMs."
# Create mapping of package names to SRPM files
SRPM_DOWNLOADED_LIST=()
for srpm in ${srpm_dir}/*.src.rpm
do
pkgname=$(pkgname_from_srpm_file ${srpm})
if [ ! -v MERGED_SOURCE_LIST[${pkgname}] ]; then
echo "NOTICE: Found extraneous SRPM for package ${pkgname}! Removing."
rm -f "${srpm}"
continue
fi
if [ ! -v SRPM_DOWNLOADED_LIST[${pkgname}] ]; then
SRPM_DOWNLOADED_LIST[${pkgname}]="${srpm}"
else
echo "NOTICE: Found multiple SRPMs for package ${pkgname}."
# set ordered_srpms[0] to older SRPM, ordered_srpms[1] to newer
ordered_srpms=($(order_srpm_files "${srpm}" "${SRPM_DOWNLOADED_LIST[${pkgname}]}"))
if [ ${#ordered_srpms[@]} -ne 2 ]; then
echo "WARNING: Unable to determine older SRPM for package ${pkgname}!"
continue
fi
echo " Removing older SRPM: ${ordered_srpms[0]##*/}"
echo " Keeping newer SRPM : ${ordered_srpms[1]##*/}"
# keep newer SRPM
SRPM_DOWNLOADED_LIST[${pkgname}]="${ordered_srpms[1]}"
# remove old SRPM and any previously extracted spec file
rm -f "${ordered_srpms[0]}" "${srpm_dir}/${pkgname}.spec"
fi
done
# Check that all source packages have been downloaded
for pkgname in ${!MERGED_SOURCE_LIST[@]}
do
if [ ! -v SRPM_DOWNLOADED_LIST[${pkgname}] ]; then
echo "WARNING: SRPM for package ${pkgname} was not downloaded!"
fi
done
}
# find_archful_source_packages srpm_dir
# srpm_dir: directory into which source rpms should be downloaded
#
# The list of archful source packages is saved as the keys of the global
# associate array ARCHFUL_SOURCE_LIST, with the value for each key being
# meaningless.
find_archful_source_packages() {
local srpm_dir="$1"
local pkgname
# Check each downloaded package to see if it is archful
ARCHFUL_SOURCE_LIST=()
for pkgname in ${!SRPM_DOWNLOADED_LIST[@]}
do
srpm=${SRPM_DOWNLOADED_LIST[${pkgname}]}
specname="${pkgname}.spec"
specpath="${srpm_dir}/${specname}"
if [ ! -r "${specpath}" ] ; then
rpm2cpio ${srpm} | cpio --extract --quiet --unconditional --directory "${srpm_dir}" "${specname}"
if [ ! -r "${specpath}" ] ; then
echo "Failed to extract SPEC file from ${srpm}!"
continue
fi
fi
if egrep '[[:blank:]]*%ifn?arch[[:blank:]]' "${specpath}" >/dev/null; then
[ "${VERBOSE}" == "TRUE" ] && echo "${pkgname} is archful."
ARCHFUL_SOURCE_LIST[${pkgname}]=1
else
[ "${VERBOSE}" == "TRUE" ] && echo "${pkgname} is NOT archful."
fi
done
echo "${#ARCHFUL_SOURCE_LIST[@]} archful buildroot source packages identified."
}
# write_source_package_lists data_dir
# data_dir: directory to which to write package lists
#
# Write out the list of archful source packages and mapping of package
# names to SRPM base file names.
write_source_package_lists() {
local data_dir="$1"
local archful_pkglist_file="${data_dir}/${BR_ARCHFUL_SOURCE_PKGNAMES_FILENAME}"
local pkg_to_srpm_map_file="${data_dir}/${BR_SOURCE_PKGMAP_FILENAME}"
# write out the list of archful source packages
printf "%s\n" "${!ARCHFUL_SOURCE_LIST[@]}" | sort -o "${archful_pkglist_file}"
# write out the mapping of package names to SRPM base file names
for pkgname in ${!SRPM_DOWNLOADED_LIST[@]}
do
echo "${pkgname}=${SRPM_DOWNLOADED_LIST[${pkgname}]##*/}"
done \
| sort -o "${pkg_to_srpm_map_file}"
}
dnf --quiet clean all
echo "Identifying source packages that may differ based on architecture ..."
data_dir="${DATA_DIR_BASE}/source/${NEW_DIR}"
srpm_dir="${data_dir}/srpms"
merge_source_package_lists
mkdir -p "${srpm_dir}"
download_source_rpms "${srpm_dir}" ${!MERGED_SOURCE_LIST[@]}
check_source_rpms "${srpm_dir}"
find_archful_source_packages "${srpm_dir}"
write_source_package_lists "${data_dir}"
exit 0