Remove persist option from configure commands

This commit is contained in:
Gregory Kurtzer
2021-04-23 21:06:57 -07:00
parent d1bc747cc2
commit 19d4fec376
11 changed files with 42 additions and 51 deletions

View File

@@ -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 {

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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.

View File

@@ -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)

View File

@@ -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.

View File

@@ -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)

View File

@@ -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)

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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.