diff --git a/CHANGELOG.md b/CHANGELOG.md index 15871e58..df43f0a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `wwclient.aarch64` overlay always provides an aarch64 wwclient executable. - `wwclient.x86_64` overlay always provides an x86_64 wwclient executable. - systemd-networkd overlay with IPv6 support +- `wwctl overlay info` lists the variables used by an overlay template ### Changed @@ -49,7 +50,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added -- `wwctl overlay show -l` will now also list the used tags in a template - Initial support for EL10 using `dnsmasq` in place of `dhcpd-server`. #1974 - `make rpm` for local development rpm builds. #1974 - `wwclient --once` prompts wwclient to run once. #1226 diff --git a/internal/app/wwctl/overlay/variables/main.go b/internal/app/wwctl/overlay/info/main.go similarity index 99% rename from internal/app/wwctl/overlay/variables/main.go rename to internal/app/wwctl/overlay/info/main.go index 55fc3ec2..a531e18a 100644 --- a/internal/app/wwctl/overlay/variables/main.go +++ b/internal/app/wwctl/overlay/info/main.go @@ -1,4 +1,4 @@ -package variables +package info import ( "fmt" diff --git a/internal/app/wwctl/overlay/variables/main_test.go b/internal/app/wwctl/overlay/info/main_test.go similarity index 99% rename from internal/app/wwctl/overlay/variables/main_test.go rename to internal/app/wwctl/overlay/info/main_test.go index fc339a82..94c4ddbd 100644 --- a/internal/app/wwctl/overlay/variables/main_test.go +++ b/internal/app/wwctl/overlay/info/main_test.go @@ -1,4 +1,4 @@ -package variables +package info import ( "bytes" diff --git a/internal/app/wwctl/overlay/variables/root.go b/internal/app/wwctl/overlay/info/root.go similarity index 90% rename from internal/app/wwctl/overlay/variables/root.go rename to internal/app/wwctl/overlay/info/root.go index 6b3e2bcd..8cfa3024 100644 --- a/internal/app/wwctl/overlay/variables/root.go +++ b/internal/app/wwctl/overlay/info/root.go @@ -1,4 +1,4 @@ -package variables +package info import ( "github.com/spf13/cobra" @@ -7,10 +7,10 @@ import ( var ( baseCmd = &cobra.Command{ - Use: "variables [flags] OVERLAY_NAME FILE_PATH", + Use: "info [flags] OVERLAY_NAME FILE_PATH", Short: "Show variables for a template file in an overlay", Long: "This command will show the variables for a given template file in a given\n" + "overlay.", - Aliases: []string{"vars", "tags"}, + Aliases: []string{"vars", "tags", "information"}, Args: cobra.ExactArgs(2), RunE: CobraRunE, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { diff --git a/internal/app/wwctl/overlay/list/main.go b/internal/app/wwctl/overlay/list/main.go index 09e3f96d..d75da8ee 100644 --- a/internal/app/wwctl/overlay/list/main.go +++ b/internal/app/wwctl/overlay/list/main.go @@ -1,7 +1,9 @@ package list import ( + "os" "strconv" + "syscall" "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/table" @@ -30,7 +32,11 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error { if vars.ShowPath { locationStr = "PATH" } - t.AddHeader("OVERLAY NAME", "FILES/DIRS", locationStr) + if vars.ListLong { + t.AddHeader("PERM MODE", "UID", "GID", "OVERLAY", "FILE PATH", locationStr) + } else { + t.AddHeader("OVERLAY NAME", "FILES/DIRS", locationStr) + } for _, name := range overlays { overlay_, err := overlay.Get(name) @@ -43,21 +49,39 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error { files := util.FindFiles(overlay_.Rootfs()) wwlog.Debug("Iterating overlay rootfs: %s", overlay_.Rootfs()) - locLine := strconv.FormatBool(overlay_.IsSiteOverlay()) - if vars.ShowPath { - locLine = overlay_.Path() - } - if vars.ListContents || vars.ListLong { - var fileCount int + if vars.ListLong { for file := range files { - t.AddLine(name, files[file], locLine) - fileCount++ - } - if fileCount == 0 { - t.AddLine(name, 0, locLine) + s, err := os.Stat(overlay_.File(files[file])) + if err != nil { + wwlog.Warn("%s: %s: %s", name, files[file], err) + continue + } + fileMode := s.Mode() + perms := fileMode & os.ModePerm + sys := s.Sys() + locLine := strconv.FormatBool(overlay_.IsSiteOverlay()) + if vars.ShowPath { + locLine = overlay_.Path() + } + t.AddLine(perms, sys.(*syscall.Stat_t).Uid, sys.(*syscall.Stat_t).Gid, name, files[file], locLine) } } else { - t.AddLine(name, len(files), locLine) + locLine := strconv.FormatBool(overlay_.IsSiteOverlay()) + if vars.ShowPath { + locLine = overlay_.Path() + } + if vars.ListContents { + var fileCount int + for file := range files { + t.AddLine(name, files[file], locLine) + fileCount++ + } + if fileCount == 0 { + t.AddLine(name, 0, locLine) + } + } else { + t.AddLine(name, len(files), locLine) + } } } t.Print() diff --git a/internal/app/wwctl/overlay/root.go b/internal/app/wwctl/overlay/root.go index 7f221a30..1c7ed6d5 100644 --- a/internal/app/wwctl/overlay/root.go +++ b/internal/app/wwctl/overlay/root.go @@ -9,10 +9,10 @@ import ( "github.com/warewulf/warewulf/internal/app/wwctl/overlay/delete" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/edit" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/imprt" + "github.com/warewulf/warewulf/internal/app/wwctl/overlay/info" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/list" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/mkdir" "github.com/warewulf/warewulf/internal/app/wwctl/overlay/show" - "github.com/warewulf/warewulf/internal/app/wwctl/overlay/variables" ) var ( @@ -36,7 +36,7 @@ func init() { baseCmd.AddCommand(imprt.GetCommand()) baseCmd.AddCommand(chmod.GetCommand()) baseCmd.AddCommand(chown.GetCommand()) - baseCmd.AddCommand(variables.GetCommand()) + baseCmd.AddCommand(info.GetCommand()) } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 100f3d18..0206204d 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -330,7 +330,11 @@ func (overlay Overlay) ParseCommentVars(file string) (retMap map[string]string) re := regexp.MustCompile(`{{\s*/\*\s*(.*?):\s*(.*?)\s*\*/\s*}}`) matches := re.FindAllStringSubmatch(string(content), -1) - wwlog.Debug("matches: %v len(%d:%d)", matches, len(matches), len(matches[0])) + if len(matches) > 0 { + wwlog.Debug("matches: %v len(%d:%d)", matches, len(matches), len(matches[0])) + } else { + wwlog.Debug("matches: [] len(0)") + } for i := range matches { if len(matches[i]) > 2 { retMap[matches[i][1]] = matches[i][2] @@ -361,9 +365,15 @@ func walkParseTree(node parse.Node, vars map[string]bool) { case *parse.RangeNode: walkParseTree(n.Pipe, vars) walkParseTree(n.List, vars) + walkParseTree(n.ElseList, vars) case *parse.WithNode: walkParseTree(n.Pipe, vars) walkParseTree(n.List, vars) + walkParseTree(n.ElseList, vars) + case *parse.TemplateNode: + walkParseTree(n.Pipe, vars) + case *parse.BreakNode, *parse.ContinueNode: + // No variables to extract case *parse.PipeNode: if n != nil { for _, cmd := range n.Cmds {