From 19d4fec376f856cac264fd13ca1e56a205172a3c Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Fri, 23 Apr 2021 21:06:57 -0700 Subject: [PATCH] Remove persist option from configure commands --- internal/app/wwctl/configure/dhcp/main.go | 9 ++------- internal/app/wwctl/configure/dhcp/root.go | 4 +--- internal/app/wwctl/configure/hosts/main.go | 14 ++++++-------- internal/app/wwctl/configure/hosts/root.go | 4 +--- internal/app/wwctl/configure/nfs/main.go | 9 ++++----- internal/app/wwctl/configure/nfs/root.go | 4 +--- internal/app/wwctl/configure/root.go | 14 +++++++++++++- internal/app/wwctl/configure/ssh/main.go | 18 +++++++++--------- internal/app/wwctl/configure/ssh/root.go | 4 ++-- internal/app/wwctl/configure/tftp/main.go | 9 ++------- internal/app/wwctl/configure/tftp/root.go | 4 +--- 11 files changed, 42 insertions(+), 51 deletions(-) diff --git a/internal/app/wwctl/configure/dhcp/main.go b/internal/app/wwctl/configure/dhcp/main.go index 084dd7c6..4d13ef78 100644 --- a/internal/app/wwctl/configure/dhcp/main.go +++ b/internal/app/wwctl/configure/dhcp/main.go @@ -24,11 +24,6 @@ type dhcpTemplate struct { } func CobraRunE(cmd *cobra.Command, args []string) error { - if SetShow == false && SetPersist == false { - fmt.Println(cmd.Help()) - os.Exit(0) - } - return Configure(SetShow) } @@ -58,7 +53,7 @@ func Configure(show bool) error { os.Exit(1) } - if controller.Dhcp.Enabled == false { + if !controller.Dhcp.Enabled { wwlog.Printf(wwlog.INFO, "This system is not configured as a Warewulf DHCP controller\n") os.Exit(1) } @@ -109,7 +104,7 @@ func Configure(show bool) error { d.RangeStart = controller.Dhcp.RangeStart d.RangeEnd = controller.Dhcp.RangeEnd - if show == false { + if !show { fmt.Printf("Writing the DHCP configuration file\n") configWriter, err := os.OpenFile(controller.Dhcp.ConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640) if err != nil { diff --git a/internal/app/wwctl/configure/dhcp/root.go b/internal/app/wwctl/configure/dhcp/root.go index 8ed14596..76ec9e97 100644 --- a/internal/app/wwctl/configure/dhcp/root.go +++ b/internal/app/wwctl/configure/dhcp/root.go @@ -12,13 +12,11 @@ var ( "in the warewulf.conf file.", RunE: CobraRunE, } - SetShow bool - SetPersist bool + SetShow bool ) func init() { baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)") - baseCmd.PersistentFlags().BoolVar(&SetPersist, "persist", false, "Persist the configuration and initialize the service") } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/configure/hosts/main.go b/internal/app/wwctl/configure/hosts/main.go index f7365787..78865fc3 100644 --- a/internal/app/wwctl/configure/hosts/main.go +++ b/internal/app/wwctl/configure/hosts/main.go @@ -2,7 +2,6 @@ package hosts import ( "bytes" - "fmt" "os" "text/template" @@ -21,14 +20,13 @@ type TemplateStruct struct { } func CobraRunE(cmd *cobra.Command, args []string) error { + return Configure(SetShow) +} + +func Configure(show bool) error { var replace TemplateStruct - if SetShow == false && SetPersist == false { - fmt.Println(cmd.Help()) - os.Exit(0) - } - - if util.IsFile("/etc/warewulf/hosts.tmpl") == false { + if !util.IsFile("/etc/warewulf/hosts.tmpl") { wwlog.Printf(wwlog.WARN, "Template not found, not updating host file\n") return nil } @@ -90,7 +88,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { replace.Ipaddr = controller.Ipaddr replace.Fqdn = controller.Fqdn - if SetShow == false { + if !SetShow { // only open "/etc/hosts" when intended to write, as 'os.O_TRUNC' will empty the file otherwise. w, err = os.OpenFile("/etc/hosts", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { diff --git a/internal/app/wwctl/configure/hosts/root.go b/internal/app/wwctl/configure/hosts/root.go index 958bf57d..a8294453 100644 --- a/internal/app/wwctl/configure/hosts/root.go +++ b/internal/app/wwctl/configure/hosts/root.go @@ -10,13 +10,11 @@ var ( "Warewulf configuration directory.", RunE: CobraRunE, } - SetShow bool - SetPersist bool + SetShow bool ) func init() { baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)") - baseCmd.PersistentFlags().BoolVar(&SetPersist, "persist", false, "Persist the configuration and initialize the service") } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/configure/nfs/main.go b/internal/app/wwctl/configure/nfs/main.go index b2c9768d..99415114 100644 --- a/internal/app/wwctl/configure/nfs/main.go +++ b/internal/app/wwctl/configure/nfs/main.go @@ -11,11 +11,10 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { + return Configure(SetShow) +} - if SetShow == false && SetPersist == false { - fmt.Println(cmd.Help()) - os.Exit(0) - } +func Configure(show bool) error { controller, err := warewulfconf.New() if err != nil { @@ -32,7 +31,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if SetShow == false { + if !SetShow { exports, err := os.OpenFile("/etc/exports", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { wwlog.Printf(wwlog.ERROR, "%s\n", err) diff --git a/internal/app/wwctl/configure/nfs/root.go b/internal/app/wwctl/configure/nfs/root.go index e8a10e87..4121efa9 100644 --- a/internal/app/wwctl/configure/nfs/root.go +++ b/internal/app/wwctl/configure/nfs/root.go @@ -10,13 +10,11 @@ var ( "configure NFS as per the configuration in the warewulf.conf file.", RunE: CobraRunE, } - SetShow bool - SetPersist bool + SetShow bool ) func init() { baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)") - baseCmd.PersistentFlags().BoolVar(&SetPersist, "persist", false, "Persist the configuration and initialize the service") } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/configure/root.go b/internal/app/wwctl/configure/root.go index 32c4664d..0d493032 100644 --- a/internal/app/wwctl/configure/root.go +++ b/internal/app/wwctl/configure/root.go @@ -40,12 +40,24 @@ func GetCommand() *cobra.Command { func CobraRunE(cmd *cobra.Command, args []string) error { - if SetDoAll == true { + if SetDoAll { fmt.Printf("################################################################################\n") dhcp.Configure(false) fmt.Printf("################################################################################\n") tftp.Configure(false) + + fmt.Printf("################################################################################\n") + hosts.Configure(false) + + fmt.Printf("################################################################################\n") + nfs.Configure(false) + + fmt.Printf("################################################################################\n") + ssh.Configure(false) + + fmt.Printf("################################################################################\n") + tftp.Configure(false) } else { cmd.Help() os.Exit(0) diff --git a/internal/app/wwctl/configure/ssh/main.go b/internal/app/wwctl/configure/ssh/main.go index 5ea7f711..fc066030 100644 --- a/internal/app/wwctl/configure/ssh/main.go +++ b/internal/app/wwctl/configure/ssh/main.go @@ -11,10 +11,10 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - if SetPersist == false { - fmt.Println(cmd.Help()) - os.Exit(0) - } + return Configure(SetShow) +} + +func Configure(show bool) error { if os.Getuid() == 0 { fmt.Printf("Updating system keys\n") @@ -25,28 +25,28 @@ func CobraRunE(cmd *cobra.Command, args []string) error { os.Exit(1) } - if util.IsFile("/etc/warewulf/keys/ssh_host_rsa_key") == false { + if !util.IsFile("/etc/warewulf/keys/ssh_host_rsa_key") { fmt.Printf("Setting up key: ssh_host_rsa_key\n") util.ExecInteractive("ssh-keygen", "-q", "-t", "rsa", "-f", "/etc/warewulf/keys/ssh_host_rsa_key", "-C", "", "-N", "") } else { fmt.Printf("Skipping, key already exists: ssh_host_rsa_key\n") } - if util.IsFile("/etc/warewulf/keys/ssh_host_dsa_key") == false { + if !util.IsFile("/etc/warewulf/keys/ssh_host_dsa_key") { fmt.Printf("Setting up key: ssh_host_dsa_key\n") util.ExecInteractive("ssh-keygen", "-q", "-t", "dsa", "-f", "/etc/warewulf/keys/ssh_host_dsa_key", "-C", "", "-N", "") } else { fmt.Printf("Skipping, key already exists: ssh_host_dsa_key\n") } - if util.IsFile("/etc/warewulf/keys/ssh_host_ecdsa_key") == false { + if !util.IsFile("/etc/warewulf/keys/ssh_host_ecdsa_key") { fmt.Printf("Setting up key: ssh_host_ecdsa_key\n") util.ExecInteractive("ssh-keygen", "-q", "-t", "ecdsa", "-f", "/etc/warewulf/keys/ssh_host_ecdsa_key", "-C", "", "-N", "") } else { fmt.Printf("Skipping, key already exists: ssh_host_ecdsa_key\n") } - if util.IsFile("/etc/warewulf/keys/ssh_host_ed25519_key") == false { + if !util.IsFile("/etc/warewulf/keys/ssh_host_ed25519_key") { fmt.Printf("Setting up key: ssh_host_ed25519_key\n") util.ExecInteractive("ssh-keygen", "-q", "-t", "ed25519", "-f", "/etc/warewulf/keys/ssh_host_ed25519_key", "-C", "", "-N", "") } else { @@ -66,7 +66,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { rsaPriv := path.Join(homeDir, "/.ssh/id_rsa") rsaPub := path.Join(homeDir, "/.ssh/id_rsa.pub") - if util.IsFile(authorizedKeys) == false { + if !util.IsFile(authorizedKeys) { fmt.Printf("Setting up: %s\n", authorizedKeys) util.ExecInteractive("ssh-keygen", "-q", "-t", "rsa", "-f", rsaPriv, "-C", "", "-N", "") util.CopyFile(rsaPub, authorizedKeys) diff --git a/internal/app/wwctl/configure/ssh/root.go b/internal/app/wwctl/configure/ssh/root.go index 8865ea00..8f7ba046 100644 --- a/internal/app/wwctl/configure/ssh/root.go +++ b/internal/app/wwctl/configure/ssh/root.go @@ -11,11 +11,11 @@ var ( "keys.", RunE: CobraRunE, } - SetPersist bool + SetShow bool ) func init() { - baseCmd.PersistentFlags().BoolVar(&SetPersist, "persist", false, "Persist the configuration and initialize the service") + baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)") } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/configure/tftp/main.go b/internal/app/wwctl/configure/tftp/main.go index a14f595a..6283574c 100644 --- a/internal/app/wwctl/configure/tftp/main.go +++ b/internal/app/wwctl/configure/tftp/main.go @@ -13,11 +13,6 @@ import ( ) func CobraRunE(cmd *cobra.Command, args []string) error { - if SetShow == false && SetPersist == false { - fmt.Println(cmd.Help()) - os.Exit(0) - } - return Configure(SetShow) } @@ -33,7 +28,7 @@ func Configure(show bool) error { os.Exit(1) } - if util.IsDir(controller.Tftp.TftpRoot) == false { + if !util.IsDir(controller.Tftp.TftpRoot) { wwlog.Printf(wwlog.ERROR, "Configured TFTP Root directory does not exist: %s\n", controller.Tftp.TftpRoot) os.Exit(1) } @@ -44,7 +39,7 @@ func Configure(show bool) error { os.Exit(1) } - if show == false { + if !show { fmt.Printf("Writing PXE files to: %s\n", path.Join(controller.Tftp.TftpRoot, "warewulf")) err = staticfiles.WriteData("files/tftp/x86.efi", path.Join(controller.Tftp.TftpRoot, "warewulf/x86.efi")) if err != nil { diff --git a/internal/app/wwctl/configure/tftp/root.go b/internal/app/wwctl/configure/tftp/root.go index f14ab40a..9b5edb2e 100644 --- a/internal/app/wwctl/configure/tftp/root.go +++ b/internal/app/wwctl/configure/tftp/root.go @@ -10,13 +10,11 @@ var ( "on your Warewulf master.", RunE: CobraRunE, } - SetShow bool - SetPersist bool + SetShow bool ) func init() { baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)") - baseCmd.PersistentFlags().BoolVar(&SetPersist, "persist", false, "Persist the configuration and initialize the service") } // GetRootCommand returns the root cobra.Command for the application.