Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rc
rabbitmq_agents
Commits
c9b0f6d5
Commit
c9b0f6d5
authored
1 year ago
by
Bo-Chun Chen
Browse files
Options
Downloads
Patches
Plain Diff
Add group manager script
parent
566ce576
No related branches found
No related tags found
1 merge request
!146
Feat group manager
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
group_manager.py
+56
-0
56 additions, 0 deletions
group_manager.py
with
56 additions
and
0 deletions
group_manager.py
0 → 100755
+
56
−
0
View file @
c9b0f6d5
#!/usr/bin/env python3
import
argparse
import
grp
import
pwd
import
sys
def
user_exists
(
username
):
try
:
pwd
.
getpwnam
(
username
)
except
KeyError
:
return
False
return
True
def
group_exists
(
groupname
):
try
:
grp
.
getgrnam
(
groupname
)
except
KeyError
:
return
False
return
True
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
Group management script
"
)
parser
.
add_argument
(
"
-g
"
,
"
--group
"
,
required
=
True
,
help
=
"
The Group to add the user(s)
"
)
parser
.
add_argument
(
"
users
"
,
metavar
=
"
USER
"
,
nargs
=
"
+
"
,
help
=
"
User(s) to be add to the group
"
,
)
args
=
parser
.
parse_args
()
exist_users
=
[]
miss
=
False
# Check if all of the users exist
for
user
in
args
.
users
:
if
not
user_exists
(
user
):
print
(
f
"
{
user
}
does not exist.
"
,
file
=
sys
.
stderr
)
miss
=
True
else
:
exist_users
.
append
(
user
)
# Check if the group exists
if
not
group_exists
(
args
.
group
):
print
(
f
"
{
args
.
group
}
does not exist.
"
,
file
=
sys
.
stderr
)
miss
=
True
if
miss
:
print
(
"
A user and/or group does not exist.
"
,
file
=
sys
.
stderr
)
print
(
"
Abort.
"
,
file
=
sys
.
stderr
)
exit
(
1
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment