Extend and optimize relocatable build config infrastructure

This commit is contained in:
Gregory Kurtzer
2022-01-15 03:32:32 +00:00
parent be41b79261
commit 8da7dd415a
23 changed files with 258 additions and 348 deletions

View File

@@ -5,6 +5,7 @@ import (
"os"
"path"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
@@ -19,15 +20,17 @@ func Configure(show bool) error {
if os.Getuid() == 0 {
fmt.Printf("Updating system keys\n")
err := os.MkdirAll("/etc/warewulf/keys", 0755)
wwkeydir := path.Join(buildconfig.SYSCONFDIR, "/etc/warewulf/keys") + "/"
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)
}
if !util.IsFile("/etc/warewulf/keys/ssh_host_rsa_key") {
if !util.IsFile(wwkeydir + "ssh_host_rsa_key") {
fmt.Printf("Setting up key: ssh_host_rsa_key\n")
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "rsa", "-f", "/etc/warewulf/keys/ssh_host_rsa_key", "-C", "", "-N", "")
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "rsa", "-f", wwkeydir+"ssh_host_rsa_key", "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
@@ -35,9 +38,9 @@ func Configure(show bool) error {
fmt.Printf("Skipping, key already exists: ssh_host_rsa_key\n")
}
if !util.IsFile("/etc/warewulf/keys/ssh_host_dsa_key") {
if !util.IsFile(wwkeydir + "ssh_host_dsa_key") {
fmt.Printf("Setting up key: ssh_host_dsa_key\n")
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "dsa", "-f", "/etc/warewulf/keys/ssh_host_dsa_key", "-C", "", "-N", "")
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "dsa", "-f", wwkeydir+"ssh_host_dsa_key", "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
@@ -45,9 +48,9 @@ func Configure(show bool) error {
fmt.Printf("Skipping, key already exists: ssh_host_dsa_key\n")
}
if !util.IsFile("/etc/warewulf/keys/ssh_host_ecdsa_key") {
if !util.IsFile(wwkeydir + "ssh_host_ecdsa_key") {
fmt.Printf("Setting up key: ssh_host_ecdsa_key\n")
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "ecdsa", "-f", "/etc/warewulf/keys/ssh_host_ecdsa_key", "-C", "", "-N", "")
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "ecdsa", "-f", wwkeydir+"ssh_host_ecdsa_key", "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
@@ -55,9 +58,9 @@ func Configure(show bool) error {
fmt.Printf("Skipping, key already exists: ssh_host_ecdsa_key\n")
}
if !util.IsFile("/etc/warewulf/keys/ssh_host_ed25519_key") {
if !util.IsFile(wwkeydir + "ssh_host_ed25519_key") {
fmt.Printf("Setting up key: ssh_host_ed25519_key\n")
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "ed25519", "-f", "/etc/warewulf/keys/ssh_host_ed25519_key", "-C", "", "-N", "")
err = util.ExecInteractive("ssh-keygen", "-q", "-t", "ed25519", "-f", wwkeydir+"ssh_host_ed25519_key", "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}