2023-08-13 14:20:55 +00:00
|
|
|
package main
|
|
|
|
|
2023-08-13 15:59:05 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"flag"
|
|
|
|
"io/fs"
|
|
|
|
|
|
|
|
"git.faercol.me/faercol/http-boot-config/config/logger"
|
|
|
|
"git.faercol.me/faercol/http-boot-config/config/prober"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cliArgs struct {
|
|
|
|
debug bool
|
|
|
|
colour bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseArgs() cliArgs {
|
|
|
|
debugFlag := flag.Bool("debug", false, "Display debug logs")
|
|
|
|
noColourFlag := flag.Bool("no-colour", false, "Disable colour logs")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
return cliArgs{
|
|
|
|
debug: *debugFlag,
|
|
|
|
colour: !*noColourFlag,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func displayAppList(apps []prober.EfiApp, l *logger.SimpleLogger) {
|
|
|
|
l.Info("Found the following EFI applications:")
|
|
|
|
for _, a := range apps {
|
|
|
|
prefix := " "
|
|
|
|
if a.Active {
|
|
|
|
prefix = "*"
|
|
|
|
}
|
|
|
|
l.Infof("\t- %s[%d] %s: %s", prefix, a.ID, a.Name, a.Path)
|
|
|
|
}
|
|
|
|
}
|
2023-08-13 14:20:55 +00:00
|
|
|
|
|
|
|
func main() {
|
2023-08-13 15:59:05 +00:00
|
|
|
args := parseArgs()
|
|
|
|
l := logger.New(args.colour, args.debug)
|
2023-08-13 14:20:55 +00:00
|
|
|
|
2023-08-13 15:59:05 +00:00
|
|
|
l.Info("Checking EFI directory for available boot images...")
|
|
|
|
images, err := prober.GetEFIApps(l)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, fs.ErrPermission) {
|
|
|
|
l.Fatal("Permission error, try to run the command as sudo")
|
|
|
|
}
|
|
|
|
l.Fatalf("Failed to check EFI directory: %s", err.Error())
|
|
|
|
}
|
2023-08-13 14:20:55 +00:00
|
|
|
|
2023-08-13 15:59:05 +00:00
|
|
|
displayAppList(images, l)
|
2023-08-13 14:20:55 +00:00
|
|
|
}
|