1package dgrb
2
3import (
4 "fmt"
5 "git.sr.ht/~chld/dgr/cmd"
6 "os"
7 "path/filepath"
8 "strings"
9)
10
11func Inst(pkg string) {
12 dgr.Msg("installing \033[1;32m", pkg, "\033[m")
13 pkginst := filepath.Join("/var/tmp/dtr", "/pkg-"+pkg+"-*")
14 pk, _ := filepath.Glob(pkginst + "/*") // globbing final boss
15
16 if len(pk) == 0 {
17 dgr.Warn("no files to install in", pkginst)
18 return
19 }
20
21 // iterate over pki to stop symbolic link errors
22 for i := range len(pk) {
23 base := filepath.Base(pk[i])
24 dst := filepath.Join(os.Getenv("DTR_ROOT"), base)
25 pkb, _ := filepath.Glob(pk[i] + "/*")
26 for n := range len(pkb) {
27 fmt.Printf("\t%s\t", pkb[n])
28 err := dgr.Run("cp", "-r", pkb[n], dst+"/.")
29 if err != nil {
30 fmt.Printf("\033[31mERR\033[m\n")
31 dgr.Die("failed to copy file", pk[i], 1)
32 } else {
33 fmt.Printf("\033[32mOK\033[m\n")
34 }
35 }
36 }
37
38 // write the installed package to a installed file for tracking
39 fx, _ := os.ReadFile(filepath.Join(os.Getenv("DTR_DB"), "installed"))
40 fxx := strings.Fields(string(fx))
41 for i := range len(fxx) {
42 if fxx[i] == pkg {
43 dgr.Msg("reinstalled \033[1;32m", pkg, "\033[m successfully")
44 return
45 }
46 }
47
48 GenM(pkg, pkginst) // generate manifest
49
50 dgr.Msg("installed \033[1;32m", pkg, "\033[m successfully")
51 //}
52}