From 475a4441296c62db275ac64cb90afc781a78a700 Mon Sep 17 00:00:00 2001 From: Melora Hugues Date: Sat, 19 Aug 2023 10:54:18 +0200 Subject: [PATCH] add disk id to config --- config/main.go | 4 ++-- config/prober/prober.go | 8 +++++++- config/prober/prober_test.go | 6 +++--- config/remote/enroll.go | 7 ++++--- config/remote/remote.go | 7 ++++--- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/config/main.go b/config/main.go index d1748c8..92a3a4c 100644 --- a/config/main.go +++ b/config/main.go @@ -114,13 +114,13 @@ func displayAppList(l *logger.SimpleLogger) { if a.Active { prefix = "*" } - l.Infof("\t- %s[%d] %s: %s", prefix, a.ID, a.Name, a.Path) + l.Infof("\t- %s[%d] %s: %s (disk id %s)", prefix, a.ID, a.Name, a.Path, a.DiskID) } } func getRemoteConfig(l *logger.SimpleLogger, host string, id uuid.UUID, pretty bool) { - l.Info("Getting config from remote server...") if pretty { + l.Info("Getting config from remote server...") if err := remote.DisplayRemoteConfigPretty(context.Background(), host, id, l); err != nil { l.Fatal(err.Error()) } diff --git a/config/prober/prober.go b/config/prober/prober.go index bab5524..91c0baf 100644 --- a/config/prober/prober.go +++ b/config/prober/prober.go @@ -12,13 +12,14 @@ import ( "git.faercol.me/faercol/http-boot-config/config/logger" ) -var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P\d+)\* (?P[\w ]+)\t(\w+\(.*\))/File\((?P.+)\)`) +var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P\d+)\* (?P[\w ]+)\t(HD\(.+,.+,(?P[0-9a-f-]+),.+,.+\))/File\((?P.+)\)`) var activeRegexp = regexp.MustCompile(`BootCurrent: (\d+)`) type EfiApp struct { ID int Name string Path string + DiskID string Active bool } @@ -49,11 +50,16 @@ func efiAppFromBootMgrOutput(rawVal string, activeId int) (app EfiApp, ok bool) if !ok { return } + disk_id, ok := result["disk_id"] + if !ok { + return + } return EfiApp{ ID: idInt, Name: strings.TrimSpace(name), Path: strings.TrimSpace(filepath), Active: idInt == activeId, + DiskID: disk_id, }, true } diff --git a/config/prober/prober_test.go b/config/prober/prober_test.go index 7e4a97a..bba5daf 100644 --- a/config/prober/prober_test.go +++ b/config/prober/prober_test.go @@ -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} + expected := EfiApp{ID: 0, Name: "Windows Boot Manager", Path: `\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI`, Active: true, DiskID: "4ad714ba-6a01-4f76-90e3-1bb93a59b67e"} 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} + expected := EfiApp{ID: 1, Name: "Manjaro", Path: `\EFI\MANJARO\GRUBX64.EFI`, Active: false, DiskID: "16f06d01-50da-6544-86bd-f3457f980086"} 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 - 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} + expected := EfiApp{ID: 2, Name: "UEFI OS", Path: `\EFI\BOOT\BOOTX64.EFI`, Active: false, DiskID: "16f06d01-50da-6544-86bd-f3457f980086"} app, ok := efiAppFromBootMgrOutput(rawVal, 0) assert.True(t, ok) assert.Equal(t, expected, app) diff --git a/config/remote/enroll.go b/config/remote/enroll.go index 9267b6f..cb0b378 100644 --- a/config/remote/enroll.go +++ b/config/remote/enroll.go @@ -16,8 +16,9 @@ import ( const enrollURL = "/enroll" type enrollEFIOption struct { - Name string `json:"name"` - Path string `json:"path"` + Name string `json:"name"` + Path string `json:"path"` + DiskID string `json:"disk_id"` } type enrollPayload struct { @@ -37,7 +38,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} + payload.Options[appID.String()] = enrollEFIOption{Name: a.Name, Path: a.Path, DiskID: a.DiskID} if a.Active { payload.SelectedOption = appID.String() } diff --git a/config/remote/remote.go b/config/remote/remote.go index a22d196..46fc981 100644 --- a/config/remote/remote.go +++ b/config/remote/remote.go @@ -24,8 +24,9 @@ type clientConfig struct { ID string `json:"ID"` Name string `json:"name"` Options map[string]struct { - Name string `json:"name"` - Path string `json:"path"` + Name string `json:"name"` + Path string `json:"path"` + DiskID string `json:"disk_id"` } `json:"options"` SelectedOption string `json:"selected_option"` } `json:"efi_config"` @@ -103,7 +104,7 @@ func DisplayRemoteConfigPretty(ctx context.Context, host string, id uuid.UUID, l } l.Info(" * Available options are:") for _, option := range parsedConf.EFIConfig.Options { - l.Infof("\t - %s: %s", option.Name, option.Path) + l.Infof("\t - %s: %s (disk id %s)", option.Name, option.Path, option.DiskID) } l.Infof(" * Remote boot server is listening on %s:%d", parsedConf.NetConfig.MulticastGroup, parsedConf.NetConfig.Port)