@@ -71,6 +71,9 @@ const (
7171 genericCPUFlagsTag = "flags" // nolint: varcheck, unused, deadcode
7272 genericCPUVendorField = "vendor_id" // nolint: varcheck, unused, deadcode
7373 genericCPUModelField = "model name" // nolint: varcheck, unused, deadcode
74+
75+ // If set, do not perform any network checks
76+ noNetworkEnvVar = "KATA_CHECK_NO_NETWORK"
7477)
7578
7679// variables rather than consts to allow tests to modify them
@@ -307,14 +310,71 @@ var kataCheckCLICommand = cli.Command{
307310 Usage : "tests if system can run " + project ,
308311 Flags : []cli.Flag {
309312 cli.BoolFlag {
310- Name : "verbose, v" ,
311- Usage : "display the list of checks performed" ,
313+ Name : "check-version-only" ,
314+ Usage : "Only compare the current and latest available versions (requires network, non-root only)" ,
315+ },
316+ cli.BoolFlag {
317+ Name : "include-all-releases" ,
318+ Usage : "Don't filter out pre-release release versions" ,
319+ },
320+ cli.BoolFlag {
321+ Name : "no-network-checks, n" ,
322+ Usage : "Do not run any checks using the network" ,
323+ },
324+ cli.BoolFlag {
325+ Name : "only-list-releases" ,
326+ Usage : "Only list newer available releases (non-root only)" ,
312327 },
313328 cli.BoolFlag {
314329 Name : "strict, s" ,
315330 Usage : "perform strict checking" ,
316331 },
332+ cli.BoolFlag {
333+ Name : "verbose, v" ,
334+ Usage : "display the list of checks performed" ,
335+ },
317336 },
337+ Description : fmt .Sprintf (`tests if system can run %s and version is current.
338+
339+ ENVIRONMENT VARIABLES:
340+
341+ - %s: If set to any value, act as if "--no-network-checks" was specified.
342+
343+ EXAMPLES:
344+
345+ - Perform basic checks:
346+
347+ $ %s %s
348+
349+ - Local basic checks only:
350+
351+ $ %s %s --no-network-checks
352+
353+ - Perform further checks:
354+
355+ $ sudo %s %s
356+
357+ - Just check if a newer version is available:
358+
359+ $ %s %s --check-version-only
360+
361+ - List available releases (shows output in format "version;release-date;url"):
362+
363+ $ %s %s --only-list-releases
364+
365+ - List all available releases (includes pre-release versions):
366+
367+ $ %s %s --only-list-releases --include-all-releases
368+ ` ,
369+ project ,
370+ noNetworkEnvVar ,
371+ name , checkCmd ,
372+ name , checkCmd ,
373+ name , checkCmd ,
374+ name , checkCmd ,
375+ name , checkCmd ,
376+ name , checkCmd ,
377+ ),
318378
319379 Action : func (context * cli.Context ) error {
320380 verbose := context .Bool ("verbose" )
@@ -329,6 +389,28 @@ var kataCheckCLICommand = cli.Command{
329389 span , _ := katautils .Trace (ctx , "kata-check" )
330390 defer span .Finish ()
331391
392+ if ! context .Bool ("no-network-checks" ) && os .Getenv (noNetworkEnvVar ) == "" {
393+ cmd := RelCmdCheck
394+
395+ if context .Bool ("only-list-releases" ) {
396+ cmd = RelCmdList
397+ }
398+
399+ if os .Geteuid () == 0 {
400+ kataLog .Warn ("Not running network checks as super user" )
401+ } else {
402+
403+ err = HandleReleaseVersions (cmd , version , context .Bool ("include-all-releases" ))
404+ if err != nil {
405+ return err
406+ }
407+ }
408+ }
409+
410+ if context .Bool ("check-version-only" ) || context .Bool ("only-list-releases" ) {
411+ return nil
412+ }
413+
332414 runtimeConfig , ok := context .App .Metadata ["runtimeConfig" ].(oci.RuntimeConfig )
333415 if ! ok {
334416 return errors .New ("kata-check: cannot determine runtime config" )
0 commit comments