sparkles: Auto-detect device with 'auto'

This commit is contained in:
Ettore Di Giacinto
2022-09-10 13:01:24 +00:00
committed by Itxaka
parent d7e6e9efa4
commit 0763c820f2
2 changed files with 21 additions and 0 deletions

View File

@@ -197,6 +197,10 @@ func RunInstall(options map[string]string) error {
os.Exit(1) os.Exit(1)
} }
if device == "auto" {
device = detectDevice()
}
cloudInit, ok := options["cc"] cloudInit, ok := options["cc"]
if !ok { if !ok {
fmt.Println("cloudInit must be specified among options") fmt.Println("cloudInit must be specified among options")

View File

@@ -110,6 +110,23 @@ func promptToUnstructured(p events.YAMLPrompt, unstructuredYAML map[string]inter
return unstructuredYAML, nil return unstructuredYAML, nil
} }
func detectDevice() string {
preferedDevice := "/dev/sda"
maxSize := float64(0)
block, err := ghw.Block()
if err == nil {
for _, disk := range block.Disks {
size := float64(disk.SizeBytes) / float64(GiB)
if size > maxSize {
maxSize = size
preferedDevice = "/dev/" + disk.Name
}
}
}
return preferedDevice
}
func InteractiveInstall(spawnShell bool) error { func InteractiveInstall(spawnShell bool) error {
bus.Manager.Initialize() bus.Manager.Initialize()