-
Notifications
You must be signed in to change notification settings - Fork 8
/
packages.go
45 lines (35 loc) · 876 Bytes
/
packages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/reconquest/executil-go"
)
func installPackages(target string, packages []string) error {
args := []string{"-c", "-d", target}
command := exec.Command("pacstrap", append(args, packages...)...)
command.Stdout = os.Stderr
command.Stderr = os.Stderr
_, _, err := executil.Run(
command,
executil.IgnoreStderr,
executil.IgnoreStdout,
)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(target, ".packages"), []byte(
strings.Join(packages, "\n"),
), 0644)
return err
}
func listExplicitlyInstalled(baseDir string) ([]string, error) {
rawPackages, err := ioutil.ReadFile(filepath.Join(baseDir, ".packages"))
if err != nil {
return nil, err
}
packages := strings.Split(strings.TrimSpace(string(rawPackages)), "\n")
return packages, nil
}