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/ go build -o build/
push-client: 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 { if a.Active {
prefix = "*" 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" "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 activeRegexp = regexp.MustCompile(`BootCurrent: (\d+)`)
var bootOrderRegexp = regexp.MustCompile(`BootOrder: ((?:[0-9A-F]{4},?)+)`) var bootOrderRegexp = regexp.MustCompile(`BootOrder: ((?:[0-9A-F]{4},?)+)`)
@ -21,8 +22,7 @@ const execPath = "/usr/bin/efibootmgr"
type EfiApp struct { type EfiApp struct {
ID int ID int
Name string Name string
Path string DevicePath string
DiskID string
Active bool Active bool
} }
@ -49,20 +49,15 @@ func efiAppFromBootMgrOutput(rawVal string, activeId int) (app EfiApp, ok bool)
if !ok { if !ok {
return return
} }
filepath, ok := result["filepath"] devicePath, ok := result["device_path"]
if !ok {
return
}
disk_id, ok := result["disk_id"]
if !ok { if !ok {
return return
} }
return EfiApp{ return EfiApp{
ID: int(idInt), ID: int(idInt),
Name: strings.TrimSpace(name), Name: strings.TrimSpace(name),
Path: strings.TrimSpace(filepath), DevicePath: strings.TrimSpace(devicePath),
Active: int(idInt) == activeId, Active: int(idInt) == activeId,
DiskID: disk_id,
}, true }, true
} }

View file

@ -10,7 +10,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - Windows", func(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)` + rawVal := (`Boot0000* Windows Boot Manager HD(1,GPT,4ad714ba-6a01-4f76-90e3-1bb93a59b67e,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)` +
`57494e444f5753000100000088000000780000004200430044004f0042004a004500430054003d007b00390064006500610038003600320063002d0035006300640064002d00`) `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) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -18,7 +18,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - Manjaro", func(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)` 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) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -26,7 +26,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - SystemdBoot VM", func(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)` 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) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -34,7 +34,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - HTTP_BOOT hexa", func(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)` 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) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -42,16 +42,18 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - EFI Base", func(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` 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) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) 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)` rawVal := `Boot0003* UEFI:CD/DVD Drive BBS(129,,0x0)`
_, ok := efiAppFromBootMgrOutput(rawVal, 0) expected := EfiApp{ID: 3, Name: "UEFI:CD/DVD Drive", DevicePath: `BBS(129,,0x0)`, Active: false}
assert.False(t, ok) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok)
assert.Equal(t, expected, app)
}) })
t.Run("NOK - Other line", func(t *testing.T) { t.Run("NOK - Other line", func(t *testing.T) {

View file

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