Skip to content

Commit 1efeaf2

Browse files
committed
Add: Add new BuildTask
1 parent 96eae3b commit 1efeaf2

8 files changed

Lines changed: 139 additions & 4 deletions

File tree

alteriso5/cmd/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AlterISO 5.0 Cmds
2+
3+
各サブコマンドが格納され、コマンドのエントリーポイントを提供します。
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
package airootfs
22

3+
import (
4+
"os"
5+
"os/exec"
6+
"path/filepath"
7+
)
8+
39
type SquashFS struct {
410
Base string
5-
Out string
11+
Out string
612
Args []string
713
}
814

15+
func (s *SquashFS) Build() error {
16+
args := append([]string{s.Base, s.Out}, s.Args...)
17+
18+
if err := os.MkdirAll(filepath.Dir(s.Out), 0755); err != nil {
19+
return err
20+
}
21+
22+
cmd := exec.Command("mksquashfs", args...)
23+
cmd.Stdin = os.Stdin
24+
cmd.Stdout = os.Stdout
25+
cmd.Stderr = os.Stderr
26+
27+
if err := cmd.Run(); err != nil {
28+
return err
29+
}
30+
return nil
31+
}

alteriso5/cmd/build/work/build.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ func (work Work) Build(p config.Profile, t config.Target) error {
99

1010
tasks := []*BuildTask{
1111
makeBaseDirs,
12-
//makeChroot,
12+
makeChroot,
1313
makeBootModes,
14+
makeAirootfs,
15+
makeBoot,
1416
}
1517

1618
for _, t := range tasks {

alteriso5/cmd/build/work/tasks.go

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

7+
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/airootfs"
78
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/chroot"
9+
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/xorriso"
810
"github.com/FascodeNet/alterlinux/alteriso5/utils"
911
cp "github.com/otiai10/copy"
1012
)
@@ -51,3 +53,30 @@ var makeBootModes *BuildTask = NewBuildTask("makeBootModes", func(w *Work) error
5153

5254
return nil
5355
})
56+
57+
var makeAirootfs *BuildTask = NewBuildTask("makeAirootfs", func(w *Work) error {
58+
59+
slog.Debug("Copying profile to airootfs...")
60+
airootfsDir := path.Join(w.Base, w.target.Arch, "airootfs")
61+
isoDir := path.Join(w.Base, "iso")
62+
63+
sqfs := airootfs.SquashFS{
64+
Base: airootfsDir,
65+
Out: path.Join(isoDir, w.profile.InstallDir, w.target.Arch, "airootfs.sfs"),
66+
}
67+
68+
return sqfs.Build()
69+
})
70+
71+
var makeBoot *BuildTask = NewBuildTask("makeBoot", func(w *Work) error {
72+
// TODO: ISO以外もサポートする
73+
74+
opt := xorriso.Options{
75+
SysLinux: true,
76+
}
77+
78+
isodir := path.Join(w.Base, "iso")
79+
80+
return xorriso.Build(isodir, w.target.Out, &opt)
81+
82+
})

alteriso5/cmd/build/work/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func (w *Work) RunOnce(task *BuildTask) error {
1717
return err
1818
} else {
1919
// Dont care about error
20+
os.MkdirAll(path.Dir(lp), 0755)
2021
os.Create(lp)
2122

2223
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package xorriso
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
"slices"
7+
)
8+
9+
type Options struct {
10+
SysLinux bool
11+
fsDir string
12+
out string
13+
args []string
14+
added []string
15+
}
16+
17+
func (o *Options) AddArgs(args ...string) {
18+
o.args = append(o.args, args...)
19+
}
20+
21+
// SysLinux MBR El Torito
22+
func (o *Options) setArgsForSysLinuxElTorito() {
23+
name := "SysLinuxEltorito"
24+
25+
if slices.Contains(o.added, name) {
26+
return
27+
}
28+
29+
o.AddArgs("-eltorito-boot", "boot/syslinux/isolinux.bin")
30+
o.AddArgs("-eltorito-catalog", "boot/syslinux/boot.cat")
31+
o.AddArgs("-no-emul-boot", "-boot-load-size", "4", "-boot-info-table")
32+
o.args = append(o.args, name)
33+
}
34+
35+
func (o *Options) setArgsForSysLinuxMBRBios() {
36+
name := "SysLinuxMBRBios"
37+
if slices.Contains(o.added, name) {
38+
return
39+
}
40+
o.AddArgs("-isohybrid-mbr", "${isofs_dir}/boot/syslinux/isohdpfx.bin")
41+
o.AddArgs("--mbr-force-bootable")
42+
o.AddArgs("-partition_offset", "16")
43+
o.added = append(o.added, name)
44+
}
45+
46+
func (o *Options) Args() []string {
47+
if o.SysLinux {
48+
o.setArgsForSysLinuxElTorito()
49+
o.setArgsForSysLinuxMBRBios()
50+
}
51+
52+
d := []string{
53+
"--output", o.out,
54+
o.fsDir,
55+
}
56+
57+
return append(d, o.args...)
58+
}
59+
60+
func Build(dir string, out string, opt *Options) error {
61+
opt.fsDir = dir
62+
opt.out = out
63+
64+
args := opt.Args()
65+
66+
cmd := exec.Command("xorriso", args...)
67+
cmd.Stdout = os.Stdout
68+
cmd.Stdin = os.Stdin
69+
cmd.Stderr = os.Stderr
70+
71+
return cmd.Run()
72+
}

alteriso5/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func Root() *cobra.Command {
99
root := cobra.Command{
1010
Use: "alteriso5",
1111
Short: "AlterISO5 is a tool to build Arch Linux live ISO images",
12+
SilenceUsage: true,
1213
}
1314

1415
cobrautils.AddSubCmdsToRoot(&root)

alteriso5/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package main
22

3-
import "github.com/FascodeNet/alterlinux/alteriso5/cmd"
3+
import (
4+
"os"
5+
6+
"github.com/FascodeNet/alterlinux/alteriso5/cmd"
7+
)
48

59
func main() {
610
root := cmd.Root()
711
if err := root.Execute(); err != nil {
8-
root.PrintErrln(err)
12+
os.Exit(1)
913
}
1014
}

0 commit comments

Comments
 (0)