@@ -21,6 +21,7 @@ import (
2121 "fmt"
2222 "os"
2323 "os/exec"
24+ "strconv"
2425 "strings"
2526 "syscall"
2627 "time"
@@ -295,3 +296,50 @@ func GetSysArch() string {
295296 }
296297 return arch
297298}
299+
300+ func GetUbuntuRelease () string {
301+ // The full shell command pipeline
302+ cmdString := "lsb_release -r | awk '{print $2}'"
303+
304+ // Execute the command using /bin/sh -c to interpret the pipe
305+ cmd := exec .Command ("/bin/sh" , "-c" , cmdString )
306+
307+ // Run the command and capture its standard output
308+ output , err := cmd .Output ()
309+ if err != nil {
310+ // Handle potential errors, e.g., command not found, permission issues, non-zero exit code
311+ if exitErr , ok := err .(* exec.ExitError ); ok {
312+ fmt .Printf ("Error: Command exited with non-zero status: %d\n " , exitErr .ExitCode ())
313+ fmt .Printf ("Stderr: %s\n " , exitErr .Stderr )
314+ } else {
315+ fmt .Printf ("Error: Failed to execute command: %v\n " , err )
316+ }
317+ return "" // Return an empty string on error
318+ }
319+
320+ // Convert the output (byte slice) to a string and trim whitespace
321+ versionString := strings .TrimSpace (string (output ))
322+ return versionString
323+ }
324+
325+ func UbuntuReleaseGreater (release string ) bool {
326+ currentReleaseStr := GetUbuntuRelease ()
327+ if currentReleaseStr == "" {
328+ fmt .Println ("Could not get current Ubuntu release for comparison." )
329+ return false
330+ }
331+
332+ currentRelease , err := strconv .ParseFloat (currentReleaseStr , 64 )
333+ if err != nil {
334+ fmt .Printf ("Error parsing current Ubuntu release '%s' to float: %v\n " , currentReleaseStr , err )
335+ return false
336+ }
337+
338+ compareRelease , err := strconv .ParseFloat (release , 64 )
339+ if err != nil {
340+ fmt .Printf ("Error parsing provided release '%s' to float: %v\n " , release , err )
341+ return false
342+ }
343+
344+ return currentRelease > compareRelease
345+ }
0 commit comments