-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
160 lines (152 loc) · 3.63 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
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
package main
import (
"embed"
"fmt"
"io/fs"
"log"
"os"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/open-function-computers-llc/server-run/commands"
"github.com/open-function-computers-llc/server-run/server"
"github.com/urfave/cli"
)
//go:embed frontend/dist
var frontend embed.FS
var Version = "latest-dev"
func main() {
// check global env file
_, err := os.Stat("/etc/server-run.env")
if err == nil {
// global env file exists! let's load it
godotenv.Load("/etc/server-run.env")
}
app := cli.NewApp()
app.Name = "OFC Server Run"
app.Usage = "Manage the website hosting accounts on this server"
app.Version = Version
app.Commands = []cli.Command{
{
Name: "serve",
Aliases: []string{"s"},
Usage: "Start the web based UI",
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "Load configuration from `FILE`",
},
},
Action: func(c *cli.Context) error {
return startServer()
},
},
{
Name: "list",
Aliases: []string{"l"},
Usage: "Display some information from the account settings file",
Flags: []cli.Flag{
cli.StringFlag{
Name: "account",
Usage: "Account you're updating manually (required)",
Required: true,
},
cli.StringFlag{
Name: "setting",
Usage: "The setting you are tring to see (required)",
Required: true,
},
},
Action: func(c *cli.Context) error {
return commands.ListSetting(c)
},
},
{
Name: "set-env",
Aliases: []string{"env"},
Usage: "Populate the system ENV for use in scripts",
Flags: []cli.Flag{
cli.StringFlag{
Name: "account",
Usage: "Account you're updating manually (required)",
Required: true,
},
cli.StringFlag{
Name: "database",
Usage: "Populate DBUSER DBHOST DBPASSWORD DBNAME for a given database",
},
},
Action: func(c *cli.Context) error {
return commands.SetEnv(c)
},
},
{
Name: "update",
Aliases: []string{"u"},
Usage: "Update a specific account's settings file",
Flags: []cli.Flag{
cli.StringFlag{
Name: "account",
Usage: "Account you're updating manually (required)",
Required: true,
},
cli.StringFlag{
Name: "locked",
Usage: "Set locked status for this account (true|false)",
},
cli.StringFlag{
Name: "set-domain",
Usage: "Update the main domain for the selected account",
},
cli.StringFlag{
Name: "add-domain",
Usage: "Add a domain to the selected account",
},
cli.StringFlag{
Name: "remove-domain",
Usage: "Remove a domain from the selected account",
},
cli.StringFlag{
Name: "add-database",
Usage: "Add a database to the selected account",
},
cli.StringFlag{
Name: "db-user",
Usage: "Username when calling \"add-database\"",
},
cli.StringFlag{
Name: "db-name",
Usage: "Database name when calling \"add-database\"",
},
cli.StringFlag{
Name: "db-host",
Usage: "Database host when calling \"add-database\"",
},
cli.StringFlag{
Name: "db-password",
Usage: "Password when calling \"add-database\"",
},
},
Action: func(c *cli.Context) error {
return commands.Update(c)
},
},
}
err = app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func startServer() error {
// static assets for Angular app
stripped, err := fs.Sub(frontend, "frontend/dist/frontend")
if err != nil {
fmt.Println("error getting bundle")
return err
}
s, err := server.New(stripped)
if err != nil {
fmt.Println("error getting server")
return err
}
return s.Serve()
}