github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/tools/vpdbootmanager/main.go (about) 1 // Copyright 2017-2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "os" 10 ) 11 12 func getUsage(progname string) string { 13 return fmt.Sprintf(`Usage: 14 %s add [netboot [dhcpv6|dhcpv4] [MAC] | localboot [grub|path [Device GUID] [Kernel Path]]] 15 %s get [variable name] 16 %s set [variable name] [variable value] 17 %s delete [variable name] 18 %s dump 19 20 Ex. 21 add localboot grub 22 add netboot dhcpv6 AA:BB:CC:DD:EE:FF 23 get 24 get firmware_version 25 set systemboot_log_level 6 26 delete systemboot_log_level 27 28 Flags for netboot: 29 30 -override-url - an optional URL used to override the boot file URL used 31 -retries - the number of times a DHCP request should be retried if failed 32 33 Flags for localboot: 34 35 -kernel-args - additional kernel args 36 -ramfs - path of ramfs to be used for kexec'ing into the target kernel 37 38 Global flags: 39 40 -vpd-dir - VPD dir to use 41 42 `, progname, progname, progname, progname, progname) 43 } 44 45 func main() { 46 if err := cli(os.Args[1:]); err != nil { 47 fmt.Println(getUsage(os.Args[0])) 48 fmt.Printf("Error: %s\n\n", err) 49 os.Exit(1) 50 } 51 } 52 53 func cli(args []string) error { 54 if len(args) < 1 { 55 return fmt.Errorf("you need to provide action") 56 } 57 switch args[0] { 58 case "add": 59 return add(args[1], args[2:]) 60 case "get": 61 varname := "" 62 if len(args) > 1 { 63 varname = args[1] 64 } 65 getter := NewGetter() 66 return getter.Print(varname) 67 case "set": 68 if len(args) == 3 { 69 err := set(args[1], args[2]) 70 if err == nil { 71 fmt.Println("Successfully set, it will take effect after reboot") 72 } 73 return err 74 } 75 case "delete": 76 if len(args) == 2 { 77 err := delete(args[1]) 78 if err == nil { 79 fmt.Println("Successfully deleted, it will take effect after reboot") 80 } 81 return err 82 } 83 case "dump": 84 return dump() 85 } 86 return fmt.Errorf("Unrecognized action") 87 }