@@ -58,6 +58,35 @@ ignore_no_source_tarball=" \
5858
5959alt_source_tag=" Source9999"
6060
61+ chroot_rpmspec () {
62+ local chroot_dir_path
63+ local sourcedir
64+
65+ chroot_dir_path=" $1 "
66+ shift
67+
68+ if [[ ! -d " $chroot_dir_path " ]]; then
69+ echo " Expected a chroot directory as first argument to 'chroot_rpmspec'. Got '$chroot_dir_path '." >&2
70+ return 1
71+ fi
72+
73+ # Looking for spec path in the argument list to extract its directory.
74+ sourcedir=" "
75+ for arg in " $@ " ; do
76+ if [[ " $arg " == * .spec && -f " $chroot_dir_path /$arg " ]]; then
77+ sourcedir=" $( dirname " $arg " ) "
78+ break
79+ fi
80+ done
81+
82+ if [[ -z $sourcedir ]]; then
83+ echo " Must pass valid spec path to 'chroot_rpmspec'!" >&2
84+ return 1
85+ fi
86+
87+ sudo chroot " $chroot_dir_path " rpmspec -D " _sourcedir $sourcedir " " $@ "
88+ }
89+
6190prepare_chroot_environment () {
6291 local chroot_archive
6392 local chroot_dir_path
@@ -91,22 +120,19 @@ prepare_chroot_environment() {
91120 echo " %dist $dist_tag " | tee " $chroot_rpm_macros_dir_path /macros.dist"
92121 echo " %$dist_name $dist_number " | tee -a " $chroot_rpm_macros_dir_path /macros.dist"
93122 echo " %with_check 1" | tee -a " $chroot_rpm_macros_dir_path /macros.dist"
94- for macro_file in SPECS/azurelinux-rpm-macros/macros* SPECS/pyproject-rpm-macros/macros.pyproject SPECS/perl/macros.perl
95- do
123+ for macro_file in SPECS/azurelinux-rpm-macros/macros* SPECS/pyproject-rpm-macros/macros.pyproject SPECS/perl/macros.perl; do
96124 sudo cp -v " $macro_file " " $chroot_rpm_macros_dir_path "
97125 done
98126
99127 echo
100128}
101129
102- if [[ $# -lt 2 ]]
103- then
130+ if [[ $# -lt 2 ]]; then
104131 echo " No specs passed to validate."
105132 exit 1
106133fi
107134
108- if [[ ! -f " $1 " ]]
109- then
135+ if [[ ! -f " $1 " ]]; then
110136 echo " First argument is not a valid file. Please pass the path to the worker chroot's archive."
111137 exit 1
112138fi
@@ -115,8 +141,8 @@ rm -f bad_registrations.txt
115141
116142WORK_DIR=$( mktemp -d -t)
117143function clean_up {
118- echo " Removing the temporary directory '$WORK_DIR '."
119- rm -rf " $WORK_DIR "
144+ echo " Removing the temporary directory '$WORK_DIR '."
145+ rm -rf " $WORK_DIR "
120146}
121147trap clean_up EXIT SIGINT SIGTERM
122148
@@ -126,11 +152,9 @@ shift # Remove the first argument (the chroot archive) from the list of specs to
126152echo " Checking $# specs."
127153
128154i=0
129- for original_spec in " $@ "
130- do
131- i=$(( i+ 1 ))
155+ for original_spec in " $@ " ; do
156+ i=$(( i + 1 ))
132157 echo " [$i /$# ] Checking $original_spec ."
133-
134158 # Using a copy of the spec file, because parsing requires some pre-processing.
135159 original_spec_dir_path=" $( dirname " $original_spec " ) "
136160 cp -r " $original_spec_dir_path " " $WORK_DIR "
140164 host_spec=" $WORK_DIR /$chroot_spec "
141165
142166 # Skipping specs for signed packages. Their unsigned versions should already be included in the manifest.
143- if echo " $original_spec " | grep -q " SPECS-SIGNED"
144- then
167+ if echo " $original_spec " | grep -q " SPECS-SIGNED" ; then
145168 echo " $host_spec is being ignored (reason: signed package), skipping."
146169 continue
147170 fi
155178 # Removing trailing comments from "Source" tags.
156179 sed -Ei " s/^(\s*Source[0-9]*:.*)#.*/\1/" " $host_spec "
157180
158- name=$( sudo chroot " $WORK_DIR " rpmspec --srpm --qf " %{NAME}" -q " $chroot_spec " 2> /dev/null)
159- if [[ -z $name ]]
160- then
161- echo " Failed to get name from '$original_spec '. Please update the spec or the macros from the 'defines' variable in this script. Error:" >> bad_registrations.txt
162- sudo chroot " $WORK_DIR " rpmspec --srpm --qf " %{NAME}" -q " $chroot_spec " & >> bad_registrations.txt
181+ name=$( chroot_rpmspec " $WORK_DIR " --srpm --qf " %{NAME}" -q " $chroot_spec " 2> /dev/null)
182+ if [[ -z $name ]]; then
183+ echo " Failed to get name from '$original_spec '. Please update the spec or the chroot macros configuration in this script. Error:" >> bad_registrations.txt
184+ chroot_rpmspec " $WORK_DIR " --srpm --qf " %{NAME}" -q " $chroot_spec " & >> bad_registrations.txt
163185 continue
164186 fi
165187
166188 # Skipping specs from the ignore lists.
167- if echo " $ignore_multiple_sources $ignore_no_source_tarball " | grep -qP " (^|\s)$name ($|\s)"
168- then
189+ if echo " $ignore_multiple_sources $ignore_no_source_tarball " | grep -qP " (^|\s)$name ($|\s)" ; then
169190 echo " $name is being ignored (reason: explicitly ignored package), skipping."
170191 continue
171192 fi
172193
173- version=$( sudo chroot " $WORK_DIR " rpmspec --srpm --qf " %{VERSION}" -q " $chroot_spec " 2> /dev/null )
174- if [[ -z $version ]]
175- then
176- echo " Failed to get version from '$original_spec '. Please update the spec or the macros from the 'defines' variable in this script. Error:" >> bad_registrations.txt
177- sudo chroot " $WORK_DIR " rpmspec --srpm --qf " %{VERSION}" -q " $chroot_spec " & >> bad_registrations.txt
194+ version=$( chroot_rpmspec " $WORK_DIR " --srpm --qf " %{VERSION}" -q " $chroot_spec " 2> /dev/null)
195+ if [[ -z $version ]]; then
196+ echo " Failed to get version from '$original_spec '. Please update the spec or the chroot macros configuration in this script. Error:" >> bad_registrations.txt
197+ chroot_rpmspec " $WORK_DIR " --srpm --qf " %{VERSION}" -q " $chroot_spec " & >> bad_registrations.txt
178198 continue
179199 fi
180200
181- parsed_spec=" $( sudo chroot " $WORK_DIR " rpmspec --parse " $chroot_spec " 2> /dev/null) "
201+ parsed_spec=" $WORK_DIR /parsed.spec"
202+ chroot_rpmspec " $WORK_DIR " --parse " $chroot_spec " 2> /dev/null > " $parsed_spec "
182203
183204 # Reading the source0 file/URL.
184- if ! echo " $parsed_spec " | grep -qP " ^\s*Source0?:"
185- then
186- echo " No source file listed for $name :$version , skipping."
205+ if ! grep -qP " ^\s*Source0?:" " $parsed_spec " ; then
206+ echo " No source file listed for $name -$version , skipping."
187207 continue
188208 fi
189209
190- source0=$( echo " $parsed_spec " | grep -P " ^\s*Source0?:" | cut -d: -f2- | xargs)
210+ source0=$( grep -P " ^\s*Source0?:" " $parsed_spec " | cut -d: -f2- | xargs)
191211 echo " Source0: $source0 ."
192212
193213 # Reading the alternate source URL.
194214 source0_alt=" "
195- if echo " $parsed_spec " | grep -qP " ^\s*$alt_source_tag :"
196- then
197- source0_alt=$( echo " $parsed_spec " | grep -P " ^\s*$alt_source_tag :" | cut -d: -f2- | xargs)
215+ if grep -qP " ^\s*$alt_source_tag :" " $parsed_spec " ; then
216+ source0_alt=$( grep -P " ^\s*$alt_source_tag :" " $parsed_spec " | cut -d: -f2- | xargs)
198217 echo " Source0Alt: $source0_alt ."
199218 fi
200219
201220 # Pull the current registration from the cgmanifest file. Every registration should have a URL, so if we don't find one
202221 # that implies the registration is missing.
203222 manifest_url=$( jq --raw-output " .Registrations[].component.other | select(.name==\" $name \" and .version==\" $version \" ) | .downloadUrl" cgmanifest.json)
204- if [[ -z $manifest_url ]]
205- then
206- echo " Registration for $name :$version is missing" >> bad_registrations.txt
223+ if [[ -z $manifest_url ]]; then
224+ echo " Registration for $name -$version is missing" >> bad_registrations.txt
207225 else
208226 echo " Registration URL: $manifest_url ."
209227
210- if [[ " $manifest_url " != " $source0 " && " $manifest_url " != " $source0_alt " ]]
211- then
228+ if [[ " $manifest_url " != " $source0 " && " $manifest_url " != " $source0_alt " ]]; then
212229 {
213- echo " Registration URL for $name : $version ($manifest_url ) matches neither the first \" Source\" tag nor the alternate source URL."
230+ echo " Registration URL for $name - $version ($manifest_url ) matches neither the first \" Source\" tag nor the alternate source URL."
214231 printf ' \tFirst "Source" tag:\t%s\n' " $source0 "
215232 printf ' \tAlternate source URL:\t%s\n' " $source0_alt "
216- } >> bad_registrations.txt
233+ } >> bad_registrations.txt
217234 else
218235 # Try a few times to download the source listed in the manifest
219236 # Parsing output instead of using error codes because 'wget' returns code 8 for FTP, even if the file exists.
220237 # Sample HTTP(S) output: Remote file exists.
221238 # Sample FTP output: File ‘time-1.9.tar.gz’ exists.
222- if ! wget --secure-protocol=TLSv1_2 --spider --timeout=30 --tries=10 " ${manifest_url} " 2>&1 | grep -qP " ^(Remote file|File ‘.*’) exists.*"
223- then
224- echo " Registration for $name :$version has invalid URL '$manifest_url ' (could not download)" >> bad_registrations.txt
239+ if ! wget --secure-protocol=TLSv1_2 --spider --timeout=30 --tries=10 " ${manifest_url} " 2>&1 | grep -qP " ^(Remote file|File ‘.*’) exists.*" ; then
240+ echo " Registration for $name -$version has invalid URL '$manifest_url ' (could not download)" >> bad_registrations.txt
225241 fi
226242 fi
227243 fi
228244done
229245
230- if [[ -s bad_registrations.txt ]]
231- then
246+ if [[ -s bad_registrations.txt ]]; then
232247 echo " ####"
233248 echo " Found errors while analyzing modified spec files, cgmanifest.json may need to be updated."
234249 echo " ####"
0 commit comments