Compare commits

...

1 commit
main ... dev

Author SHA1 Message Date
32bbd956f5 tmp to fixup for main 2023-09-01 18:45:22 +02:00
5 changed files with 26 additions and 30 deletions

View file

@ -5,4 +5,4 @@ build:
go build -o build/
push-client:
scp build/config root@192.168.122.2:/usr/bin/efi-http-config
scp build/config root@192.168.122.76:/usr/bin/efi-http-config

View file

@ -154,7 +154,7 @@ func displayAppList(l *logger.SimpleLogger) {
if a.Active {
prefix = "*"
}
l.Infof("\t- %s[%d] %s: %s (disk id %s)", prefix, a.ID, a.Name, a.Path, a.DiskID)
l.Infof("\t- %s[%d] %s: %s", prefix, a.ID, a.Name, a.DevicePath)
}
}

View file

@ -10,7 +10,8 @@ import (
"strings"
)
var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P<id>[0-9A-F]+)\* (?P<name>.+)\t(.+\(.+,.+,(?P<disk_id>[0-9a-f-]+),.+,.+\))/File\((?P<filepath>.+)\)`)
// var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P<id>[0-9A-F]+)\* (?P<name>.+)\t(.+\(.+,.+,(?P<disk_id>[0-9a-f-]+),.+,.+\))/File\((?P<filepath>.+)\)`)
var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P<id>[0-9A-F]+)\* (?P<name>.+)\t(?P<device_path>.+\))`)
var activeRegexp = regexp.MustCompile(`BootCurrent: (\d+)`)
var bootOrderRegexp = regexp.MustCompile(`BootOrder: ((?:[0-9A-F]{4},?)+)`)
@ -19,11 +20,10 @@ const HTTPBootLabel = "HTTP_BOOT"
const execPath = "/usr/bin/efibootmgr"
type EfiApp struct {
ID int
Name string
Path string
DiskID string
Active bool
ID int
Name string
DevicePath string
Active bool
}
func efiAppFromBootMgrOutput(rawVal string, activeId int) (app EfiApp, ok bool) {
@ -49,20 +49,15 @@ func efiAppFromBootMgrOutput(rawVal string, activeId int) (app EfiApp, ok bool)
if !ok {
return
}
filepath, ok := result["filepath"]
if !ok {
return
}
disk_id, ok := result["disk_id"]
devicePath, ok := result["device_path"]
if !ok {
return
}
return EfiApp{
ID: int(idInt),
Name: strings.TrimSpace(name),
Path: strings.TrimSpace(filepath),
Active: int(idInt) == activeId,
DiskID: disk_id,
ID: int(idInt),
Name: strings.TrimSpace(name),
DevicePath: strings.TrimSpace(devicePath),
Active: int(idInt) == activeId,
}, true
}

View file

@ -10,7 +10,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - Windows", func(t *testing.T) {
rawVal := (`Boot0000* Windows Boot Manager HD(1,GPT,4ad714ba-6a01-4f76-90e3-1bb93a59b67e,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)` +
`57494e444f5753000100000088000000780000004200430044004f0042004a004500430054003d007b00390064006500610038003600320063002d0035006300640064002d00`)
expected := EfiApp{ID: 0, Name: "Windows Boot Manager", Path: `\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI`, Active: true, DiskID: "4ad714ba-6a01-4f76-90e3-1bb93a59b67e"}
expected := EfiApp{ID: 0, Name: "Windows Boot Manager", DevicePath: `HD(1,GPT,4ad714ba-6a01-4f76-90e3-1bb93a59b67e,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)`, Active: true}
app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok)
assert.Equal(t, expected, app)
@ -18,7 +18,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - Manjaro", func(t *testing.T) {
rawVal := `Boot0001* Manjaro HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\MANJARO\GRUBX64.EFI)`
expected := EfiApp{ID: 1, Name: "Manjaro", Path: `\EFI\MANJARO\GRUBX64.EFI`, Active: false, DiskID: "16f06d01-50da-6544-86bd-f3457f980086"}
expected := EfiApp{ID: 1, Name: "Manjaro", DevicePath: `HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\MANJARO\GRUBX64.EFI)`, Active: false}
app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok)
assert.Equal(t, expected, app)
@ -26,7 +26,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - SystemdBoot VM", func(t *testing.T) {
rawVal := `Boot0001* SYSTEMD_BOOT PciRoot(0x0)/Pci(0x1f,0x2)/Sata(0,65535,0)/HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\systemd\systemd-bootx64.efi)`
expected := EfiApp{ID: 1, Name: "SYSTEMD_BOOT", Path: `\EFI\systemd\systemd-bootx64.efi`, Active: false, DiskID: "c4540877-4592-494f-bd8a-2a23abb22c3f"}
expected := EfiApp{ID: 1, Name: "SYSTEMD_BOOT", DevicePath: `PciRoot(0x0)/Pci(0x1f,0x2)/Sata(0,65535,0)/HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\systemd\systemd-bootx64.efi)`, Active: false}
app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok)
assert.Equal(t, expected, app)
@ -34,7 +34,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - HTTP_BOOT hexa", func(t *testing.T) {
rawVal := `Boot000A* httpboot.efi HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\httpboot\httpboot.efi)`
expected := EfiApp{ID: 10, Name: "httpboot.efi", Path: `\EFI\httpboot\httpboot.efi`, Active: false, DiskID: "c4540877-4592-494f-bd8a-2a23abb22c3f"}
expected := EfiApp{ID: 10, Name: "httpboot.efi", DevicePath: `HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\httpboot\httpboot.efi)`, Active: false}
app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok)
assert.Equal(t, expected, app)
@ -42,16 +42,18 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - EFI Base", func(t *testing.T) {
rawVal := `Boot0002* UEFI OS HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\BOOT\BOOTX64.EFI)0000424f`
expected := EfiApp{ID: 2, Name: "UEFI OS", Path: `\EFI\BOOT\BOOTX64.EFI`, Active: false, DiskID: "16f06d01-50da-6544-86bd-f3457f980086"}
expected := EfiApp{ID: 2, Name: "UEFI OS", DevicePath: `HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\BOOT\BOOTX64.EFI)`, Active: false}
app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok)
assert.Equal(t, expected, app)
})
t.Run("NOK - CD", func(t *testing.T) {
t.Run("OK - CD", func(t *testing.T) {
rawVal := `Boot0003* UEFI:CD/DVD Drive BBS(129,,0x0)`
_, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.False(t, ok)
expected := EfiApp{ID: 3, Name: "UEFI:CD/DVD Drive", DevicePath: `BBS(129,,0x0)`, Active: false}
app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok)
assert.Equal(t, expected, app)
})
t.Run("NOK - Other line", func(t *testing.T) {

View file

@ -17,9 +17,8 @@ import (
const enrollURL = "/enroll"
type enrollEFIOption struct {
Name string `json:"name"`
Path string `json:"path"`
DiskID string `json:"disk_id"`
Name string `json:"name"`
DevicePath string `json:"device_path"`
}
type enrollPayload struct {
@ -47,7 +46,7 @@ func enrollToServer(ctx context.Context, host string, name string, apps []prober
}
for _, a := range apps {
appID := uuid.New()
payload.Options[appID.String()] = enrollEFIOption{Name: a.Name, Path: a.Path, DiskID: a.DiskID}
payload.Options[appID.String()] = enrollEFIOption{Name: a.Name, DevicePath: a.DevicePath}
if a.Active {
payload.SelectedOption = appID.String()
}