Skip to content

Commit 3b84669

Browse files
committed
Add: make efibootimg
1 parent c0b2a0e commit 3b84669

8 files changed

Lines changed: 60 additions & 33 deletions

File tree

alteriso5/cmd/build/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/FascodeNet/alterlinux/alteriso5/config"
99
"github.com/FascodeNet/alterlinux/alteriso5/utils"
1010
"github.com/FascodeNet/alterlinux/alteriso5/work"
11+
"github.com/Hayao0819/nahi/cobrautils"
1112
"github.com/spf13/cobra"
1213
)
1314

@@ -25,7 +26,7 @@ func Cmd() *cobra.Command {
2526
}, os.Interrupt)
2627

2728
// Check dependencies
28-
if err := utils.CallCmd(cmd, *check.Cmd()); err != nil {
29+
if err := cobrautils.CallCmd(cmd, *check.Cmd()); err != nil {
2930
return err
3031
}
3132

alteriso5/utils/cobra.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ package utils
22

33
import "github.com/spf13/cobra"
44

5-
func CallCmd(me *cobra.Command, target cobra.Command, args ...string) error {
6-
target.SetOut(me.OutOrStdout())
7-
target.SetErr(me.OutOrStderr())
8-
target.SetIn(me.InOrStdin())
9-
target.SetArgs(args)
10-
return target.Execute()
11-
}
5+
126

137
func WithParentPersistentPreRunE(f func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error {
148
return func(cmd *cobra.Command, args []string) error {

alteriso5/utils/dir.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

alteriso5/utils/exec.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package utils
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
)
7+
8+
func CommandWithStdio(cmd string, args ...string) *exec.Cmd {
9+
c := exec.Command(cmd, args...)
10+
c.Stdout = os.Stdout
11+
c.Stderr = os.Stderr
12+
c.Stdin = os.Stdin
13+
return c
14+
}

alteriso5/work/boot/efibootimg.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
package boot
22

3+
import (
4+
"fmt"
5+
"log/slog"
6+
7+
"github.com/FascodeNet/alterlinux/alteriso5/utils"
8+
)
9+
10+
func byteToKib(b int64) int64 {
11+
return b / 1024
12+
}
13+
14+
func mibToKiB(m int64) int64 {
15+
return m * 1024
16+
}
17+
318
// TODO: Implement MakeEfiBootImg
419
func MakeEfiBootImg(dest string, size int64) error {
20+
sizeMib := mibToKiB((byteToKib(size) + 1024) / 1024)
21+
slog.Debug("Creating EFI boot image...", "dest", dest, "size", sizeMib)
22+
23+
mkfs := utils.CommandWithStdio("mkfs.fat", "-C", "-n", "ALTERISO_EFI", dest, fmt.Sprint(sizeMib))
24+
if err := mkfs.Run(); err != nil {
25+
return err
26+
}
27+
28+
mmd := utils.CommandWithStdio("mmd", "-i", dest, "::/EFI", "::/EFI/BOOT")
29+
if err := mmd.Run(); err != nil {
30+
return err
31+
}
32+
533
return nil
634
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package work

alteriso5/work/task-bootmode-uefi.go renamed to alteriso5/work/task-bootmode-uefi-systemd.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
// Prepare configuration files for systemd-boot
14-
var makeCommonSystemdBootConfig *BuildTask = NewBuildTask("makeCommonSystemdBootConfig", func(w Work) error {
14+
var makeCommonSystemdBoot *BuildTask = NewBuildTask("makeCommonSystemdBoot", func(w Work) error {
1515
var total int64 = 0
1616
// TODO: Get ucode list
1717

@@ -86,8 +86,18 @@ var makeCommonSystemdBootConfig *BuildTask = NewBuildTask("makeCommonSystemdBoot
8686
return boot.MakeEfiBootImg(path.Join(w.Base, "efiboot.img"), total)
8787
})
8888

89-
var makeCommonSystemdBoot *BuildTask = NewBuildTask("makeCommonSystemdBoot", func(w Work) error {
89+
var makeCommonSystemdBootConfig *BuildTask = NewBuildTask("makeCommonSystemdBootConfig", func(w Work) error {
90+
workLoaderDir := path.Join(w.Base, w.target.Arch, "loader")
91+
if err := os.MkdirAll(path.Join(workLoaderDir, "entries"), 0755); err != nil {
92+
return err
93+
}
94+
95+
// cpTasks := utils.CopyTask{
96+
97+
// }
98+
9099
return nil
100+
91101
})
92102

93103
var makeUefiX64SystemdBootEsp *BuildTask = NewBuildTask("makeUefiX64SystemdBootEsp", func(w Work) error {

alteriso5/work/task-init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"log/slog"
55
"path"
66

7-
"github.com/FascodeNet/alterlinux/alteriso5/utils"
7+
"github.com/Hayao0819/nahi/osutils"
88
cp "github.com/otiai10/copy"
99
)
1010

@@ -16,7 +16,7 @@ var makeBaseDirs *BuildTask = NewBuildTask("makeBaseDirs",
1616
work.target.Out,
1717
}
1818

19-
if err := utils.MkdirsAll(dirs...); err != nil {
19+
if err := osutils.MkdirsAll(dirs...); err != nil {
2020
return err
2121
}
2222
return nil

0 commit comments

Comments
 (0)