-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.go
87 lines (80 loc) · 1.58 KB
/
operations.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"embed"
"fmt"
"io"
"io/fs"
"log"
"os"
"strings"
"github.com/fleshin/flechade/run"
git "gopkg.in/src-d/go-git.v4"
)
func showVersion() {
fmt.Println("flechade - customize your linux")
fmt.Println("Version:", run.GetVer())
fmt.Println("")
}
func runFromLocal(cfgFS embed.FS) {
targetDir := "/tmp/flechade-default"
err := os.MkdirAll(targetDir, os.ModePerm)
if err != nil {
log.Fatal("unable to create directory: ", targetDir)
}
fs.WalkDir(cfgFS, "data", func(path string, d fs.DirEntry, err error) error {
if err != nil {
log.Fatal(err)
}
if !d.IsDir() {
//fmt.Println(path)
last := strings.LastIndex(path, "/")
fname := path[last:]
dstFile, err := os.OpenFile(targetDir+fname, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer dstFile.Close()
cfgFile, err := cfgFS.Open(path)
if err != nil {
return err
}
defer cfgFile.Close()
_, err = io.Copy(dstFile, cfgFile)
if err != nil {
return err
}
}
return nil
})
runFromDir(targetDir)
}
func runFromDir(dataDir string) {
set, err := run.LoadSetFromDir(dataDir)
if err != nil {
log.Fatal(err)
}
set.Run()
fmt.Println("Setup complete. Enjoy!")
}
func runFromUrl(repoUrl string) {
tgtDir := "/tmp/flechade-repo"
err := os.RemoveAll(tgtDir)
if err != nil {
log.Fatal(err)
}
_, err = git.PlainClone(tgtDir, false, &git.CloneOptions{
URL: repoUrl,
})
if err != nil {
log.Fatal(err)
}
runFromDir(tgtDir)
}
func contPrevRun() {
set := new(run.Set)
err := set.Load()
if err != nil {
log.Fatal(err)
}
set.Run()
}