-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
executable file
·52 lines (41 loc) · 1.19 KB
/
init.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
package webconfig
import (
"fmt"
"os"
)
// NewPage initalizes the NewWebConfig. It creates the
// default directories and starts the internal daemon.
func NewWebConfig(webRootPath string) *Config {
var c Config
c.WebRootPath = webRootPath
c.refreshRate = 15
// Create the appdata if it does not exist
c.AppDataPath = fmt.Sprintf("%s/appdata", c.WebRootPath)
if !fileOrDirExists(c.AppDataPath) {
os.Mkdir(c.AppDataPath, os.ModePerm)
}
c.ConfigFilePath = fmt.Sprintf("%s/.cfg/.all", c.AppDataPath)
cfgDir := fmt.Sprintf("%s/.cfg", c.AppDataPath)
if !fileOrDirExists(cfgDir) {
os.Mkdir(cfgDir, os.ModePerm)
}
certDir := fmt.Sprintf("%s/appdata/certs", c.WebRootPath)
if !fileOrDirExists(certDir) {
os.Mkdir(certDir, os.ModePerm)
}
selfcertDir := fmt.Sprintf("%s/appdata/certs/self", c.WebRootPath)
if !fileOrDirExists(selfcertDir) {
os.Mkdir(selfcertDir, os.ModePerm)
}
if !fileOrDirExists(c.ConfigFilePath) {
c.writeDefaultConfig()
}
c.GetConfig()
go c.refreshConfig()
// Need to do this on start.
if c.MessageBanner.On && c.MessageBanner.SecondsToDisplay > 0 {
c.MessageBanner.TickCount = c.MessageBanner.SecondsToDisplay
go c.setTimeoutResetMsgBanner()
}
return &c
}