MCPcopy Create free account
hub / github.com/celer-pkg/celer / removeCurrentUserFromGroup

Function removeCurrentUserFromGroup

pkgcache/cache_setup.go:564–596  ·  view source on GitHub ↗
(groupName string)

Source from the content-addressed store, hash-verified

562}
563
564func removeCurrentUserFromGroup(groupName string) error {
565 currentUser, err := currentUserForGroup()
566 if err != nil {
567 return err
568 }
569
570 groupExists := true
571 if _, err := lookupGroup(groupName); err != nil {
572 var unknownGroupError user.UnknownGroupError
573 if !errors.As(err, &unknownGroupError) {
574 return fmt.Errorf("failed to lookup %s group -> %w", groupName, err)
575 }
576 groupExists = false
577 }
578 if !groupExists {
579 return nil
580 }
581
582 groups, err := cmd.NewExecutor("", "id", "-nG", currentUser).ExecuteOutput()
583 if err != nil {
584 return fmt.Errorf("failed to get groups for %q -> %w", currentUser, err)
585 }
586 userInGroup := slices.Contains(strings.Fields(groups), groupName)
587 if !userInGroup {
588 return nil
589 }
590
591 if output, err := cmd.NewExecutor("", "gpasswd", "-d", currentUser, groupName).ExecuteOutput(); err != nil {
592 return fmt.Errorf("failed to remove %q from %q group -> %s -> %w", currentUser, groupName, output, err)
593 }
594 color.PrintHint("✔ remove %s from group %s", currentUser, groupName)
595 return nil
596}
597
598func currentUserForGroup() (string, error) {
599 candidate := os.Getenv("SUDO_USER")

Callers 1

removeSystemGroupAndUserFunction · 0.85

Calls 4

NewExecutorFunction · 0.92
PrintHintFunction · 0.92
currentUserForGroupFunction · 0.85
ExecuteOutputMethod · 0.80

Tested by

no test coverage detected