Update to support show correctly

Signed-off-by: jcsiadal <jeremy.c.siadal@intel.com>
This commit is contained in:
jcsiadal
2022-02-11 18:10:32 +00:00
parent 496674ab9e
commit c4938b55c7
3 changed files with 66 additions and 59 deletions

View File

@@ -7,8 +7,10 @@ import (
)
func Configure(s string, v bool) error {
fmt.Printf("################################################################################\n")
fmt.Printf("Configuring: %s\n", s)
if !v {
fmt.Printf("################################################################################\n")
fmt.Printf("Configuring: %s\n", s)
}
var err error
switch s {

View File

@@ -12,58 +12,61 @@ import (
)
func configureSSH(show bool) error {
if os.Getuid() == 0 {
fmt.Printf("Updating system keys\n")
if !show {
if os.Getuid() == 0 {
fmt.Printf("Updating system keys\n")
wwkeydir := path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys") + "/"
wwkeydir := path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys") + "/"
err := os.MkdirAll(path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys"), 0755)
err := os.MkdirAll(path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys"), 0755)
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not create base directory: %s\n", err)
os.Exit(1)
}
for _, k := range [4]string{"rsa", "dsa", "ecdsa", "ed25519"} {
keytype := "ssh_host_" + k + "_key"
if !util.IsFile(path.Join(wwkeydir, keytype)) {
fmt.Printf("Setting up key: %s\n", keytype)
wwlog.Printf(wwlog.DEBUG, "Creating new %s key\n", keytype)
err = util.ExecInteractive("ssh-keygen", "-q", "-t", k, "-f", path.Join(wwkeydir, keytype), "-C", "", "-N", "")
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed to exec ssh-keygen: %s\n", err)
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
} else {
fmt.Printf("Skipping, key already exists: %s\n", keytype)
}
}
} else {
fmt.Printf("Updating user's keys\n")
}
homeDir, err := os.UserHomeDir()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not create base directory: %s\n", err)
wwlog.Printf(wwlog.ERROR, "Could not obtain the user's home directory: %s\n", err)
os.Exit(1)
}
for _, k := range [4]string{"rsa", "dsa", "ecdsa", "ed25519"} {
keytype := "ssh_host_" + k + "_key"
if !util.IsFile(path.Join(wwkeydir, keytype)) {
fmt.Printf("Setting up key: %s\n", keytype)
wwlog.Printf(wwlog.DEBUG, "Creating new %s key\n", keytype)
err = util.ExecInteractive("ssh-keygen", "-q", "-t", k, "-f", path.Join(wwkeydir, keytype), "-C", "", "-N", "")
if err != nil {
wwlog.Printf(wwlog.ERROR, "Failed to exec ssh-keygen: %s\n", err)
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
} else {
fmt.Printf("Skipping, key already exists: %s\n", keytype)
authorizedKeys := path.Join(homeDir, "/.ssh/authorized_keys")
rsaPriv := path.Join(homeDir, "/.ssh/id_rsa")
rsaPub := path.Join(homeDir, "/.ssh/id_rsa.pub")
if !util.IsFile(authorizedKeys) {
fmt.Printf("Setting up: %s\n", authorizedKeys)
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "rsa", "-f", rsaPriv, "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
err := util.CopyFile(rsaPub, authorizedKeys)
if err != nil {
return errors.Wrap(err, "failed to copy keys")
}
} else {
fmt.Printf("Skipping, authorized_keys already exists: %s\n", authorizedKeys)
}
} else {
fmt.Printf("Updating user's keys\n")
fmt.Printf("'ssh -s' is not yet implemented.\n")
}
homeDir, err := os.UserHomeDir()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not obtain the user's home directory: %s\n", err)
os.Exit(1)
}
authorizedKeys := path.Join(homeDir, "/.ssh/authorized_keys")
rsaPriv := path.Join(homeDir, "/.ssh/id_rsa")
rsaPub := path.Join(homeDir, "/.ssh/id_rsa.pub")
if !util.IsFile(authorizedKeys) {
fmt.Printf("Setting up: %s\n", authorizedKeys)
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "rsa", "-f", rsaPriv, "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
err := util.CopyFile(rsaPub, authorizedKeys)
if err != nil {
return errors.Wrap(err, "failed to copy keys")
}
} else {
fmt.Printf("Skipping, authorized_keys already exists: %s\n", authorizedKeys)
}
return nil
}

View File

@@ -15,25 +15,25 @@ import (
var tftpdir string = path.Join(buildconfig.TFTPDIR(), "warewulf")
func configureTFTP(show bool) error {
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
err = os.MkdirAll(tftpdir, 0755)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if !show {
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
return err
}
err = os.MkdirAll(tftpdir, 0755)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
return err
}
fmt.Printf("Writing PXE files to: %s\n", tftpdir)
for _, f := range [4]string{"x86.efi", "i386.efi", "i386.kpxe", "arm64.efi"} {
err = staticfiles.WriteData(path.Join("files/tftp", f), path.Join(tftpdir, f))
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
return err
}
}
@@ -41,8 +41,10 @@ func configureTFTP(show bool) error {
err = util.SystemdStart(controller.Tftp.SystemdName)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
return err
}
} else {
fmt.Printf("'tftp -s' is not yet implemented.\n")
}
return nil