Just check syncuids on default

This commit is contained in:
Christian Goll
2022-03-04 10:26:11 +01:00
committed by Christian Goll
parent 5fb10130f3
commit 61eae386af
5 changed files with 15 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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