-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
77 lines (61 loc) · 1.65 KB
/
main.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
/*
@author: [email protected]
@author: [email protected]
@Wazigate System Management
*/
package main
import (
"log"
"os"
"path/filepath"
_ "embed"
"github.com/Waziup/wazigate-system/api"
"github.com/Waziup/wazigate-system/pkg/nm"
)
func main() {
// Remove date and time from logs
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
log.SetOutput(os.Stdout)
log.Println("[SETUP] Performing setup, please wait ...")
for i, fn := range setup {
if err := fn(); err != nil {
log.Fatalf("[ERR ] Setup %d/%d failed: %v", i, len(setup), err)
}
}
log.Println("[SETUP] Setup completed successfully.")
api.ListenAndServeHTTP()
}
var setup = []func() error{
movePackageJSON,
nm.Connect,
api.Init,
api.RunLEDManager,
api.RunTimezoneManager,
api.RunBlackoutManager,
api.RunButtonsManager,
api.RunOLEDManager,
api.RunFanManager,
api.GoMonitor,
}
////////////////////////////////////////////////////////////////////////////////
//go:embed package.json
var packageJSON []byte
const defaultWaziappFolder = "/var/lib/waziapp"
var waziappFolder = getWaziappFolder()
func getWaziappFolder() string {
waziappFolder := os.Getenv("WAZIAPP_FOLDER")
if waziappFolder != "" {
return waziappFolder
}
return defaultWaziappFolder
}
var packageJSONFile = filepath.Join(waziappFolder, "package.json")
func movePackageJSON() error {
if err := os.WriteFile(packageJSONFile, packageJSON, 0777); err != nil {
log.Println("Make sure to run this container with the mapped volume '/var/lib/waziapp'.")
log.Println("See the Waziapp documentation for more details on running Waziapps.")
return err
}
api.PackageJSON = packageJSON
return nil
}