Skip to content

Commit

Permalink
feat: add check for running in EFI environment
Browse files Browse the repository at this point in the history
resolves #3
  • Loading branch information
nkraetzschmar committed Nov 22, 2024
1 parent 23e513f commit e6c7aef
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ func getCname(path string) (string, string, error) {
return cname, version, nil
}

func checkEFI(expected_loader_entry string) error {
_, err := os.Stat("sys/firmware/efi")
if err != nil {
return errors.New("not EFI booted")
}

data, err := os.ReadFile("/sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f")
if err != nil {
return errors.New("not booted with systemd EFI stub")
}

if string(data[4:]) == expected_loader_entry {
return nil
} else {
return errors.New("booted entry does not match expected value")
}
}

func getManifest(repo *remote.Repository, ctx context.Context, ref string) (map[string]interface{}, error) {
manifest_descriptor, err := repo.Resolve(ctx, ref)
if err != nil {
Expand Down Expand Up @@ -261,6 +279,7 @@ func main() {
media_type := flag.String("media-type", "application/io.gardenlinux.uki", "artifact media type to fetch")
target_dir := flag.String("target-dir", "/efi/EFI/Linux", "directory to write artifacts to")
os_release_path := flag.String("os-release", "/etc/os-release", "alternative path where the os-release file is read from")
skip_efi_check := flag.Bool("skip-efi-check", false, "skip performing EFI safety checks")

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] <version>\n", os.Args[0])
Expand All @@ -279,6 +298,13 @@ func main() {
panic(err)
}

if !*skip_efi_check {
err = checkEFI(cname + "-" + current_version + ".efi")
if err != nil {
panic(err)
}
}

ctx := context.Background()

repo, err := remote.NewRepository(*repo_url)
Expand Down

0 comments on commit e6c7aef

Please sign in to comment.