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