Skip to content

Commit c62192a

Browse files
committed
Fix Go version discovery on Ubuntu versions
1 parent 0ac8612 commit c62192a

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

uyuni-tools.spec

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ BuildRequires: golang(API) >= 1.25
8383

8484
%if 0%{?ubuntu}
8585
%define go_version 1.22
86+
# On Ubuntu 22.04, the metapackage golang is too old (1.18) and
87+
# we must use the versioned package name specifically for this OS version.
88+
%if 0%{?ubuntu} == 2204
89+
BuildRequires: golang-%{go_version}-go
90+
%else
8691
BuildRequires: golang >= %{go_version}
8792
%endif
93+
%endif
8894
# ubuntu
8995

9096
%if 0%{?debian}
@@ -324,15 +330,43 @@ go_tags=""
324330

325331
go_path=""
326332
%if 0%{?ubuntu}
327-
if test -d /usr/lib/go-%{go_version}/bin/; then
328-
go_path=/usr/lib/go-%{go_version}/bin/
333+
max_major=0
334+
max_minor=0
335+
336+
for dir in /usr/lib/go-*/bin; do
337+
if [ -x "$dir/go" ]; then
338+
# Extract version string (e.g. from /usr/lib/go-1.22.1/bin to 1.22.1)
339+
v_str="${dir%/bin}"
340+
v_str="${v_str#/usr/lib/go-}"
341+
# Get Major: Everything before the first dot
342+
major="${v_str%%.*}"
343+
# Get the rest: Everything after the first dot (e.g., 22.1)
344+
minor_full="${v_str#*.}"
345+
# Get Minor: Everything before the first dot in the 'rest' (e.g., 22)
346+
minor="${minor_full%%.*}"
347+
if [ "$major" -gt "$max_major" ] || { [ "$major" -eq "$max_major" ] && [ "$minor" -gt "$max_minor" ]; }; then
348+
max_major=$major
349+
max_minor=$minor
350+
go_path="$dir/"
351+
fi
352+
fi
353+
done
354+
# Minimum version check against go_version macro
355+
req_ver="%{go_version}"
356+
req_major="${req_ver%%.*}"
357+
req_minor_full="${req_ver#*.}"
358+
req_minor="${req_minor_full%%.*}"
359+
360+
if [ -n "$go_path" ]; then
361+
if [ "$max_major" -lt "$req_major" ] || { [ "$max_major" -eq "$req_major" ] && [ "$max_minor" -lt "$req_minor" ]; }; then
362+
echo "ERROR: Found Go version ${max_major}.${max_minor} at ${go_path}, but version >= %{go_version} is required."
363+
exit 1
364+
fi
329365
fi
330366
%else
331367
%if "%{?_go_bin}" != ""
332368
go_path='%{_go_bin}/'
333369
%endif
334-
# "_go_bin" != ""
335-
336370
%endif
337371
# ubuntu
338372

0 commit comments

Comments
 (0)