will always run syncuids on exec and import

This commit is contained in:
Christian Goll
2022-03-10 12:42:51 +01:00
committed by Christian Goll
parent 7f1636c9a9
commit db2dcbfbe2
4 changed files with 19 additions and 7 deletions

View File

@@ -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))) {
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))) {
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)

View File

@@ -25,12 +25,14 @@ var (
},
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
}
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.

View File

@@ -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)
}

View File

@@ -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.