Skip to content

Commit 4f280c2

Browse files
committed
Add: Copy syslinux binary files
1 parent 259048e commit 4f280c2

4 files changed

Lines changed: 112 additions & 25 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package work
2+
3+
type BuildTask struct {
4+
name string
5+
task func(work *Work) error
6+
}
7+
8+
func NewBuildTask(name string, task func(*Work) error) *BuildTask {
9+
return &BuildTask{
10+
name: name,
11+
task: task,
12+
}
13+
}
14+
15+
func (t *BuildTask) Name() string {
16+
return t.name
17+
}
18+
19+
func (t *BuildTask) Run(w *Work) error {
20+
return t.task(w)
21+
}

alteriso5/cmd/build/work/tasks.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/boot"
99
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/chroot"
1010
"github.com/FascodeNet/alterlinux/alteriso5/utils"
11-
cp "github.com/otiai10/copy"
1211
)
1312

1413
var makeBaseDirs *BuildTask = NewBuildTask("makeBaseDirs",
@@ -41,16 +40,37 @@ var makeBootModes *BuildTask = NewBuildTask("makeBootModes", func(w *Work) error
4140
makeSysLinux := NewBuildTask("makeSysLinux", func(w *Work) error {
4241

4342
slog.Debug("Setting up SYSLINUX for BIOS booting from a disk...")
43+
dirs := w.GetDirs()
4444

45-
isoSyslinuxDir := path.Join(w.Base, "iso", "boot", "syslinux")
45+
isoSyslinuxDir := path.Join(dirs.Iso, "boot", "syslinux")
4646

47-
if err := utils.MkdirsAll(isoSyslinuxDir); err != nil {
47+
if err := utils.MkdirsAll(isoSyslinuxDir, dirs.SyslinuxConfig); err != nil {
4848
return err
4949
}
5050

51-
profileSysLinuxDir := path.Join(w.profile.Base, "syslinux")
5251

53-
if err := cp.Copy(profileSysLinuxDir, isoSyslinuxDir); err != nil {
52+
biosFilesDir := path.Join(dirs.Pacstrap, "usr", "lib", "syslinux", "bios")
53+
cpFiles := []utils.CopyTask{
54+
{
55+
Source: biosFilesDir,
56+
Dest: isoSyslinuxDir,
57+
Skip: utils.OnlySpecificExtention(".c32"),
58+
},
59+
{
60+
Source: dirs.SyslinuxConfig,
61+
Dest: isoSyslinuxDir,
62+
},
63+
{
64+
Source: path.Join(biosFilesDir, "lpxelinux.0"),
65+
Dest: path.Join(isoSyslinuxDir, "lpxelinux.0"),
66+
},
67+
{
68+
Source: path.Join(biosFilesDir, "memdisk"),
69+
Dest: path.Join(isoSyslinuxDir, "memdisk"),
70+
},
71+
}
72+
73+
if err := utils.CopyAll(cpFiles...); err != nil {
5474
return err
5575
}
5676

alteriso5/cmd/build/work/work.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
package work
22

33
import (
4+
"path"
5+
46
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/config"
57
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/chroot"
68
"github.com/spf13/cobra"
79
)
810

9-
type BuildTask struct {
10-
name string
11-
task func(work *Work) error
12-
}
13-
14-
func NewBuildTask(name string, task func(*Work) error) *BuildTask {
15-
return &BuildTask{
16-
name: name,
17-
task: task,
18-
}
19-
}
20-
21-
func (t *BuildTask) Name() string {
22-
return t.name
23-
}
24-
25-
func (t *BuildTask) Run(w *Work) error {
26-
return t.task(w)
27-
}
28-
2911
type Work struct {
3012
Base string
3113
Chroots []*chroot.Env
3214
profile *config.Profile
3315
target *config.Target
3416
Cmd *cobra.Command
3517
}
18+
19+
type dirs struct {
20+
Work string
21+
Pacstrap string
22+
Iso string
23+
SyslinuxConfig string
24+
}
25+
26+
func (w *Work) GetDirs() *dirs {
27+
return &dirs{
28+
Work: w.Base,
29+
Pacstrap: path.Join(w.Base, w.target.Arch, "airootfs"),
30+
Iso: path.Join(w.Base, "iso"),
31+
SyslinuxConfig: path.Join(w.profile.Base, "syslinux"),
32+
}
33+
}

alteriso5/utils/copy.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package utils
2+
3+
import (
4+
"io/fs"
5+
"os"
6+
"path/filepath"
7+
8+
cp "github.com/otiai10/copy"
9+
)
10+
11+
type CopyTask struct {
12+
Source string
13+
Dest string
14+
Perm fs.FileMode
15+
Skip func(srcinfo os.FileInfo, src, dest string) (bool, error) // Skipするファイルならtrueを返す
16+
}
17+
18+
func (c *CopyTask) Copy() error {
19+
20+
opt := cp.Options{}
21+
22+
if c.Perm != 0 {
23+
opt.PermissionControl = cp.AddPermission(c.Perm)
24+
}
25+
26+
return cp.Copy(c.Source, c.Dest, opt)
27+
}
28+
29+
func OnlySpecificExtention(ext string) func(srcinfo os.FileInfo, src, dest string) (bool, error) {
30+
return func(srcinfo os.FileInfo, src, dest string) (bool, error) {
31+
if srcinfo.IsDir() {
32+
return false, nil
33+
}
34+
if filepath.Ext(src) != ext {
35+
return true, nil
36+
}
37+
return false, nil
38+
}
39+
}
40+
41+
func CopyAll(tasks ...CopyTask) error {
42+
for _, task := range tasks {
43+
if err := task.Copy(); err != nil {
44+
return err
45+
}
46+
}
47+
return nil
48+
}

0 commit comments

Comments
 (0)