diff --git a/internal/app/wwctl/container/exec/main.go b/internal/app/wwctl/container/exec/main.go index d4237014..07d83ac8 100644 --- a/internal/app/wwctl/container/exec/main.go +++ b/internal/app/wwctl/container/exec/main.go @@ -78,16 +78,26 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } fileStat, _ = os.Stat(path.Join(containerPath, "/etc/passwd")) unixStat = fileStat.Sys().(*syscall.Stat_t) + syncuids := false if passwdTime.Before(time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec))) { - wwlog.Printf(wwlog.WARN, "/etc/passwd has been modified, maybe you want to run syncuser\n") + if NoSyncUser { + wwlog.Printf(wwlog.WARN, "/etc/passwd has been modified, maybe you want to run syncuser\n") + } + syncuids = true } wwlog.Printf(wwlog.DEBUG, "passwd: %v\n", time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec))) fileStat, _ = os.Stat(path.Join(containerPath, "/etc/group")) unixStat = fileStat.Sys().(*syscall.Stat_t) if groupTime.Before(time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec))) { - wwlog.Printf(wwlog.WARN, "/etc/group has been modified, maybe you want to run syncuser\n") + if NoSyncUser { + wwlog.Printf(wwlog.WARN, "/etc/group has been modified, maybe you want to run syncuser\n") + } + syncuids = true } wwlog.Printf(wwlog.DEBUG, "group: %v\n", time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec))) + if syncuids && !NoSyncUser { + container.SyncUids(containerName, true) + } fmt.Printf("Rebuilding container...\n") err = container.Build(containerName, false) diff --git a/internal/app/wwctl/container/exec/root.go b/internal/app/wwctl/container/exec/root.go index 913d4f79..5294b591 100644 --- a/internal/app/wwctl/container/exec/root.go +++ b/internal/app/wwctl/container/exec/root.go @@ -25,12 +25,14 @@ var ( }, FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, } - binds []string + NoSyncUser bool + binds []string ) func init() { baseCmd.AddCommand(child.GetCommand()) baseCmd.PersistentFlags().StringArrayVarP(&binds, "bind", "b", []string{}, "Bind a local path into the container (must exist)") + baseCmd.PersistentFlags().BoolVar(&NoSyncUser, "nosyncuser", 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/imprt/main.go b/internal/app/wwctl/container/imprt/main.go index 8f2e6bcc..f93c439a 100644 --- a/internal/app/wwctl/container/imprt/main.go +++ b/internal/app/wwctl/container/imprt/main.go @@ -129,8 +129,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error { wwlog.Printf(wwlog.WARN, "Could not copy /etc/resolv.conf into container: %s\n", err) } - err = container.SyncUids(name, SyncUser) - if err != nil && SyncUser { + err = container.SyncUids(name, !NoSyncUser) + if err != nil && !NoSyncUser { wwlog.Printf(wwlog.ERROR, "Error in user sync, fix error and run 'syncuser' manually: %s\n", err) os.Exit(1) } diff --git a/internal/app/wwctl/container/imprt/root.go b/internal/app/wwctl/container/imprt/root.go index a5df6030..ee9c960b 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 - SyncUser bool + NoSyncUser 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(&SyncUser, "syncuser", false, "Don't synchronize uis/gods from host to container") + baseCmd.PersistentFlags().BoolVar(&NoSyncUser, "nosyncuser", false, "Don't synchronize uis/gods from host to container") } // GetRootCommand returns the root cobra.Command for the application.