Skip to content

Commit 669a72e

Browse files
committed
Update: Add profile reader
1 parent 08818c3 commit 669a72e

9 files changed

Lines changed: 81 additions & 26 deletions

File tree

alteriso5/cmd/build/cmd.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package build
22

33
import (
4-
"fmt"
54
"os"
65
"path"
76

@@ -16,11 +15,12 @@ func Cmd() *cobra.Command {
1615
cmd := cobra.Command{
1716
Use: "build",
1817
Short: "Build an ISO image",
18+
Args: cobra.ExactArgs(1),
1919
RunE: func(cmd *cobra.Command, args []string) error {
2020

2121
// Handle signals
2222
utils.OnSignal(func(s os.Signal) {
23-
fmt.Println("Received signal:", s)
23+
cmd.Println("Received signal:", s)
2424
os.Exit(1)
2525
}, os.Interrupt)
2626

@@ -44,15 +44,14 @@ func Cmd() *cobra.Command {
4444
}
4545

4646
// Dummy profile
47-
profile := config.Profile{
48-
Base: path.Join(current, "profile"),
49-
InstallDir: "alter",
50-
BootModes: []string{"SysLinux"},
47+
profile, err := config.ReadProfile(args[0])
48+
if err != nil {
49+
return err
5150
}
5251

5352
// TODO: Add more targets
5453
target := config.NewTarget("x86_64", outDir)
55-
return work.Build(profile, target, cmd)
54+
return work.Build(*profile, target, cmd)
5655

5756
},
5857
}
Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
package config
22

3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
"path"
8+
)
9+
310
type Profile struct {
411
Base string
5-
InstallDir string
6-
BootModes []string
12+
InstallDir string `json:"install_dir"`
13+
BootModes []string `json:"bootmodes"`
14+
ISOName string `json:"iso_name"`
15+
ISOLabel string `json:"iso_label"`
716
}
817

9-
func ReadProfile(path string) (Profile, error) {
10-
return Profile{}, nil
18+
func ReadProfile(dir string) (*Profile, error) {
19+
20+
data, err := os.ReadFile(path.Join(dir, "profiledef.json"))
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
new := Profile{
26+
Base: dir,
27+
}
28+
29+
if err := json.Unmarshal(data, &new); err != nil {
30+
return nil, err
31+
}
32+
33+
fmt.Println(new)
34+
35+
return &new, nil
1136
}

alteriso5/cmd/build/work/boot/xorriso-syslinux.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
// SysLinux MBR El Torito
88
func (o *xorriso) SetArgsForSysLinuxElTorito() {
99
arg := xorrisoArg{
10-
name: "SysLinuxEltorito",
10+
name: "SysLinuxEltorito",
11+
bootMode: "SysLinux",
1112
}
1213

1314
arg.add("-eltorito-boot", "boot/syslinux/isolinux.bin")
@@ -20,7 +21,8 @@ func (o *xorriso) SetArgsForSysLinuxElTorito() {
2021
func (o *xorriso) SetArgsForSysLinuxMBRBios() {
2122

2223
arg := xorrisoArg{
23-
name: "SysLinuxMBRBios",
24+
name: "SysLinuxMBRBios",
25+
bootMode: "SysLinux",
2426
}
2527

2628
arg.add("-isohybrid-mbr", path.Join(o.fsDir, "boot", "syslinux", "isohqpfx.bin"))
@@ -30,3 +32,8 @@ func (o *xorriso) SetArgsForSysLinuxMBRBios() {
3032
o.addArg(&arg)
3133

3234
}
35+
36+
func init() {
37+
Xorriso.SetArgsForSysLinuxElTorito()
38+
Xorriso.SetArgsForSysLinuxMBRBios()
39+
}

alteriso5/cmd/build/work/boot/xorriso.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"os/exec"
77
"path"
8+
"slices"
89
)
910

1011
var Xorriso = xorriso{}
@@ -16,8 +17,9 @@ type xorriso struct {
1617
}
1718

1819
type xorrisoArg struct {
19-
name string
20-
args *[]string
20+
name string
21+
bootMode string
22+
args *[]string
2123
}
2224

2325
func (xa *xorrisoArg) add(args ...string) {
@@ -65,22 +67,24 @@ func (o *xorriso) preArgs() *xorrisoArg {
6567
}
6668
}
6769

68-
func (x *xorriso) Args() *[]string {
70+
func (x *xorriso) Args(bootmode ...string) *[]string {
6971
args := []string{}
7072
pre := x.preArgs()
7173
args = append(args, *pre.args...)
7274
for _, a := range x.args {
73-
args = append(args, *a.args...)
75+
if slices.Contains(bootmode, a.bootMode) {
76+
args = append(args, *a.args...)
77+
}
7478
}
7579

7680
return &args
7781
}
7882

79-
func (x *xorriso) Build(dir string, out string) error {
83+
func (x *xorriso) Build(dir string, out string, bootmode ...string) error {
8084
x.fsDir = dir
8185
x.out = out
8286

83-
args := x.Args()
87+
args := x.Args(bootmode...)
8488

8589
cmd := exec.Command("xorriso", *args...)
8690
cmd.Stdout = os.Stdout

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

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

10+
// SysLinux
1011
var makeSysLinux = NewBuildTask("makeSysLinux", func(w Work) error {
1112

1213
slog.Debug("Setting up SYSLINUX for BIOS booting from a disk...")
@@ -68,6 +69,7 @@ var makeSysLinux = NewBuildTask("makeSysLinux", func(w Work) error {
6869
return nil
6970
})
7071

72+
// Run each bootmodes
7173
var makeBootModes *BuildTask = NewBuildTask("makeBootModes", func(w Work) error {
7274
return w.RunOnce(makeSysLinux)
7375
})

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

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

33
import (
4+
"log/slog"
5+
"path"
6+
47
"github.com/FascodeNet/alterlinux/alteriso5/utils"
8+
cp "github.com/otiai10/copy"
59
)
610

711
var makeBaseDirs *BuildTask = NewBuildTask("makeBaseDirs",
@@ -18,6 +22,20 @@ var makeBaseDirs *BuildTask = NewBuildTask("makeBaseDirs",
1822
return nil
1923
})
2024

25+
var makeCustomAirootfs *BuildTask = NewBuildTask("makeCustomAirootfs", func(w Work) error {
26+
slog.Info("Copying custom airootfs files...")
27+
profileAirootfsDir := path.Join(w.profile.Base, "airootfs")
28+
29+
if err := cp.Copy(profileAirootfsDir, w.GetDirs().Pacstrap, cp.Options{
30+
PreserveOwner: true,
31+
Sync: true,
32+
}); err != nil {
33+
return err
34+
}
35+
36+
return nil
37+
})
38+
2139
var makeChroot *BuildTask = NewBuildTask("makeChroot", func(work Work) error {
2240

2341
env, err := work.GetChroot()

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@ package work
33
import "github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/boot"
44

55
var makeOutFiles *BuildTask = NewBuildTask("makeOutFiles", func(w Work) error {
6-
boot.Xorriso.SetArgsForSysLinuxElTorito()
7-
boot.Xorriso.SetArgsForSysLinuxElTorito()
8-
9-
return boot.Xorriso.Build(w.GetDirs().Iso, w.target.Out)
6+
return boot.Xorriso.Build(w.GetDirs().Iso, w.target.Out, w.profile.BootModes...)
107
})

build.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3-
4-
script_path=$(cd "$(dirname "${0}")" || exit 1; pwd)
5-
go run "${script_path}/alteriso5/main.go" "$@"
3+
script_path=$(
4+
cd "$(dirname "${0}")" || exit 1
5+
pwd
6+
)
7+
go run "${script_path}/alteriso5/main.go" build "$script_path/profile"

profile/profiledef.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"install_dir": "alter",
23
"bootmodes": ["SysLinux"]
34
}

0 commit comments

Comments
 (0)