From 61eae386afa109618c0565f615dc661cf117c573 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 4 Mar 2022 10:26:11 +0100 Subject: [PATCH] Just check syncuids on default --- internal/app/wwctl/container/imprt/main.go | 12 ++++++------ internal/app/wwctl/container/imprt/root.go | 4 ++-- internal/app/wwctl/container/syncuser/main.go | 2 +- internal/app/wwctl/container/syncuser/root.go | 2 ++ internal/pkg/container/util.go | 5 ++++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/internal/app/wwctl/container/imprt/main.go b/internal/app/wwctl/container/imprt/main.go index 24c465f8..8f2e6bcc 100644 --- a/internal/app/wwctl/container/imprt/main.go +++ b/internal/app/wwctl/container/imprt/main.go @@ -128,13 +128,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if err != nil { wwlog.Printf(wwlog.WARN, "Could not copy /etc/resolv.conf into container: %s\n", err) } - if !NoSyncUser { - err = container.SyncUids(name) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Error in user sync, fix error and run 'syncuser' manually: %s\n", err) - os.Exit(1) - } + + err = container.SyncUids(name, SyncUser) + if err != nil && SyncUser { + wwlog.Printf(wwlog.ERROR, "Error in user sync, fix error and run 'syncuser' manually: %s\n", err) + os.Exit(1) } + fmt.Printf("Building container: %s\n", name) err = container.Build(name, true) if err != nil { diff --git a/internal/app/wwctl/container/imprt/root.go b/internal/app/wwctl/container/imprt/root.go index ee9c960b..a5df6030 100644 --- a/internal/app/wwctl/container/imprt/root.go +++ b/internal/app/wwctl/container/imprt/root.go @@ -18,7 +18,7 @@ Imported containers are used to create bootable VNFS images.`, SetUpdate bool SetBuild bool SetDefault bool - NoSyncUser bool + SyncUser bool ) func init() { @@ -26,7 +26,7 @@ func init() { baseCmd.PersistentFlags().BoolVarP(&SetUpdate, "update", "u", false, "Update and overwrite an existing container") baseCmd.PersistentFlags().BoolVarP(&SetBuild, "build", "b", false, "Build container when after pulling") baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this container for the default profile") - baseCmd.PersistentFlags().BoolVar(&NoSyncUser, "nosyncuser", false, "Don't synchronize uis/gods from host to container") + baseCmd.PersistentFlags().BoolVar(&SyncUser, "syncuser", false, "Don't synchronize uis/gods from host to container") } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/container/syncuser/main.go b/internal/app/wwctl/container/syncuser/main.go index 6be09448..04be7b32 100644 --- a/internal/app/wwctl/container/syncuser/main.go +++ b/internal/app/wwctl/container/syncuser/main.go @@ -14,7 +14,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if !container.ValidName(containerName) { return fmt.Errorf("%s is not a valid container", containerName) } - err := container.SyncUids(containerName) + err := container.SyncUids(containerName, noSyncUser) if err != nil { wwlog.Printf(wwlog.ERROR, "Error in synchronize: %s\n", err) os.Exit(1) diff --git a/internal/app/wwctl/container/syncuser/root.go b/internal/app/wwctl/container/syncuser/root.go index 08ba2a74..eb654b55 100644 --- a/internal/app/wwctl/container/syncuser/root.go +++ b/internal/app/wwctl/container/syncuser/root.go @@ -24,9 +24,11 @@ uid/gid collision is detected. File ownerships are also changed.`, Args: cobra.MinimumNArgs(1), } + noSyncUser bool ) func init() { + baseCmd.PersistentFlags().BoolVar(&noSyncUser, "nosyncuser", false, "Don't synchronize uis/gods just check") } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/pkg/container/util.go b/internal/pkg/container/util.go index 0aaed979..e07b1cc5 100644 --- a/internal/pkg/container/util.go +++ b/internal/pkg/container/util.go @@ -98,7 +98,7 @@ type simpleUserInfo struct { /* sync the uids,gids from the host to the container */ -func SyncUids(containerName string) error { +func SyncUids(containerName string, showOnly bool) error { var userDb []completeUserInfo passwdName := "/etc/passwd" groupName := "/etc/group" @@ -163,6 +163,9 @@ func SyncUids(containerName string) error { */ } + if !showOnly { + return nil + } // create list of files which need changed ownerships in order to change them later what // avoid uid/gid collisions for idx, user := range userDb {