@@ -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
8691BuildRequires: golang >= %{go_version }
8792%endif
93+ %endif
8894# ubuntu
8995
9096%if 0%{?debian }
@@ -324,15 +330,62 @@ go_tags=""
324330
325331go_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+ max_patch= 0
336+ max_ver_str= "0.0.0"
337+
338+ for dir in /usr/lib/go-*/bin; do
339+ if [ -x "$dir/go" ]; then
340+ # Extract version string (e.g. from /usr/lib/go-1.22.1/bin to 1.22.1)
341+ v_str= "${dir%/bin}"
342+ v_str= "${v_str#/usr/lib/go-}"
343+ major= "${v_str%%.*}"
344+ minor_full= "${v_str#*.}"
345+ minor= "${minor_full%%.*}"
346+ patch= 0
347+ if [ "$minor_full" != "$minor" ]; then
348+ patch_full= "${minor_full#*.}"
349+ patch= "${patch_full%%.*}"
350+ fi
351+ # Comparison (Major > Minor > Patch)
352+ is_newer= 0
353+ if [ "$major" -gt "$max_major" ]; then
354+ is_newer= 1
355+ elif [ "$major" -eq "$max_major" ]; then
356+ if [ "$minor" -gt "$max_minor" ]; then
357+ is_newer= 1
358+ elif [ "$minor" -eq "$max_minor" ] && [ "$patch" -gt "$max_patch" ]; then
359+ is_newer= 1
360+ fi
361+ fi
362+
363+ if [ "$is_newer" -eq 1 ]; then
364+ max_major= $major
365+ max_minor= $minor
366+ max_patch= $patch
367+ max_ver_str= "$v_str"
368+ go_path= "$dir/"
369+ fi
370+ fi
371+ done
372+
373+ # Minimum version check
374+ req_ver= "%{go_version }"
375+ req_major= "${req_ver%%.*}"
376+ req_minor_full= "${req_ver#*.}"
377+ req_minor= "${req_minor_full%%.*}"
378+
379+ if [ -n "$go_path" ]; then
380+ if [ "$max_major" -lt "$req_major" ] || { [ "$max_major" -eq "$req_major" ] && [ "$max_minor" -lt "$req_minor" ]; }; then
381+ echo "ERROR: Found Go version ${max_ver_str} at ${go_path}, but version >= %{go_version } is required."
382+ exit 1
383+ fi
329384 fi
330385%else
331386 %if "%{?_go_bin }" != ""
332387 go_path= '%{_go_bin }/'
333388 %endif
334- # "_go_bin" != ""
335-
336389%endif
337390# ubuntu
338391
0 commit comments