mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-17 02:36:17 +01:00
move application code into beszel folder
This commit is contained in:
48
beszel/cmd/agent/agent.go
Normal file
48
beszel/cmd/agent/agent.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"beszel"
|
||||
"beszel/internal/agent"
|
||||
"beszel/internal/update"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// handle flags / subcommands
|
||||
if len(os.Args) > 1 {
|
||||
switch os.Args[1] {
|
||||
case "-v":
|
||||
fmt.Println(beszel.AppName+"-agent", beszel.Version)
|
||||
case "update":
|
||||
update.UpdateBeszelAgent()
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
var pubKey []byte
|
||||
if pubKeyEnv, exists := os.LookupEnv("KEY"); exists {
|
||||
pubKey = []byte(pubKeyEnv)
|
||||
} else {
|
||||
log.Fatal("KEY environment variable is not set")
|
||||
}
|
||||
|
||||
var port string
|
||||
|
||||
if p, exists := os.LookupEnv("PORT"); exists {
|
||||
// allow passing an address in the form of "127.0.0.1:45876"
|
||||
if !strings.Contains(port, ":") {
|
||||
port = ":" + port
|
||||
}
|
||||
port = p
|
||||
} else {
|
||||
port = ":45876"
|
||||
}
|
||||
|
||||
a := agent.NewAgent(pubKey, port)
|
||||
|
||||
a.Run()
|
||||
|
||||
}
|
||||
31
beszel/cmd/hub/hub.go
Normal file
31
beszel/cmd/hub/hub.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"beszel"
|
||||
"beszel/internal/hub"
|
||||
"beszel/internal/update"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := pocketbase.NewWithConfig(pocketbase.Config{
|
||||
DefaultDataDir: beszel.AppName + "_data",
|
||||
})
|
||||
app.RootCmd.Version = beszel.Version
|
||||
app.RootCmd.Use = beszel.AppName
|
||||
app.RootCmd.Short = ""
|
||||
|
||||
// add update command
|
||||
app.RootCmd.AddCommand(&cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update " + beszel.AppName + " to the latest version",
|
||||
Run: update.UpdateBeszel,
|
||||
})
|
||||
|
||||
hubApp := hub.NewHub(app)
|
||||
|
||||
hubApp.Run()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user