Skip to content

Commit 68a57a8

Browse files
committed
Move: Subcommand structure
1 parent 68d4a7a commit 68a57a8

16 files changed

Lines changed: 192 additions & 44 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
work
1+
/work

alteriso5/cmd/build/build.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package build
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"os"
7+
"path"
8+
9+
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/config"
10+
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work"
11+
)
12+
13+
func check() error {
14+
if os.Getuid() != 0 {
15+
return errors.New("this program must be run as root")
16+
}
17+
return nil
18+
}
19+
20+
func build() error {
21+
current, err := os.Getwd()
22+
if err != nil {
23+
return err
24+
}
25+
26+
workDir := path.Join(current, "work")
27+
outDir := path.Join(current, "out")
28+
29+
work, err := work.New(workDir)
30+
if err != nil {
31+
return err
32+
}
33+
34+
profile := config.DummyProfile()
35+
target := config.NewTarget([]string{"x86_64"}, outDir)
36+
return work.Build(profile, target)
37+
}
38+
39+
func Main() {
40+
if err := check(); err != nil {
41+
fmt.Fprintln(os.Stderr, err)
42+
os.Exit(1)
43+
}
44+
45+
if err := build(); err != nil {
46+
fmt.Fprintln(os.Stderr, err)
47+
}
48+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package airootfs
2+
3+
type FileSystem interface {
4+
Init() error
5+
GetPath() (string, error)
6+
Mount(path string) error
7+
}
8+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package airootfs
2+
3+
func Get(name string) (FileSystem, error) {
4+
return SquashFS{}, nil
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package airootfs
2+
3+
type SquashFS struct {
4+
Path string
5+
}
6+
7+
func (s SquashFS) GetPath() (string, error) {
8+
return s.Path, nil
9+
}
10+
11+
func (s SquashFS) Init() error {
12+
return nil
13+
}
14+
15+
func (s SquashFS) Mount(path string) error {
16+
return nil
17+
}

alteriso5/cmd/build/work/build.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package work
2+
3+
import "github.com/FascodeNet/alterlinux/alteriso5/cmd/build/config"
4+
5+
func (work Work) Build(p config.Profile, t config.Target) error {
6+
7+
work.profile = &p
8+
work.target = &t
9+
10+
var tasks []BuildTask = []BuildTask{
11+
work.MakeBaseDirs,
12+
work.MakeChroot,
13+
}
14+
15+
for _, t := range tasks {
16+
err := t()
17+
if err != nil {
18+
return err
19+
}
20+
}
21+
22+
return nil
23+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package chroot
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
)
7+
8+
type Env struct {
9+
Arch string
10+
Dir string
11+
}
12+
13+
func New(dir, arch string) *Env {
14+
return &Env{
15+
Arch: arch,
16+
Dir: dir,
17+
}
18+
}
19+
20+
func (e *Env) Init() error {
21+
if err := os.MkdirAll(e.Dir, 0755); err != nil {
22+
return err
23+
}
24+
25+
pacstrap := exec.Command("pacstrap", "-c", e.Dir, "base", "base-devel", "linux", "linux-firmware")
26+
pacstrap.Env = append(os.Environ(), "LANG=C")
27+
pacstrap.Stdout = os.Stdout
28+
pacstrap.Stderr = os.Stderr
29+
if err := pacstrap.Run(); err != nil {
30+
return err
31+
}
32+
33+
return nil
34+
}

0 commit comments

Comments
 (0)