-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync-pkg.go
49 lines (42 loc) · 1.01 KB
/
sync-pkg.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
package opnborg
import (
"strings"
)
// checkInstallPKG checks the target server for missing packages
func checkInstallPKG(server string, config *OPNCall, opn *Opnsense) error {
// extract
srvpkg := strings.Split(opn.System.Firmware.Plugins, ",")
// compare
var add bool
var missing []string
for _, master := range config.Sync.PKG.Packages {
add = true
for _, pkg := range srvpkg {
if master == pkg {
add = false
break
}
}
if add {
missing = append(missing, master)
}
}
if len(missing) > 0 {
displayChan <- []byte("[SYNC][MISSING-PKG]" + server + ":" + strings.Join(missing, ","))
}
// install missing pkg
for _, pkg := range missing {
if err := installPKG(config, server, pkg); err != nil {
displayChan <- []byte("[SYNC][PKG][FAIL][INSTALL]" + pkg + " -> " + server)
} else {
if config.Debug {
displayChan <- []byte("[SYNC][PKG][DONE]" + pkg + " -> " + server)
}
}
}
// fin
if config.Debug {
displayChan <- []byte("[SYNC][FINISH]" + server)
}
return nil
}