You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB
Go

package cmd
import (
"git.cijber.net/zer.ooo/service"
"github.com/spf13/cobra"
"os"
"path/filepath"
)
var (
endpoint string
location string
)
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialises an zer.ooo server install",
Long: "Init (zerooo init) will initialise a server",
Run: func(cmd *cobra.Command, args []string) {
config, err := service.LoadConfig(ConfigPath)
service.Check(err, "Failed reading config, err: %s", err)
if (cmd.Flag("endpoint").Changed) {
config.Zerooo.Endpoint = endpoint
}
if (cmd.Flag("location").Changed) {
if len(location) > 0 && location[0] != '/' {
cwd, err := os.Getwd()
service.Check(err, "Can't get current working directory, err: %s", err)
location = filepath.Join(cwd, location)
}
config.Zerooo.Location = location
}
service.CreateConfig(ConfigPath, config)
mgmt := service.NewManager(*config)
mgmt.Init()
mgmt.Register()
},
}
func init() {
f := initCmd.Flags()
f.StringVar(&endpoint, "endpoint", "https://zer.ooo", "Endpoint to register this server")
f.StringVar(&location, "location", "/etc/zerooo", "Location of OpenVPN installation")
}