mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-21 11:46:37 +00:00
e8cb102819
Scans the USB EFI partition at boot for autoinstall.toml. When enabled = true, the installer runs fully unattended using values from the config file then ejects the USB and reboots — no user interaction needed. - New autoinstall package: TOML config struct, boot-media scanner, install.Config converter, EjectAndReboot - Scanner skips iso9660 mounts so the bundled reference copy of the template never accidentally triggers headless mode - "auto" disk target selects the largest non-removable disk - "auto" NIC target picks the first physical interface - Validates all required fields before touching any disk - main.go: check for autoinstall config before launching TUI
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
/*
|
|
Copyright © 2026 Mulga Defense Corporation
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/mulgadc/spinifex/cmd/installer/autoinstall"
|
|
"github.com/mulgadc/spinifex/cmd/installer/install"
|
|
"github.com/mulgadc/spinifex/cmd/installer/ui"
|
|
)
|
|
|
|
func main() {
|
|
// Check for a headless autoinstall config on the boot media before
|
|
// launching the interactive TUI. If found and enabled, run without
|
|
// any user input then eject the USB and reboot.
|
|
if cfg, err := autoinstall.Load(); err != nil {
|
|
fmt.Fprintf(os.Stderr, "autoinstall: %v\n", err)
|
|
os.Exit(1)
|
|
} else if cfg != nil {
|
|
if err := install.Run(cfg); err != nil {
|
|
fmt.Fprintf(os.Stderr, "install failed: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
autoinstall.EjectAndReboot()
|
|
return
|
|
}
|
|
|
|
// Normal interactive path.
|
|
ttyPath := detectTTY()
|
|
|
|
cfg, err := ui.Run(ttyPath)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "installer: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if err := install.Run(cfg); err != nil {
|
|
fmt.Fprintf(os.Stderr, "install failed: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
// detectTTY returns the TTY device path the installer should attach to.
|
|
// It reads SPINIFEX_CONSOLE from the kernel cmdline (/proc/cmdline) so that
|
|
// spinifex-init can direct the installer to the correct console (ttyS0 for
|
|
// serial, tty1 for VGA). Falls back to tty1.
|
|
func detectTTY() string {
|
|
data, err := os.ReadFile("/proc/cmdline")
|
|
if err == nil {
|
|
for param := range strings.FieldsSeq(string(data)) {
|
|
if after, ok := strings.CutPrefix(param, "SPINIFEX_CONSOLE="); ok {
|
|
val := after
|
|
if val != "" && val != "auto" {
|
|
return "/dev/" + val
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return "/dev/tty1"
|
|
}
|