forked from xteve-project/xTeVe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxteve.go
232 lines (178 loc) · 5.24 KB
/
xteve.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// Copyright 2019 marmei. All rights reserved.
// Copyright 2022 senexcrenshaw. All rights reserved.
// Use of this source code is governed by a MIT license that can be found in the
// LICENSE file.
// GitHub: https://github.com/SenexCrenshaw/xTeVe
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"xteve/src"
)
// GitHubStruct : GitHub Account. The Updates are published via this Account
type GitHubStruct struct {
Branch string
Repo string
Update bool
User string
}
// GitHub : GitHub Account
// If you want to fork this project, enter your Github account here. This prevents a newer version of xTeVe from updating your version.
var GitHub = GitHubStruct{Branch: "main", User: "SenexCrenshaw", Repo: "xTeVe", Update: false}
// Branch: GitHub Branch
// User: GitHub Username
// Repo: GitHub Repository
// Update: Automatic updates from the GitHub repository [true|false]
// Name : Program Name
const Name = "xTeVe"
// DBVersion : Database Version
const DBVersion = "2.3.0"
// APIVersion : API Version
const APIVersion = "1.1.0"
var homeDirectory = fmt.Sprintf("%s%s.%s%s", src.GetUserHomeDirectory(), string(os.PathSeparator), strings.ToLower(Name), string(os.PathSeparator))
var samplePath = fmt.Sprintf("%spath%sto%sxteve%s", string(os.PathSeparator), string(os.PathSeparator), string(os.PathSeparator), string(os.PathSeparator))
var sampleRestore = fmt.Sprintf("%spath%sto%sfile%s", string(os.PathSeparator), string(os.PathSeparator), string(os.PathSeparator), string(os.PathSeparator))
var configFolder = flag.String("config", "", ": Config Folder ["+samplePath+"] (default: "+homeDirectory+")")
var port = flag.String("port", "", ": Server port [34400] (default: 34400)")
var restore = flag.String("restore", "", ": Restore from backup ["+sampleRestore+"xteve_backup.zip]")
var gitBranch = flag.String("branch", "", ": Git Branch [master|beta] (default: master)")
var noUpdates = flag.Bool("no-updates", false, ": Disable updates")
var debug = flag.Int("debug", 0, ": Debug level [0 - 3] (default: 0)")
var info = flag.Bool("info", false, ": Show system info")
var version = flag.Bool("version", false, ": Show system version")
var h = flag.Bool("h", false, ": Show help")
// Activates Development Mode. The local Files are then used for the Webserver.
var dev = flag.Bool("dev", false, ": Activates the developer mode, the source code must be available. The local files for the web interface are used.")
var buildwebui = flag.Bool("buildwebui", false, ": Builds webUI.go and exits.")
func main() {
// Separate Build Number from Version Number
var build = strings.Split(src.Version, ".")
var system = &src.System
system.APIVersion = APIVersion
system.Branch = GitHub.Branch
system.Build = build[len(build)-1:][0]
system.DBVersion = DBVersion
system.GitHub = GitHub
system.Name = Name
system.Version = strings.Join(build[0:len(build)-1], ".")
// Panic
defer func() {
if r := recover(); r != nil {
fmt.Println()
fmt.Println("* * * * * FATAL ERROR * * * * *")
fmt.Println("OS: ", runtime.GOOS)
fmt.Println("Arch:", runtime.GOARCH)
fmt.Println("Err: ", r)
fmt.Println()
pc := make([]uintptr, 20)
runtime.Callers(2, pc)
for i := range pc {
if runtime.FuncForPC(pc[i]) != nil {
f := runtime.FuncForPC(pc[i])
file, line := f.FileLine(pc[i])
if string(file)[0:1] != "?" {
fmt.Printf("%s:%d %s\n", filepath.Base(file), line, f.Name())
}
}
}
fmt.Println()
fmt.Println("* * * * * * * * * * * * * * * *")
}
}()
flag.Parse()
if *h {
flag.Usage()
return
}
if *buildwebui {
src.HTMLInit("webUI", "src", "html"+string(os.PathSeparator), "src"+string(os.PathSeparator)+"webUI.go")
err := src.BuildGoFile()
if err != nil {
src.ShowError(err, 0)
} else {
fmt.Println("webUI.go built successfully")
}
os.Exit(0)
}
system.Dev = *dev
if *version {
src.ShowSystemVersion()
return
}
// Display System Information
if *info {
system.Flag.Info = true
err := src.Init()
if err != nil {
src.ShowError(err, 0)
os.Exit(0)
}
src.ShowSystemInfo()
return
}
// Webserver Port
if len(*port) > 0 {
system.Flag.Port = *port
}
// Branch
system.Flag.Branch = *gitBranch
if len(system.Flag.Branch) > 0 {
fmt.Println("Git Branch is now:", system.Flag.Branch)
}
// Updates
if noUpdates != nil {
system.GitHub.Update = false
}
// Debug Level
system.Flag.Debug = *debug
if system.Flag.Debug > 3 {
flag.Usage()
return
}
// Storage location for the Configuration Files
if len(*configFolder) > 0 {
system.Folder.Config = *configFolder
}
// Restore Backup
if len(*restore) > 0 {
system.Flag.Restore = *restore
err := src.Init()
if err != nil {
src.ShowError(err, 0)
os.Exit(0)
}
err = src.XteveRestoreFromCLI(*restore)
if err != nil {
src.ShowError(err, 0)
}
os.Exit(0)
}
err := src.Init()
if err != nil {
src.ShowError(err, 0)
os.Exit(0)
}
err = src.BinaryUpdate()
if err != nil {
src.ShowError(err, 0)
}
err = src.StartSystem(false)
if err != nil {
src.ShowError(err, 0)
os.Exit(0)
}
err = src.InitMaintenance()
if err != nil {
src.ShowError(err, 0)
os.Exit(0)
}
err = src.StartWebserver()
if err != nil {
src.ShowError(err, 0)
os.Exit(0)
}
}