Files
warewulf/internal/pkg/configure/tftp.go
Jonathon Anderson 8321193645 Refactor and document config/datastructure
Also adjusted case for initialisms (e.g., DHCP, TFTP, NFS).

Signed-off-by: Jonathon Anderson <janderson@ciq.co>
2023-04-19 14:02:43 -06:00

50 lines
1.1 KiB
Go

package configure
import (
"fmt"
"os"
"path"
"github.com/hpcng/warewulf/internal/pkg/util"
warewulfconf "github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
func TFTP() error {
controller := warewulfconf.Get()
var tftpdir string = path.Join(controller.Paths.TFTPdir, "warewulf")
err := os.MkdirAll(tftpdir, 0755)
if err != nil {
wwlog.Error("%s", err)
return err
}
fmt.Printf("Writing PXE files to: %s\n", tftpdir)
copyCheck := make(map[string]bool)
for _, f := range controller.TFTP.IPXEBinaries {
if copyCheck[f] {
continue
}
copyCheck[f] = true
err = util.SafeCopyFile(path.Join(controller.Paths.Datadir, f), path.Join(tftpdir, f))
if err != nil {
wwlog.Warn("ipxe binary could not be copied, booting may not work: %s", err)
}
}
if !controller.TFTP.Enabled {
wwlog.Info("Warewulf does not auto start TFTP services due to disable by warewulf.conf")
os.Exit(0)
}
fmt.Printf("Enabling and restarting the TFTP services\n")
err = util.SystemdStart(controller.TFTP.SystemdName)
if err != nil {
wwlog.Error("%s", err)
return err
}
return nil
}