Skip to content

Commit fa33943

Browse files
committed
Update: Rename chroot Env
1 parent 927d78e commit fa33943

7 files changed

Lines changed: 44 additions & 18 deletions

File tree

alteriso5/cmd/build/work/airootfs/chroot.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
"github.com/FascodeNet/alterlinux/alteriso5/utils"
1111
)
1212

13-
type Env struct {
13+
type Chroot struct {
1414
Arch string
1515
Dir string
1616
initilized bool
1717
}
1818

19-
func New(dir, arch string) (*Env, error) {
20-
env := Env{
19+
func GetChrootDir(dir, arch string) (*Chroot, error) {
20+
env := Chroot{
2121
Arch: arch,
2222
Dir: dir,
2323
}
@@ -35,7 +35,7 @@ func New(dir, arch string) (*Env, error) {
3535
return &env, nil
3636
}
3737

38-
func (e *Env) Init() error {
38+
func (e *Chroot) Init() error {
3939
if err := os.MkdirAll(e.Dir, 0755); err != nil {
4040
return err
4141
}
@@ -56,7 +56,7 @@ func (e *Env) Init() error {
5656
return nil
5757
}
5858

59-
func (e *Env) FindKernels() ([]string, error) {
59+
func (e *Chroot) FindKernels() ([]string, error) {
6060
kernels := []string{}
6161

6262
//bootDir := path.Join(e.Dir, "boot")

alteriso5/cmd/build/work/buildtask.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package work
22

33
type BuildTask struct {
44
name string
5-
task func(work *Work) error
5+
task func(work Work) error
66
}
77

8-
func NewBuildTask(name string, task func(*Work) error) *BuildTask {
8+
9+
func NewBuildTask(name string, task func(Work) error) *BuildTask {
910
return &BuildTask{
1011
name: name,
1112
task: task,
@@ -17,5 +18,5 @@ func (t *BuildTask) Name() string {
1718
}
1819

1920
func (t *BuildTask) Run(w *Work) error {
20-
return t.task(w)
21+
return t.task(*w)
2122
}

alteriso5/cmd/build/work/task-bootmodes.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/FascodeNet/alterlinux/alteriso5/utils"
88
)
99

10-
var makeSysLinux = NewBuildTask("makeSysLinux", func(w *Work) error {
10+
var makeSysLinux = NewBuildTask("makeSysLinux", func(w Work) error {
1111

1212
slog.Debug("Setting up SYSLINUX for BIOS booting from a disk...")
1313
dirs := w.GetDirs()
@@ -24,6 +24,7 @@ var makeSysLinux = NewBuildTask("makeSysLinux", func(w *Work) error {
2424
Source: biosFilesDir,
2525
Dest: isoSyslinuxDir,
2626
Skip: utils.OnlySpecificExtention(".c32"),
27+
Perm: 0644,
2728
},
2829
{
2930
Source: dirs.SyslinuxConfig,
@@ -39,14 +40,31 @@ var makeSysLinux = NewBuildTask("makeSysLinux", func(w *Work) error {
3940
},
4041
}
4142

43+
chroot, err := w.GetChroot()
44+
if err != nil {
45+
return err
46+
}
47+
kernels, err := chroot.FindKernels()
48+
if err != nil {
49+
return err
50+
}
51+
52+
for _, kernel := range kernels {
53+
cpFiles = append(cpFiles, utils.CopyTask{
54+
Source: kernel,
55+
Dest: path.Join(isoSyslinuxDir, path.Base(kernel)),
56+
Perm: 0644,
57+
})
58+
59+
}
60+
4261
if err := utils.CopyAll(cpFiles...); err != nil {
4362
return err
4463
}
4564

4665
return nil
4766
})
4867

49-
var makeBootModes *BuildTask = NewBuildTask("makeBootModes", func(w *Work) error {
50-
68+
var makeBootModes *BuildTask = NewBuildTask("makeBootModes", func(w Work) error {
5169
return w.RunOnce(makeSysLinux)
5270
})

alteriso5/cmd/build/work/task-init.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package work
22

33
import (
4-
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/airootfs"
54
"github.com/FascodeNet/alterlinux/alteriso5/utils"
65
)
76

87
var makeBaseDirs *BuildTask = NewBuildTask("makeBaseDirs",
9-
func(work *Work) error {
8+
func(work Work) error {
109

1110
dirs := []string{
1211
work.Base,
@@ -19,11 +18,12 @@ var makeBaseDirs *BuildTask = NewBuildTask("makeBaseDirs",
1918
return nil
2019
})
2120

22-
var makeChroot *BuildTask = NewBuildTask("makeChroot", func(work *Work) error {
21+
var makeChroot *BuildTask = NewBuildTask("makeChroot", func(work Work) error {
2322

24-
env, err := airootfs.New(work.GetDirs().Pacstrap, work.target.Arch)
23+
env, err := work.GetChroot()
2524
if err != nil {
2625
return err
26+
2727
}
2828
if err := env.Init(); err != nil {
2929
return err

alteriso5/cmd/build/work/task-outfiles.go

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

33
import "github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/boot"
44

5-
var makeOutFiles *BuildTask = NewBuildTask("makeOutFiles", func(w *Work) error {
6-
5+
var makeOutFiles *BuildTask = NewBuildTask("makeOutFiles", func(w Work) error {
76
boot.Xorriso.SetArgsForSysLinuxElTorito()
87
boot.Xorriso.SetArgsForSysLinuxElTorito()
98

alteriso5/cmd/build/work/tasks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/airootfs"
88
)
99

10-
var makeAirootfs *BuildTask = NewBuildTask("makeAirootfs", func(w *Work) error {
10+
var makeAirootfs *BuildTask = NewBuildTask("makeAirootfs", func(w Work) error {
1111

1212
slog.Debug("Copying profile to airootfs...")
1313
airootfsDir := path.Join(w.Base, w.target.Arch, "airootfs")

alteriso5/cmd/build/work/work.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package work
22

33
import (
4+
"log/slog"
45
"os"
56
"path"
67

78
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/config"
9+
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/airootfs"
810
"github.com/Hayao0819/nahi/osutils"
911
"github.com/spf13/cobra"
1012
)
@@ -38,9 +40,15 @@ func (w *Work) GetDirs() *dirs {
3840
}
3941
}
4042

43+
func (w *Work) GetChroot() (*airootfs.Chroot, error) {
44+
return airootfs.GetChrootDir(w.GetDirs().Pacstrap, w.target.Arch)
45+
46+
}
47+
4148
func (w *Work) RunOnce(task *BuildTask) error {
4249
lp := path.Join(w.Base, w.target.Arch, "lockfile", task.Name())
4350
if osutils.Exists(lp) {
51+
slog.Warn("This task has already runned", "name", task.Name())
4452
return nil
4553
}
4654

0 commit comments

Comments
 (0)