Revert "Move configuration code out of wwctl"

This commit is contained in:
Gregory M. Kurtzer
2022-02-11 16:20:05 -08:00
committed by GitHub
parent 5a7f99af18
commit 67ee3bf5f8
33 changed files with 685 additions and 683 deletions

13
Defaults.mk.in Normal file
View File

@@ -0,0 +1,13 @@
VERSION ?= @VERSION@
RELEASE ?= @RELEASE@
PREFIX ?= @PREFIX@
BINDIR ?= @BINDIR@
SYSCONFDIR ?= @SYSCONFDIR@
SRVDIR ?= @SRVDIR@
DATADIR ?= @DATADIR@
MANDIR ?= @MANDIR@
LOCALSTATEDIR ?= @LOCALSTATEDIR@
TFTPDIR ?= @TFTPDIR@
FIREWALLDDIR ?= @FIREWALLDDIR@
SYSTEMDDIR ?= @SYSTEMDDIR@
BASH_COMPLETION ?= @BASH_COMPLETION@

163
Makefile
View File

@@ -1,63 +1,39 @@
.PHONY: all .PHONY: all
# Linux distro (set to /etc/os-release ID)
OS ?= rocky
# List of variables to save or replace in files
VARLIST := OS
-include Defaults.mk -include Defaults.mk
# Project Information
VARLIST += WAREWULF VERSION RELEASE
WAREWULF ?= warewulf
VERSION ?= 4.2.0 VERSION ?= 4.2.0
GIT_TAG := $(shell test -e .git && git describe --tags --long --first-parent --always) GIT_TAG := $(shell test -e .git && git describe --tags --long --first-parent --always)
ifndef $(GIT_TAG) ifndef $(GIT_TAG)
ifdef $(filter $(OS),ubuntu debian) RELEASE ?= 1.git_$(GIT_TAG)
RELEASE ?= 1.git_$(subst -,+,$(GIT_TAG))
else
RELEASE ?= 1.git_$(subst -,_,$(GIT_TAG))
endif
else else
RELEASE ?= 1 RELEASE ?= 1
endif endif
# System directory paths # System locations
VARLIST += PREFIX BINDIR SYSCONFDIR SRVDIR DATADIR MANDIR DOCDIR LOCALSTATEDIR SHAREDSTATEDIR
PREFIX ?= /usr/local PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin BINDIR ?= $(PREFIX)/bin
SYSCONFDIR ?= $(PREFIX)/etc SYSCONFDIR ?= $(PREFIX)/etc
SRVDIR ?= /srv SRVDIR ?= $(PREFIX)/srv
DATADIR ?= $(PREFIX)/share DATADIR ?= $(PREFIX)/share
MANDIR ?= $(DATADIR)/man MANDIR ?= $(DATADIR)/man
DOCDIR ?= $(DATADIR)/doc LOCALSTATEDIR ?= $(PREFIX)/var
LOCALSTATEDIR ?= /var WWCLIENTLOC ?= /warewulf/bin
SHAREDSTATEDIR ?= /var/local
# OS-Specific Service Locations
VARLIST += TFTPDIR FIREWALLDDIR SYSTEMDDIR
ifeq ($(OS),suse)
TFTPDIR ?= /srv/tftpboot
endif
ifeq ($(OS),ubuntu)
TFTPDIR ?= /srv/tftp
endif
TFTPDIR ?= /var/lib/tftpboot TFTPDIR ?= /var/lib/tftpboot
FIREWALLDDIR ?= /usr/lib/firewalld/services FIREWALLDDIR ?= /usr/lib/firewalld/services
SYSTEMDDIR ?= /usr/lib/systemd/system SYSTEMDDIR ?= /usr/lib/systemd/system
BASHCOMPDIR ?= /etc/bash_completion.d BASH_COMPLETION ?= /etc/bash_completion.d/
# Warewulf directory paths # Warewulf locations
VARLIST += WWCLIENTDIR WWCONFIGDIR WWPROVISIONDIR WWOVERLAYDIR WWCHROOTDIR WWTFTPDIR WWDOCDIR WWPROVISIONDIR = $(SRVDIR)/warewulf
WWCONFIGDIR := $(SYSCONFDIR)/$(WAREWULF) WWOVERLAYDIR = $(LOCALSTATEDIR)/warewulf/overlays
WWPROVISIONDIR := $(SHAREDSTATEDIR)/$(WAREWULF) WWCHROOTDIR = $(LOCALSTATEDIR)/warewulf/chroots
WWOVERLAYDIR := $(SHAREDSTATEDIR)/$(WAREWULF)/overlays
WWCHROOTDIR := $(SHAREDSTATEDIR)/$(WAREWULF)/chroots # SuSE
WWTFTPDIR := $(TFTPDIR)/$(WAREWULF) #TFTPDIR ?= /srv/tftpboot
WWDOCDIR := $(DOCDIR)/$(WAREWULF) #FIREWALLDIR ?= /srv/tftp
WWCLIENTDIR ?= /warewulf
# auto installed tooling # auto installed tooling
TOOLS_DIR := .tools TOOLS_DIR := .tools
@@ -75,7 +51,7 @@ GOPROXY ?= https://proxy.golang.org
export GOPROXY export GOPROXY
# built tags needed for wwbuild binary # built tags needed for wwbuild binary
WW_GO_BUILD_TAGS := containers_image_openpgp containers_image_ostree WW_BUILD_GO_BUILD_TAGS := containers_image_openpgp containers_image_ostree
all: config vendor wwctl wwclient bash_completion.d man_pages all: config vendor wwctl wwclient bash_completion.d man_pages
@@ -92,8 +68,10 @@ $(GO_TOOLS_BIN):
$(GOLANGCI_LINT): $(GOLANGCI_LINT):
@curl -qq -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOLANGCI_LINT_VERSION) @curl -qq -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOLANGCI_LINT_VERSION)
setup: vendor $(TOOLS_DIR) setup_tools setup: vendor $(TOOLS_DIR) setup_tools
# vendor
vendor: vendor:
go mod tidy -v go mod tidy -v
go mod vendor go mod vendor
@@ -103,11 +81,27 @@ $(TOOLS_DIR):
# Pre-build steps for source, such as "go generate" # Pre-build steps for source, such as "go generate"
config: config:
# Store configuration for subsequent runs set -x ;\
printf " $(foreach V,$(VARLIST),$V := $(strip $($V))\n)" > Defaults.mk for i in `find . -type f -name "*.in" -not -path "./vendor/*"`; do \
# Global variable search and replace for all *.in files NAME=`echo $$i | sed -e 's,\.in,,'`; \
find . -type f -name "*.in" -not -path "./vendor/*" \ sed -e 's,@BINDIR@,$(BINDIR),g' \
-exec sh -c 'sed -ne "$(foreach V,$(VARLIST),s,@$V@,$(strip $($V)),g;)p" $${0} > $${0%.in}' {} \; -e 's,@SYSCONFDIR@,$(SYSCONFDIR),g' \
-e 's,@LOCALSTATEDIR@,$(LOCALSTATEDIR),g' \
-e 's,@PREFIX@,$(PREFIX),g' \
-e 's,@DATADIR@,$(DATADIR),g' \
-e 's,@MANDIR@,$(MANDIR),g' \
-e 's,@SRVDIR@,$(SRVDIR),g' \
-e 's,@TFTPDIR@,$(TFTPDIR),g' \
-e 's,@FIREWALLDDIR@,$(FIREWALLDDIR),g' \
-e 's,@SYSTEMDDIR@,$(SYSTEMDDIR),g' \
-e 's,@BASH_COMPLETION@,$(BASH_COMPLETION),g' \
-e 's,@WWOVERLAYDIR@,$(WWOVERLAYDIR),g' \
-e 's,@WWCHROOTDIR@,$(WWCHROOTDIR),g' \
-e 's,@WWPROVISIONDIR@,$(WWPROVISIONDIR),g' \
-e 's,@VERSION@,$(VERSION),g' \
-e 's,@WWCLIENTLOC@,$(WWCLIENTLOC),g' \
-e 's,@RELEASE@,$(RELEASE),g' $$i > $$NAME; \
done
touch config touch config
rm_config: rm_config:
@@ -115,10 +109,11 @@ rm_config:
genconfig: rm_config config genconfig: rm_config config
# Lint # Lint
lint: setup_tools lint: setup_tools
@echo Running golangci-lint... @echo Running golangci-lint...
@$(GOLANGCI_LINT) run --build-tags "$(WW_GO_BUILD_TAGS)" --skip-dirs internal/pkg/staticfiles ./... @$(GOLANGCI_LINT) run --build-tags "$(WW_BUILD_GO_BUILD_TAGS)" --skip-dirs internal/pkg/staticfiles ./...
vet: vet:
go vet ./... go vet ./...
@@ -142,86 +137,98 @@ files: all
install -d -m 0755 $(DESTDIR)$(BINDIR) install -d -m 0755 $(DESTDIR)$(BINDIR)
install -d -m 0755 $(DESTDIR)$(WWCHROOTDIR) install -d -m 0755 $(DESTDIR)$(WWCHROOTDIR)
install -d -m 0755 $(DESTDIR)$(WWPROVISIONDIR) install -d -m 0755 $(DESTDIR)$(WWPROVISIONDIR)
install -d -m 0755 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/$(WWCLIENTDIR) install -d -m 0755 $(DESTDIR)$(WWOVERLAYDIR)
install -d -m 0755 $(DESTDIR)$(WWCONFIGDIR)/ipxe install -d -m 0755 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/warewulf/bin/
install -d -m 0755 $(DESTDIR)$(WWTFTPDIR)/ipxe/ install -d -m 0755 $(DESTDIR)$(SYSCONFDIR)/warewulf/
install -d -m 0755 $(DESTDIR)$(BASHCOMPDIR) install -d -m 0755 $(DESTDIR)$(SYSCONFDIR)/warewulf/ipxe
install -d -m 0755 $(DESTDIR)$(TFTPDIR)/warewulf/ipxe/
install -d -m 0755 $(DESTDIR)$(BASH_COMPLETION)
install -d -m 0755 $(DESTDIR)$(MANDIR)/man1 install -d -m 0755 $(DESTDIR)$(MANDIR)/man1
install -d -m 0755 $(DESTDIR)$(WWDOCDIR)
install -d -m 0755 $(DESTDIR)$(FIREWALLDDIR) install -d -m 0755 $(DESTDIR)$(FIREWALLDDIR)
install -d -m 0755 $(DESTDIR)$(SYSTEMDDIR) install -d -m 0755 $(DESTDIR)$(SYSTEMDDIR)
test -f $(DESTDIR)$(WWCONFIGDIR)/warewulf.conf || install -m 644 etc/warewulf.conf $(DESTDIR)$(WWCONFIGDIR) test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/warewulf.conf || install -m 644 etc/warewulf.conf $(DESTDIR)$(SYSCONFDIR)/warewulf/
test -f $(DESTDIR)$(WWCONFIGDIR)/hosts.tmpl || install -m 644 etc/hosts.tmpl $(DESTDIR)$(WWCONFIGDIR) test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/hosts.tmpl || install -m 644 etc/hosts.tmpl $(DESTDIR)$(SYSCONFDIR)/warewulf/
test -f $(DESTDIR)$(WWCONFIGDIR)/nodes.conf || install -m 644 etc/nodes.conf $(DESTDIR)$(WWCONFIGDIR) test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/nodes.conf || install -m 644 etc/nodes.conf $(DESTDIR)$(SYSCONFDIR)/warewulf/
cp -r etc/dhcp $(DESTDIR)$(WWCONFIGDIR)/ cp -r etc/dhcp $(DESTDIR)$(SYSCONFDIR)/warewulf/
cp -r etc/ipxe $(DESTDIR)$(WWCONFIGDIR)/ cp -r etc/ipxe $(DESTDIR)$(SYSCONFDIR)/warewulf/
cp -r overlays/wwinit $(DESTDIR)$(WWOVERLAYDIR)/ cp -r overlays/* $(DESTDIR)$(WWOVERLAYDIR)/
cp -r overlays/generic $(DESTDIR)$(WWOVERLAYDIR)/
cp -r overlays/wwclient/* $(DESTDIR)$(WWOVERLAYDIR)/wwinit/$(WWCLIENTDIR)/
chmod 755 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/init chmod 755 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/init
rm -f $(DESTDIR)$(WWOVERLAYDIR)/wwinit/init.in chmod 755 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/warewulf/wwinit
find $(DESTDIR)$(WWOVERLAYDIR) -type f -name "*.in" -exec rm -f {} \;
chmod 755 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/$(WWCLIENTDIR)/wwinit
chmod 600 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/etc/ssh/ssh* chmod 600 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/etc/ssh/ssh*
chmod 644 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/etc/ssh/ssh*.pub.ww chmod 644 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/etc/ssh/ssh*.pub.ww
install -m 0755 wwctl $(DESTDIR)$(BINDIR) install -m 0755 wwctl $(DESTDIR)$(BINDIR)
install -m 0644 include/firewalld/warewulf.xml $(DESTDIR)$(FIREWALLDDIR) install -c -m 0644 include/firewalld/warewulf.xml $(DESTDIR)$(FIREWALLDDIR)
install -m 0644 include/systemd/warewulfd.service $(DESTDIR)$(SYSTEMDDIR) install -c -m 0644 include/systemd/warewulfd.service $(DESTDIR)$(SYSTEMDDIR)
install -m 0644 LICENSE.md $(DESTDIR)$(WWDOCDIR) cp bash_completion.d/warewulf $(DESTDIR)$(BASH_COMPLETION)
cp bash_completion.d/warewulf $(DESTDIR)$(BASHCOMPDIR)
cp man_pages/* $(DESTDIR)$(MANDIR)/man1/ cp man_pages/* $(DESTDIR)$(MANDIR)/man1/
init: init:
systemctl daemon-reload systemctl daemon-reload
cp -r tftpboot/* $(WWTFTPDIR)/ipxe/ cp -r tftpboot/* $(TFTPDIR)/warewulf/ipxe/
restorecon -r $(WWTFTPDIR) restorecon -r $(TFTPDIR)/warewulf
# Overlay file system has changed
#debfiles: debian
# chmod +x $(DESTDIR)$(WWROOT)/warewulf/overlays/system/debian/init
# chmod 600 $(DESTDIR)$(WWROOT)/warewulf/overlays/system/debian/etc/ssh/ssh*
# chmod 644 $(DESTDIR)$(WWROOT)/warewulf/overlays/system/debian/etc/ssh/ssh*.pub.ww
# mkdir -p $(DESTDIR)$(WWROOT)/warewulf/overlays/system/debian/warewulf/bin/
# cp wwclient $(DESTDIR)$(WWROOT)/warewulf/overlays/system/debian/warewulf/bin/
wwctl: wwctl:
cd cmd/wwctl; GOOS=linux go build -mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../wwctl cd cmd/wwctl; GOOS=linux go build -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl
wwclient: wwclient:
cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags "-extldflags -static \ cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags "-extldflags -static \
-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=/etc/warewulf/warewulf.conf'" -o ../../wwclient -X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=/etc/warewulf/warewulf.conf'" -o ../../wwclient
install_wwclient: wwclient install_wwclient: wwclient
install -m 0755 wwclient $(DESTDIR)$(WWOVERLAYDIR)/wwinit/$(WWCLIENTDIR)/wwclient install -m 0755 wwclient $(DESTDIR)$(WWOVERLAYDIR)/wwinit/$(WWCLIENTLOC)/wwclient
bash_completion: bash_completion:
cd cmd/bash_completion && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\ cd cmd/bash_completion && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\
-X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\ -X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\
-mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../bash_completion -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../bash_completion
bash_completion.d: bash_completion bash_completion.d: bash_completion
install -d -m 0755 bash_completion.d install -d -m 0755 bash_completion.d
./bash_completion bash_completion.d/warewulf ./bash_completion bash_completion.d/warewulf
man_page: man_page:
cd cmd/man_page && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\ cd cmd/man_page && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\
-X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\ -X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\
-mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../man_page -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../man_page
man_pages: man_page man_pages: man_page
install -d man_pages install -d man_pages
./man_page ./man_pages ./man_page ./man_pages
cd man_pages; for i in wwctl*1; do echo "Compressing manpage: $$i"; gzip --force $$i; done cd man_pages; for i in wwctl*1; do echo "Compressing manpage: $$i"; gzip --force $$i; done
#config_defaults:
# cd cmd/config_defaults && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf' \
# -X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf' \
# -X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.defaultDataStore=$(WWROOT)/warewulf'" \
# -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../config_defaults
dist: vendor config dist: vendor config
rm -rf .dist/$(WAREWULF)-$(VERSION) rm -rf .dist/warewulf-$(VERSION)
mkdir -p .dist/$(WAREWULF)-$(VERSION) mkdir -p .dist/warewulf-$(VERSION)
cp -rap * .dist/$(WAREWULF)-$(VERSION)/ cp -rap * .dist/warewulf-$(VERSION)/
cd .dist; tar -czf ../$(WAREWULF)-$(VERSION).tar.gz $(WAREWULF)-$(VERSION) cd .dist; tar -czf ../warewulf-$(VERSION).tar.gz warewulf-$(VERSION)
rm -rf .dist rm -rf .dist
clean: clean:
rm -f wwclient rm -f wwclient
rm -f wwctl rm -f wwctl
rm -rf .dist rm -rf .dist
rm -f $(WAREWULF)-$(VERSION).tar.gz rm -f warewulf-$(VERSION).tar.gz
rm -f bash_completion rm -f bash_completion
rm -rf bash_completion.d rm -rf bash_completion.d
rm -f man_page rm -f man_page
rm -rf man_pages rm -rf man_pages
rm -rf vendor rm -rf vendor
# rm -f config_defaults
rm -f config rm -f config
rm -f Defaults.mk rm -f Defaults.mk

View File

@@ -10,7 +10,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"path"
"strings" "strings"
"syscall" "syscall"
"time" "time"
@@ -63,10 +62,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
return errors.New("found pidfile " + PIDFile + " not starting") return errors.New("found pidfile " + PIDFile + " not starting")
} }
clientDir := buildconfig.WWCLIENTDIR() if os.Args[0] == buildconfig.WWCLIENTLOC() {
testDir := path.Join(clientDir, "wwclient-test")
if os.Args[0] == path.Join(clientDir, "wwclient") {
err := os.Chdir("/") err := os.Chdir("/")
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "failed to change dir: %s", err) wwlog.Printf(wwlog.ERROR, "failed to change dir: %s", err)
@@ -77,15 +73,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
time.Sleep(5000 * time.Millisecond) time.Sleep(5000 * time.Millisecond)
} else { } else {
fmt.Printf("Called via: %s\n", os.Args[0]) fmt.Printf("Called via: %s\n", os.Args[0])
fmt.Printf("Runtime overlay is being put in '%s' rather than '/'\n", testDir) fmt.Printf("Runtime overlay is being put in '/warewulf/wwclient-test' rather than '/'\n")
err := os.MkdirAll(testDir, 0755) err := os.MkdirAll("/warewulf/wwclient-test", 0755)
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "failed to create dir: %s", err) wwlog.Printf(wwlog.ERROR, "failed to create dir: %s", err)
_ = os.Remove(PIDFile) _ = os.Remove(PIDFile)
os.Exit(1) os.Exit(1)
} }
err = os.Chdir(testDir) err = os.Chdir("/warewulf/wwclient-test")
if err != nil { if err != nil {
wwlog.Printf(wwlog.ERROR, "failed to change dir: %s", err) wwlog.Printf(wwlog.ERROR, "failed to change dir: %s", err)
_ = os.Remove(PIDFile) _ = os.Remove(PIDFile)

View File

@@ -1,4 +1,4 @@
package configure package dhcp
import ( import (
"path" "path"
@@ -8,12 +8,12 @@ import (
) )
func TestDhcpTemplateFile(t *testing.T) { func TestDhcpTemplateFile(t *testing.T) {
tests := []struct { tests := []struct{
parameter string parameter string
expected string expected string
}{ }{
{"", path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")}, {"", path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")},
{"default", path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")}, {"default", path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")},
{"static", path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/static-dhcpd.conf")}, {"static", path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/static-dhcpd.conf")},
{"/test/absolute/path.conf", "/test/absolute/path.conf"}, {"/test/absolute/path.conf", "/test/absolute/path.conf"},
} }
@@ -25,3 +25,4 @@ func TestDhcpTemplateFile(t *testing.T) {
} }
} }
} }

View File

@@ -1,10 +1,144 @@
package dhcp package dhcp
import ( import (
"github.com/hpcng/warewulf/internal/pkg/configure" "fmt"
"os"
"path"
"strconv"
"strings"
"text/template"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { type dhcpTemplate struct {
return configure.Configure("DHCP", setShow) Ipaddr string
Port string
RangeStart string
RangeEnd string
Network string
Netmask string
Nodes []node.NodeInfo
}
func CobraRunE(cmd *cobra.Command, args []string) error {
return Configure(SetShow)
}
func Configure(show bool) error {
var d dhcpTemplate
var templateFile string
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if controller.Ipaddr == "" {
wwlog.Printf(wwlog.ERROR, "The Warewulf IP Address is not properly configured\n")
os.Exit(1)
}
if controller.Netmask == "" {
wwlog.Printf(wwlog.ERROR, "The Warewulf Netmask is not properly configured\n")
os.Exit(1)
}
if !controller.Dhcp.Enabled {
wwlog.Printf(wwlog.INFO, "This system is not configured as a Warewulf DHCP controller\n")
os.Exit(1)
}
if controller.Dhcp.RangeStart == "" {
wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range start`\n")
os.Exit(1)
}
if controller.Dhcp.RangeEnd == "" {
wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range end`\n")
os.Exit(1)
}
if controller.Dhcp.ConfigFile == "" {
controller.Dhcp.ConfigFile = "/etc/dhcp/dhcpd.conf"
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err)
os.Exit(1)
}
d.Nodes = append(d.Nodes, nodes...)
templateFile = dhcpTemplateFile(controller.Dhcp.Template)
tmpl, err := template.New(path.Base(templateFile)).ParseFiles(templateFile)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
d.Ipaddr = controller.Ipaddr
d.Port = strconv.Itoa(controller.Warewulf.Port)
d.Network = controller.Network
d.Netmask = controller.Netmask
d.RangeStart = controller.Dhcp.RangeStart
d.RangeEnd = controller.Dhcp.RangeEnd
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 {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer configWriter.Close()
err = tmpl.Execute(configWriter, d)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
fmt.Printf("Enabling and restarting the DHCP services\n")
err = util.SystemdStart(controller.Dhcp.SystemdName)
if err != nil {
return errors.Wrap(err, "failed to start")
}
} else {
err = tmpl.Execute(os.Stdout, d)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
return nil
}
// dhcpTemplateFile returns the path of the warewulf dhcp template given controller.Dhcp.Template.
func dhcpTemplateFile(controllerDhcpTemplate string) (templateFile string) {
if controllerDhcpTemplate == "" {
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")
} else {
if strings.HasPrefix(controllerDhcpTemplate, "/") {
templateFile = controllerDhcpTemplate
} else {
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/"+controllerDhcpTemplate+"-dhcpd.conf")
}
}
return
} }

View File

@@ -7,17 +7,17 @@ import (
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
Use: "dhcp [OPTIONS]", Use: "dhcp [OPTIONS]",
Short: "Manage and initialize DHCP", Short: "Manage and initialize DHCP",
Long: "DHCP is a dependent service to Warewulf. This command will configure DHCP as defined\n" + Long: "DHCP is a dependent service to Warewulf. This command will configure DHCP as defined\n" +
"in the warewulf.conf file.", "in the warewulf.conf file.",
RunE: CobraRunE, RunE: CobraRunE,
} }
setShow bool SetShow bool
) )
func init() { func init() {
baseCmd.PersistentFlags().BoolVarP(&setShow, "show", "s", false, "Show configuration (don't update)") baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.

View File

@@ -1,10 +1,117 @@
package hosts package hosts
import ( import (
"github.com/hpcng/warewulf/internal/pkg/configure" "bytes"
"os"
"path"
"text/template"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { type TemplateStruct struct {
return configure.Configure("hosts", setShow) PrevHostFile string
Ipaddr string
Fqdn string
AllNodes []node.NodeInfo
}
func CobraRunE(cmd *cobra.Command, args []string) error {
return Configure(SetShow)
}
func Configure(show bool) error {
var replace TemplateStruct
if !util.IsFile(path.Join(buildconfig.SYSCONFDIR(), "warewulf/hosts.tmpl")) {
wwlog.Printf(wwlog.WARN, "Template not found, not updating host file\n")
return nil
}
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
n, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
tmpl, err := template.ParseFiles(path.Join(buildconfig.SYSCONFDIR(), "warewulf/hosts.tmpl"))
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not parse hosts template: %s\n", err)
os.Exit(1)
}
replace.PrevHostFile = ""
w, err := os.Open("/etc/hosts")
if err != nil {
wwlog.Printf(wwlog.WARN, "%s\n", err)
} else {
// if /etc/hosts.ww does not exist, backup /etc/hosts to /etc/hosts.wwbackup
if !util.IsFile("/etc/hosts.wwbackup") {
err = util.CopyFile("/etc/hosts", "/etc/hosts.wwbackup")
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
}
}
// read all lines before the # warewulf comment and put into PrevHostFile template variable
lines, _ := util.ReadFile("/etc/hosts")
if lines != nil {
var buffer bytes.Buffer
for _, line := range lines {
//wwlog.Printf(wwlog.INFO, "Reading line: %s\n", line)
if util.ValidString(line, "^#.*maintained by warewulf") {
break
}
buffer.WriteString(line)
buffer.WriteString("\n")
}
replace.PrevHostFile = buffer.String()
}
}
//wwlog.Printf(wwlog.INFO, "PrevHostFile is %s\n", replace.PrevHostFile)
w.Close()
nodes, _ := n.FindAllNodes()
replace.AllNodes = nodes
replace.Ipaddr = controller.Ipaddr
replace.Fqdn = controller.Fqdn
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 {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer w.Close()
err = tmpl.Execute(w, replace)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
} else {
err = tmpl.Execute(os.Stdout, replace)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
return nil
} }

View File

@@ -4,18 +4,18 @@ import "github.com/spf13/cobra"
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
Use: "hosts [OPTIONS]", Use: "hosts [OPTIONS]",
Short: "Update the /etc/hosts file", Short: "Update the /etc/hosts file",
Long: "Write out the /etc/hosts file based on the Warewulf template (hosts.tmpl) in the\n" + Long: "Write out the /etc/hosts file based on the Warewulf template (hosts.tmpl) in the\n" +
"Warewulf configuration directory.", "Warewulf configuration directory.",
RunE: CobraRunE, RunE: CobraRunE,
} }
setShow bool SetShow bool
) )
func init() { func init() {
baseCmd.PersistentFlags().BoolVarP(&setShow, "show", "s", false, "Show configuration (don't update)") baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.

View File

@@ -1,10 +1,75 @@
package nfs package nfs
import ( import (
"github.com/hpcng/warewulf/internal/pkg/configure" "fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
return configure.Configure("NFS", setShow) return Configure(SetShow)
}
func Configure(show bool) error {
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if controller.Network == "" {
wwlog.Printf(wwlog.ERROR, "Network must be defined in warewulf.conf to configure NFS\n")
os.Exit(1)
}
if controller.Netmask == "" {
wwlog.Printf(wwlog.ERROR, "Netmask must be defined in warewulf.conf to configure NFS\n")
os.Exit(1)
}
if !SetShow {
if controller.Nfs.Enabled {
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)
os.Exit(1)
}
defer exports.Close()
fmt.Fprintf(exports, "# This file was written by Warewulf (wwctl configure nfs)\n")
for _, export := range controller.Nfs.ExportsExtended {
fmt.Fprintf(exports, "%s %s/%s(%s)\n", export.Path, controller.Network, controller.Netmask, export.ExportOptions)
}
fmt.Printf("Enabling and restarting the NFS services\n")
if controller.Nfs.SystemdName == "" {
err := util.SystemdStart("nfs-server")
if err != nil {
return errors.Wrap(err, "failed to start nfs-server")
}
} else {
err := util.SystemdStart(controller.Nfs.SystemdName)
if err != nil {
return errors.Wrap(err, "failed to start")
}
}
}
} else {
fmt.Printf("/etc/exports:\n")
for _, export := range controller.Nfs.ExportsExtended {
fmt.Printf("%s %s/%s\n", export.Path, controller.Network, controller.Netmask)
}
fmt.Printf("\n")
}
return nil
} }

View File

@@ -5,17 +5,17 @@ import "github.com/spf13/cobra"
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
Use: "nfs [OPTIONS]", Use: "nfs [OPTIONS]",
Short: "Manage and initialize NFS", Short: "Manage and initialize NFS",
Long: "NFS is an optional dependent service of Warewulf, this tool will automatically\n" + Long: "NFS is an optional dependent service of Warewulf, this tool will automatically\n" +
"configure NFS as per the configuration in the warewulf.conf file.", "configure NFS as per the configuration in the warewulf.conf file.",
RunE: CobraRunE, RunE: CobraRunE,
} }
setShow bool SetShow bool
) )
func init() { func init() {
baseCmd.PersistentFlags().BoolVarP(&setShow, "show", "s", false, "Show configuration (don't update)") baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.

View File

@@ -1,6 +1,7 @@
package configure package configure
import ( import (
"fmt"
"os" "os"
"github.com/hpcng/warewulf/internal/app/wwctl/configure/dhcp" "github.com/hpcng/warewulf/internal/app/wwctl/configure/dhcp"
@@ -8,20 +9,20 @@ import (
"github.com/hpcng/warewulf/internal/app/wwctl/configure/nfs" "github.com/hpcng/warewulf/internal/app/wwctl/configure/nfs"
"github.com/hpcng/warewulf/internal/app/wwctl/configure/ssh" "github.com/hpcng/warewulf/internal/app/wwctl/configure/ssh"
"github.com/hpcng/warewulf/internal/app/wwctl/configure/tftp" "github.com/hpcng/warewulf/internal/app/wwctl/configure/tftp"
"github.com/hpcng/warewulf/internal/pkg/configure" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
Use: "configure [OPTIONS]", Use: "configure [OPTIONS]",
Short: "Manage system services", Short: "Manage system services",
Long: "This application allows you to manage and initialize Warewulf dependent system\n" + Long: "This application allows you to manage and initialize Warewulf dependent system\n" +
"services based on the configuration in the warewulf.conf file.", "services based on the configuration in the warewulf.conf file.",
RunE: CobraRunE, RunE: CobraRunE,
} }
allFunctions bool SetDoAll bool
) )
func init() { func init() {
@@ -31,7 +32,7 @@ func init() {
baseCmd.AddCommand(ssh.GetCommand()) baseCmd.AddCommand(ssh.GetCommand())
baseCmd.AddCommand(nfs.GetCommand()) baseCmd.AddCommand(nfs.GetCommand())
baseCmd.PersistentFlags().BoolVarP(&allFunctions, "all", "a", false, "Configure all services") baseCmd.PersistentFlags().BoolVarP(&SetDoAll, "all", "a", false, "Configure all services")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.
@@ -40,17 +41,44 @@ func GetCommand() *cobra.Command {
} }
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
var err error if SetDoAll {
if allFunctions { fmt.Printf("################################################################################\n")
for _, s := range [5]string{"DHPC", "hosts", "NFS", "SSH", "TFTP"} { fmt.Printf("Configuring: DHCP\n")
err = configure.Configure(s, false) err := dhcp.Configure(false)
if err != nil { if err != nil {
os.Exit(1) return errors.Wrap(err, "failed to configure dhcp")
} }
fmt.Printf("################################################################################\n")
fmt.Printf("Configuring: TFTP\n")
err = tftp.Configure(false)
if err != nil {
return errors.Wrap(err, "failed to configure tftp")
}
fmt.Printf("################################################################################\n")
fmt.Printf("Configuring: /etc/hosts\n")
err = hosts.Configure(false)
if err != nil {
return errors.Wrap(err, "failed to configure hosts")
}
fmt.Printf("################################################################################\n")
fmt.Printf("Configuring: NFS\n")
err = nfs.Configure(false)
if err != nil {
return errors.Wrap(err, "failed to configure nfs")
}
fmt.Printf("################################################################################\n")
fmt.Printf("Configuring: SSH\n")
err = ssh.Configure(false)
if err != nil {
return errors.Wrap(err, "failed to configure ssh")
} }
} else { } else {
_ = cmd.Help() //nolint:errcheck
cmd.Help()
os.Exit(0) os.Exit(0)
} }

View File

@@ -1,10 +1,99 @@
package ssh package ssh
import ( import (
"github.com/hpcng/warewulf/internal/pkg/configure" "fmt"
"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"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
return configure.Configure("SSH", setShow) return Configure(SetShow)
}
func Configure(show bool) error {
if os.Getuid() == 0 {
fmt.Printf("Updating system keys\n")
wwkeydir := path.Join(buildconfig.SYSCONFDIR(), "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(wwkeydir + "ssh_host_rsa_key") {
fmt.Printf("Setting up key: ssh_host_rsa_key\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")
}
} else {
fmt.Printf("Skipping, key already exists: ssh_host_rsa_key\n")
}
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", wwkeydir+"ssh_host_dsa_key", "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
} else {
fmt.Printf("Skipping, key already exists: ssh_host_dsa_key\n")
}
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", wwkeydir+"ssh_host_ecdsa_key", "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
} else {
fmt.Printf("Skipping, key already exists: ssh_host_ecdsa_key\n")
}
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", wwkeydir+"ssh_host_ed25519_key", "-C", "", "-N", "")
if err != nil {
return errors.Wrap(err, "failed to exec ssh-keygen command")
}
} else {
fmt.Printf("Skipping, key already exists: ssh_host_ed25519_key\n")
}
} else {
fmt.Printf("Updating user's keys\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

@@ -5,18 +5,18 @@ import "github.com/spf13/cobra"
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
Use: "ssh [OPTIONS]", Use: "ssh [OPTIONS]",
Short: "Manage and initialize SSH", Short: "Manage and initialize SSH",
Long: "SSH is an optionally dependent service for Warewulf, this tool will automatically\n" + Long: "SSH is an optionally dependent service for Warewulf, this tool will automatically\n" +
"setup the ssh keys nodes using the 'default' system overlay as well as user owned\n" + "setup the ssh keys nodes using the 'default' system overlay as well as user owned\n" +
"keys.", "keys.",
RunE: CobraRunE, RunE: CobraRunE,
} }
setShow bool SetShow bool
) )
func init() { func init() {
baseCmd.PersistentFlags().BoolVarP(&setShow, "show", "s", false, "Show configuration (don't update)") baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.

View File

@@ -1,10 +1,70 @@
package tftp package tftp
import ( import (
"github.com/hpcng/warewulf/internal/pkg/configure" "fmt"
"os"
"path"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/staticfiles"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func CobraRunE(cmd *cobra.Command, args []string) error { func CobraRunE(cmd *cobra.Command, args []string) error {
return configure.Configure("TFTP", setShow) return Configure(SetShow)
}
func Configure(show bool) error {
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if buildconfig.TFTPDIR() == "" {
wwlog.Printf(wwlog.ERROR, "Tftp root directory is not configured by build\n")
os.Exit(1)
}
err = os.MkdirAll(path.Join(buildconfig.TFTPDIR(), "warewulf"), 0755)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if !show {
fmt.Printf("Writing PXE files to: %s\n", path.Join(buildconfig.TFTPDIR(), "warewulf"))
err = staticfiles.WriteData("files/tftp/x86.efi", path.Join(buildconfig.TFTPDIR(), "warewulf/x86.efi"))
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
err = staticfiles.WriteData("files/tftp/i386.efi", path.Join(buildconfig.TFTPDIR(), "warewulf/i386.efi"))
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
err = staticfiles.WriteData("files/tftp/i386.kpxe", path.Join(buildconfig.TFTPDIR(), "warewulf/i386.kpxe"))
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
err = staticfiles.WriteData("files/tftp/arm64.efi", path.Join(buildconfig.TFTPDIR(), "warewulf/arm64.efi"))
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
fmt.Printf("Enabling and restarting the TFTP services\n")
err = util.SystemdStart(controller.Tftp.SystemdName)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
return nil
} }

View File

@@ -5,17 +5,17 @@ import "github.com/spf13/cobra"
var ( var (
baseCmd = &cobra.Command{ baseCmd = &cobra.Command{
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
Use: "tftp [OPTIONS]", Use: "tftp [OPTIONS]",
Short: "Manage and initialize TFTP", Short: "Manage and initialize TFTP",
Long: "TFTP is a dependent service of Warewulf, this tool will enable the tftp services\n" + Long: "TFTP is a dependent service of Warewulf, this tool will enable the tftp services\n" +
"on your Warewulf master.", "on your Warewulf master.",
RunE: CobraRunE, RunE: CobraRunE,
} }
setShow bool SetShow bool
) )
func init() { func init() {
baseCmd.PersistentFlags().BoolVarP(&setShow, "show", "s", false, "Show configuration (don't update)") baseCmd.PersistentFlags().BoolVarP(&SetShow, "show", "s", false, "Show configuration (don't update)")
} }
// GetRootCommand returns the root cobra.Command for the application. // GetRootCommand returns the root cobra.Command for the application.

View File

@@ -6,7 +6,6 @@ var (
bindir string = "UNDEF" bindir string = "UNDEF"
sysconfdir string = "UNDEF" sysconfdir string = "UNDEF"
localstatedir string = "UNDEF" localstatedir string = "UNDEF"
sharedstatedir string = "UNDEF"
srvdir string = "UNDEF" srvdir string = "UNDEF"
tftpdir string = "UNDEF" tftpdir string = "UNDEF"
firewallddir string = "UNDEF" firewallddir string = "UNDEF"
@@ -14,9 +13,9 @@ var (
wwoverlaydir string = "UNDEF" wwoverlaydir string = "UNDEF"
wwchrootdir string = "UNDEF" wwchrootdir string = "UNDEF"
wwprovisiondir string = "UNDEF" wwprovisiondir string = "UNDEF"
wwclientdir string = "UNDEF"
version string = "UNDEF" version string = "UNDEF"
release string = "UNDEF" release string = "UNDEF"
wwclientloc string = "UNDEF"
) )
func BINDIR() string { func BINDIR() string {
@@ -79,12 +78,7 @@ func RELEASE() string {
return release return release
} }
func WWCLIENTDIR() string { func WWCLIENTLOC() string {
wwlog.Printf(wwlog.DEBUG, "WWPROVISIONDIR = '%s'\n", wwclientdir) wwlog.Printf(wwlog.DEBUG, "WWCLIENTLOC = '%s'\n", wwclientloc)
return wwclientdir return wwclientloc
}
func SHAREDSTATEDIR() string {
wwlog.Printf(wwlog.DEBUG, "SHAREDSTATEDIR = '%s'\n", sharedstatedir)
return sharedstatedir
} }

View File

@@ -4,7 +4,6 @@ func init() {
bindir = "@BINDIR@" bindir = "@BINDIR@"
sysconfdir = "@SYSCONFDIR@" sysconfdir = "@SYSCONFDIR@"
localstatedir = "@LOCALSTATEDIR@" localstatedir = "@LOCALSTATEDIR@"
sharedstatedir = "@SHAREDSTATEDIR@"
srvdir = "@SRVDIR@" srvdir = "@SRVDIR@"
tftpdir = "@TFTPDIR@" tftpdir = "@TFTPDIR@"
firewallddir = "@FIREWALLDDIR@" firewallddir = "@FIREWALLDDIR@"
@@ -12,7 +11,7 @@ func init() {
wwoverlaydir = "@WWOVERLAYDIR@" wwoverlaydir = "@WWOVERLAYDIR@"
wwchrootdir = "@WWCHROOTDIR@" wwchrootdir = "@WWCHROOTDIR@"
wwprovisiondir = "@WWPROVISIONDIR@" wwprovisiondir = "@WWPROVISIONDIR@"
wwclientdir = "@WWCLIENTDIR@"
version = "@VERSION@" version = "@VERSION@"
release = "@RELEASE@" release = "@RELEASE@"
wwclientloc = "@WWCLIENTLOC"
} }

View File

@@ -1,32 +0,0 @@
package configure
import (
"fmt"
"github.com/pkg/errors"
)
func Configure(s string, v bool) error {
if !v {
fmt.Printf("################################################################################\n")
fmt.Printf("Configuring: %s\n", s)
}
var err error
switch s {
case "DHCP":
err = configureDHCP(v)
case "hosts":
err = configureHosts(v)
case "NFS":
err = configureNFS(v)
case "SSH":
err = configureSSH(v)
case "TFTP":
err = configureTFTP(v)
}
if err != nil {
return errors.Wrap(err, "Failed to configure "+s)
}
return nil
}

View File

@@ -1,139 +0,0 @@
package configure
import (
"fmt"
"os"
"path"
"strconv"
"strings"
"text/template"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
)
type dhcpTemplate struct {
Ipaddr string
Port string
RangeStart string
RangeEnd string
Network string
Netmask string
Nodes []node.NodeInfo
}
func configureDHCP(show bool) error {
var d dhcpTemplate
var templateFile string
nodeDB, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if controller.Ipaddr == "" {
wwlog.Printf(wwlog.ERROR, "The Warewulf IP Address is not properly configured\n")
os.Exit(1)
}
if controller.Netmask == "" {
wwlog.Printf(wwlog.ERROR, "The Warewulf Netmask is not properly configured\n")
os.Exit(1)
}
if !controller.Dhcp.Enabled {
wwlog.Printf(wwlog.INFO, "This system is not configured as a Warewulf DHCP controller\n")
os.Exit(1)
}
if controller.Dhcp.RangeStart == "" {
wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range start`\n")
os.Exit(1)
}
if controller.Dhcp.RangeEnd == "" {
wwlog.Printf(wwlog.ERROR, "Configuration is not defined: `dhcpd range end`\n")
os.Exit(1)
}
if controller.Dhcp.ConfigFile == "" {
controller.Dhcp.ConfigFile = "/etc/dhcp/dhcpd.conf"
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not find all controllers: %s\n", err)
os.Exit(1)
}
d.Nodes = append(d.Nodes, nodes...)
templateFile = dhcpTemplateFile(controller.Dhcp.Template)
tmpl, err := template.New(path.Base(templateFile)).ParseFiles(templateFile)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
d.Ipaddr = controller.Ipaddr
d.Port = strconv.Itoa(controller.Warewulf.Port)
d.Network = controller.Network
d.Netmask = controller.Netmask
d.RangeStart = controller.Dhcp.RangeStart
d.RangeEnd = controller.Dhcp.RangeEnd
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 {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer configWriter.Close()
err = tmpl.Execute(configWriter, d)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
fmt.Printf("Enabling and restarting the DHCP services\n")
err = util.SystemdStart(controller.Dhcp.SystemdName)
if err != nil {
return errors.Wrap(err, "failed to start")
}
} else {
err = tmpl.Execute(os.Stdout, d)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
return nil
}
// dhcpTemplateFile returns the path of the warewulf dhcp template given controller.Dhcp.Template.
func dhcpTemplateFile(controllerDhcpTemplate string) (templateFile string) {
if controllerDhcpTemplate == "" {
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")
} else {
if strings.HasPrefix(controllerDhcpTemplate, "/") {
templateFile = controllerDhcpTemplate
} else {
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/"+controllerDhcpTemplate+"-dhcpd.conf")
}
}
return
}

View File

@@ -1,110 +0,0 @@
package configure
import (
"bytes"
"os"
"path"
"text/template"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
type hostsTemplate struct {
PrevHostFile string
Ipaddr string
Fqdn string
AllNodes []node.NodeInfo
}
func configureHosts(show bool) error {
var replace hostsTemplate
if !util.IsFile(path.Join(buildconfig.SYSCONFDIR(), "warewulf/hosts.tmpl")) {
wwlog.Printf(wwlog.WARN, "Template not found, not updating host file\n")
return nil
}
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
n, err := node.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not open node configuration: %s\n", err)
os.Exit(1)
}
tmpl, err := template.ParseFiles(path.Join(buildconfig.SYSCONFDIR(), "warewulf/hosts.tmpl"))
if err != nil {
wwlog.Printf(wwlog.ERROR, "Could not parse hosts template: %s\n", err)
os.Exit(1)
}
replace.PrevHostFile = ""
w, err := os.Open("/etc/hosts")
if err != nil {
wwlog.Printf(wwlog.WARN, "%s\n", err)
} else {
// if /etc/hosts.ww does not exist, backup /etc/hosts to /etc/hosts.wwbackup
if !util.IsFile("/etc/hosts.wwbackup") {
err = util.CopyFile("/etc/hosts", "/etc/hosts.wwbackup")
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
}
}
// read all lines before the # warewulf comment and put into PrevHostFile template variable
lines, _ := util.ReadFile("/etc/hosts")
if lines != nil {
var buffer bytes.Buffer
for _, line := range lines {
//wwlog.Printf(wwlog.INFO, "Reading line: %s\n", line)
if util.ValidString(line, "^#.*maintained by warewulf") {
break
}
buffer.WriteString(line)
buffer.WriteString("\n")
}
replace.PrevHostFile = buffer.String()
}
}
w.Close()
nodes, _ := n.FindAllNodes()
replace.AllNodes = nodes
replace.Ipaddr = controller.Ipaddr
replace.Fqdn = controller.Fqdn
if !show {
// 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 {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
defer w.Close()
err = tmpl.Execute(w, replace)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
} else {
err = tmpl.Execute(os.Stdout, replace)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
}
return nil
}

View File

@@ -1,69 +0,0 @@
package configure
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
)
func configureNFS(show bool) error {
controller, err := warewulfconf.New()
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
if controller.Network == "" {
wwlog.Printf(wwlog.ERROR, "Network must be defined in warewulf.conf to configure NFS\n")
os.Exit(1)
}
if controller.Netmask == "" {
wwlog.Printf(wwlog.ERROR, "Netmask must be defined in warewulf.conf to configure NFS\n")
os.Exit(1)
}
if !show {
if controller.Nfs.Enabled {
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)
os.Exit(1)
}
defer exports.Close()
fmt.Fprintf(exports, "# This file was written by Warewulf (wwctl configure nfs)\n")
for _, export := range controller.Nfs.ExportsExtended {
fmt.Fprintf(exports, "%s %s/%s(%s)\n", export.Path, controller.Network, controller.Netmask, export.ExportOptions)
}
fmt.Printf("Enabling and restarting the NFS services\n")
if controller.Nfs.SystemdName == "" {
err := util.SystemdStart("nfs-server")
if err != nil {
return errors.Wrap(err, "failed to start nfs-server")
}
} else {
err := util.SystemdStart(controller.Nfs.SystemdName)
if err != nil {
return errors.Wrap(err, "failed to start")
}
}
}
} else {
fmt.Printf("/etc/exports:\n")
for _, export := range controller.Nfs.ExportsExtended {
fmt.Printf("%s %s/%s\n", export.Path, controller.Network, controller.Netmask)
}
fmt.Printf("\n")
}
return nil
}

View File

@@ -1,72 +0,0 @@
package configure
import (
"fmt"
"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"
)
func configureSSH(show bool) error {
if !show {
if os.Getuid() == 0 {
fmt.Printf("Updating system keys\n")
wwkeydir := path.Join(buildconfig.SYSCONFDIR(), "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)
}
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 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)
}
} else {
fmt.Printf("'ssh -s' is not yet implemented.\n")
}
return nil
}

View File

@@ -1,51 +0,0 @@
package configure
import (
"fmt"
"os"
"path"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/staticfiles"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
var tftpdir string = path.Join(buildconfig.TFTPDIR(), "warewulf")
func configureTFTP(show bool) error {
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)
return err
}
}
fmt.Printf("Enabling and restarting the TFTP services\n")
err = util.SystemdStart(controller.Tftp.SystemdName)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
return err
}
} else {
fmt.Printf("'tftp -s' is not yet implemented.\n")
}
return nil
}

View File

@@ -5,7 +5,7 @@ After=local-fs.target
[Service] [Service]
Type=notify Type=notify
ExecStart=@WWCLIENTDIR@/wwclient ExecStart=/warewulf/bin/wwclient
ExecReload=/bin/kill -s SIGHUP "$MAINPID" ExecReload=/bin/kill -s SIGHUP "$MAINPID"
PIDFile=/var/run/wwclient.pid PIDFile=/var/run/wwclient.pid
TimeoutSec=60 TimeoutSec=60

View File

@@ -6,8 +6,8 @@
# Edit at your own risk! DANGER DANGER. # Edit at your own risk! DANGER DANGER.
if test -f "@WWCLIENTDIR@/config"; then if test -f "/warewulf/config"; then
. @WWCLIENTDIR@/config . /warewulf/config
else else
echo "ERROR: Warewulf configuration file not found... rebooting in 1 minute" echo "ERROR: Warewulf configuration file not found... rebooting in 1 minute"
sleep 60 sleep 60
@@ -24,7 +24,7 @@ mount -t devtmpfs devtmpfs /dev
mount -t sysfs sysfs /sys mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /run mount -t tmpfs tmpfs /run
chmod 755 @WWCLIENTDIR@/wwinit chmod 755 /warewulf/wwinit
echo "Checking Rootfs type" echo "Checking Rootfs type"
ROOTFSTYPE=`stat -f -c "%T" /` ROOTFSTYPE=`stat -f -c "%T" /`
@@ -32,7 +32,7 @@ ROOTFSTYPE=`stat -f -c "%T" /`
if test "$WWROOT" = "initramfs"; then if test "$WWROOT" = "initramfs"; then
echo "Provisioned to default initramfs file system: $ROOTFSTYPE" echo "Provisioned to default initramfs file system: $ROOTFSTYPE"
echo "Calling WW Init" echo "Calling WW Init"
exec @WWCLIENTDIR@/wwinit exec /warewulf/wwinit
elif test "$WWROOT" = "tmpfs"; then elif test "$WWROOT" = "tmpfs"; then
if test "$ROOTFSTYPE" = "tmpfs"; then if test "$ROOTFSTYPE" = "tmpfs"; then
echo "ERROR: Switching the root file system requires the kernel argument: 'rootfstype=ramfs'" echo "ERROR: Switching the root file system requires the kernel argument: 'rootfstype=ramfs'"
@@ -44,7 +44,7 @@ elif test "$WWROOT" = "tmpfs"; then
tar -cf - --exclude ./proc --exclude ./sys --exclude ./dev --exclude ./newroot . | tar -xf - -C /newroot tar -cf - --exclude ./proc --exclude ./sys --exclude ./dev --exclude ./newroot . | tar -xf - -C /newroot
mkdir /newroot/proc /newroot/dev /newroot/sys /newroot/run 2>/dev/null mkdir /newroot/proc /newroot/dev /newroot/sys /newroot/run 2>/dev/null
echo "Calling switch_root and invoking WW Init" echo "Calling switch_root and invoking WW Init"
exec /sbin/switch_root /newroot @WWCLIENTDIR@/wwinit exec /sbin/switch_root /newroot /warewulf/wwinit
fi fi
else else
echo "ERROR: Unknown Warewulf Root file system: $WWROOT" echo "ERROR: Unknown Warewulf Root file system: $WWROOT"

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
. @WWCLIENTDIR@/config . /warewulf/config
echo "Bringing up lo:127.0.0.1" echo "Bringing up lo:127.0.0.1"
/sbin/ip link set dev lo up /sbin/ip link set dev lo up

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
. @WWCLIENTDIR@/config . /warewulf/config
export PATH=/usr/bin:/bin:/usr/sbin:/sbin export PATH=/usr/bin:/bin:/usr/sbin:/sbin

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
. @WWCLIENTDIR@/config . /warewulf/config
# This will eventually be optional # This will eventually be optional
if true; then if true; then

View File

@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
. @WWCLIENTDIR@/config . /warewulf/config
# Only start if the systemd is no available # Only start if the systemd is no available
test -e /usr/lib/systemd/systemd && exit 0 test -e /usr/lib/systemd/systemd && exit 0
echo "Starting wwclient" echo "Starting wwclient"
nohup @WWCLIENTDIR@/wwclient >/var/log/wwclient.log 2>&1 </dev/null & nohup /warewulf/bin/wwclient >/var/log/wwclient.log 2>&1 </dev/null &

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
. @WWCLIENTDIR@/config . /warewulf/config
if test -z "$WWROOT"; then if test -z "$WWROOT"; then
echo "Skipping SELinux configuration: Warewulf Root device not set" echo "Skipping SELinux configuration: Warewulf Root device not set"

View File

@@ -2,9 +2,9 @@
echo "Hello from WWINIT" echo "Hello from WWINIT"
. @WWCLIENTDIR@/config . /warewulf/config
for i in @WWCLIENTDIR@/init.d/*; do for i in /warewulf/init.d/*; do
NAME=`basename $i` NAME=`basename $i`
echo "Launching: $NAME" echo "Launching: $NAME"
sh "$i" sh "$i"

View File

@@ -1,15 +1,12 @@
%define debug_package %{nil}
%if 0%{?sle_version}
%global tftpdir /srv/tftpboot
%global srvdir /srv
%else
# Assume Fedora-based OS if not SUSE-based
%global tftpdir /var/lib/tftpboot
%global srvdir %{_sharedstatedir}
%endif
%global wwgroup warewulf %global wwgroup warewulf
%if 0%{?sle_version}
%global tftpdir "/srv/tftpboot"
%global srvdir "/srv"
%else
%global tftpdir "/var/lib/tftpboot"
%global srvdir "%{_localstatedir}/warewulf/srv"
%endif
%define debug_package %{nil}
Name: warewulf Name: warewulf
Summary: A provisioning system for large clusters of bare metal and/or virtual systems Summary: A provisioning system for large clusters of bare metal and/or virtual systems
@@ -30,18 +27,17 @@ Conflicts: warewulf-ipmi
BuildRequires: make BuildRequires: make
%if 0%{?sle_version} %if 0%{?rhel}
BuildRequires: systemd-rpm-macros
BuildRequires: go
BuildRequires: firewall-macros
Requires: tftp
Requires: nfs-kernel-server
%else
BuildRequires: systemd BuildRequires: systemd
BuildRequires: golang BuildRequires: golang
BuildRequires: firewalld-filesystem
Requires: tftp-server Requires: tftp-server
Requires: nfs-utils Requires: nfs-utils
%else
# sle_version
BuildRequires: systemd-rpm-macros
BuildRequires: go
Requires: tftp
Requires: nfs-kernel-server
%endif %endif
%if 0%{?rhel} >= 8 || 0%{?sle_version} %if 0%{?rhel} >= 8 || 0%{?sle_version}
@@ -61,36 +57,30 @@ system for large clusters of bare metal and/or virtual systems.
%build %build
make genconfig \ make genconfig PREFIX=/usr \
PREFIX=%{_prefix} \ SRVDIR=%{srvdir} \
BINDIR=%{_bindir} \ LOCALSTATEDIR=%{_localstatedir} \
SYSCONFDIR=%{_sysconfdir} \ SYSCONFDIR=%{_sysconfdir} \
DATADIR=%{_datadir} \ DATADIR=%{_datadir} \
LOCALSTATEDIR=%{_localstatedir} \
SHAREDSTATEDIR=%{_sharedstatedir} \
MANDIR=%{_mandir} \ MANDIR=%{_mandir} \
INFODIR=%{_infodir} \ BINDIR=%{_bindir} \
DOCDIR=%{_docdir} \
SRVDIR=%{srvdir} \
TFTPDIR=%{tftpdir} \ TFTPDIR=%{tftpdir} \
SYSTEMDDIR=%{_unitdir} \ SYSTEMDDIR=%{_unitdir} \
BASHCOMPDIR=/etc/bash_completion.d/ \ MANDIR=%{_mandir} \
FIREWALLDDIR=/usr/lib/firewalld/services \ BASH_COMPLETION=/etc/bash_completion.d/ \
WWCLIENTDIR=%{_libexecdir}/warewulf FIREWALLDDIR=/usr/lib/firewalld/services
make
make
%install %install
make install DESTDIR=%{buildroot} make install DESTDIR=%{buildroot}
%pre %pre
getent group %{wwgroup} >/dev/null || groupadd -r %{wwgroup} getent group %{wwgroup} >/dev/null || groupadd -r %{wwgroup}
%post %post
%systemd_post warewulfd.service %systemd_post warewulfd.service
%firewalld_reload
%preun %preun
@@ -99,34 +89,26 @@ getent group %{wwgroup} >/dev/null || groupadd -r %{wwgroup}
%postun %postun
%systemd_postun_with_restart warewulfd.service %systemd_postun_with_restart warewulfd.service
%firewalld_reload
%files %files
%defattr(-, root, %{wwgroup}) %defattr(-, root, %{wwgroup})
%dir %{_sysconfdir}/warewulf %dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/warewulf/* %config(noreplace) %{_sysconfdir}/%{name}/*
%config(noreplace) %attr(0640,-,-) %{_sysconfdir}/warewulf/nodes.conf %config(noreplace) %attr(0640,-,-) %{_sysconfdir}/%{name}/nodes.conf
%{_sysconfdir}/bash_completion.d/warewulf %{_sysconfdir}/bash_completion.d/warewulf
%dir %{_sharedstatedir}/warewulf %dir %{_localstatedir}/warewulf
%{_sharedstatedir}/warewulf/chroots %{_localstatedir}/warewulf/chroots
%{_sharedstatedir}/warewulf/overlays %{_localstatedir}/warewulf/overlays
%{srvdir}/warewulf %{srvdir}
%attr(-, root, root) %{_bindir}/wwctl %attr(-, root, root) %{_bindir}/wwctl
%attr(-, root, root) %{_prefix}/lib/firewalld/services/warewulf.xml %attr(-, root, root) %{_prefix}/lib/firewalld/services/warewulf.xml
%attr(-, root, root) %{_unitdir}/warewulfd.service %attr(-, root, root) %{_unitdir}/warewulfd.service
%attr(-, root, root) %{_mandir}/man1/wwctl* %attr(-, root, root) %{_mandir}/man1/wwctl*
%license %{_docdir}/warewulf/LICENSE.md
%changelog %changelog
* Wed Jan 26 2022 Jeremy Siadal <jeremy.c.siadal@intel.com> - 4.2.0-1
- Add license install
- Updates for RH and SUSE RPM guidelines
* Sat Jan 15 2022 Gregory Kurtzer <gmkurtzer@gmail.com> - 4.2.0-1 * Sat Jan 15 2022 Gregory Kurtzer <gmkurtzer@gmail.com> - 4.2.0-1
- Integrated genconfig Make options - Integrated genconfig Make options
- Cleaned up SPEC to use default RPM macros - Cleaned up SPEC to use default RPM macros