2022-04-08 16:12:35 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-05-22 14:56:45 +02:00
|
|
|
"context"
|
2022-04-08 16:12:35 +02:00
|
|
|
|
2022-05-22 14:56:45 +02:00
|
|
|
"code.icod.de/postfix/manager/ent"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
2022-04-08 16:12:35 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2022-05-22 14:56:45 +02:00
|
|
|
var (
|
|
|
|
db string
|
|
|
|
setupPostfix bool
|
|
|
|
setupDovecot bool
|
|
|
|
)
|
|
|
|
|
2022-04-08 16:12:35 +02:00
|
|
|
// installCmd represents the install command
|
|
|
|
var installCmd = &cobra.Command{
|
|
|
|
Use: "install",
|
2022-05-22 14:56:45 +02:00
|
|
|
Short: "installs the database config files for postfix and creates the database",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
// create database schema
|
|
|
|
client, e := ent.Open("mysql", "dev:dev@tcp(localhost:3306)/postfix")
|
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
defer client.Close()
|
|
|
|
ctx := context.Background()
|
|
|
|
if e := client.Schema.Create(ctx); e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
// setup postfix
|
|
|
|
|
2022-04-08 16:12:35 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(installCmd)
|
|
|
|
|
2022-05-22 14:56:45 +02:00
|
|
|
installCmd.Flags().BoolVar(&setupPostfix, "setup:postfix", true, "--setup:postfix=true|false")
|
|
|
|
installCmd.Flags().BoolVar(&setupPostfix, "setup:dovecot", true, "--setup:dovecot=true|false")
|
|
|
|
|
2022-04-08 16:12:35 +02:00
|
|
|
// Here you will define your flags and configuration settings.
|
|
|
|
|
|
|
|
// Cobra supports Persistent Flags which will work for this command
|
|
|
|
// and all subcommands, e.g.:
|
|
|
|
// installCmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
|
|
|
|
|
|
// Cobra supports local flags which will only run when this command
|
|
|
|
// is called directly, e.g.:
|
|
|
|
// installCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
|
|
}
|