@@ -2,15 +2,45 @@ package flasherapi
22
33import (
44 "context"
5+ "log/slog"
6+ "strings"
57
68 "github.com/arduino/arduino-app-cli/pkg/board/remote"
79)
810
911// GetOSImageVersion returns the version of the OS image used in the board.
1012// It is used by the AppLab to enforce image version compatibility.
11- func GetOSImageVersion (conn remote.RemoteConn ) string {
12- // if no version is set, return a default value
13- return "20251123-159"
13+ func GetOSImageVersion (ctx context.Context , conn remote.RemoteConn ) (string , error ) {
14+ const defaultVersion = "20250807-136"
15+
16+ output , err := conn .GetCmd ("cat /etc/buildinfo" ).Output (ctx )
17+ if err != nil {
18+ return defaultVersion , err
19+ }
20+
21+ if version , ok := ParseOSImageVersion (string (output )); ok {
22+ slog .Info ("find OS Image version" , "version" , version )
23+ return version , nil
24+ }
25+ slog .Info ("Unable to find OS Image version" , "using default version" , defaultVersion )
26+ return defaultVersion , nil
27+ }
28+
29+ func ParseOSImageVersion (buildInfo string ) (string , bool ) {
30+ for _ , line := range strings .Split (buildInfo , "\n " ) {
31+ line = strings .TrimSpace (line )
32+
33+ key , value , ok := strings .Cut (line , "=" )
34+ if ! ok || key != "BUILD_ID" {
35+ continue
36+ }
37+
38+ version := strings .Trim (value , "\" ' " )
39+ if version != "" {
40+ return version , true
41+ }
42+ }
43+ return "" , false
1444}
1545
1646type OSImageRelease struct {
0 commit comments