forked from syntaxerrormmm/paperms
Primo script funzionante.
This commit is contained in:
parent
908610abcc
commit
103e7b3032
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Virtualenv
|
||||||
|
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
|
||||||
|
.Python
|
||||||
|
[Bb]in
|
||||||
|
[Ii]nclude
|
||||||
|
[Ll]ib
|
||||||
|
[Ll]ib64
|
||||||
|
[Ll]ocal
|
||||||
|
[Ss]cripts
|
||||||
|
[Ss]hare
|
||||||
|
pyvenv.cfg
|
||||||
|
.venv
|
||||||
|
pip-selfcheck.json
|
72
pulseaudiomgr.py
Normal file
72
pulseaudiomgr.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import grp
|
||||||
|
import re
|
||||||
|
from subprocess import check_output
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
|
class UpdateGrp:
|
||||||
|
|
||||||
|
def __init__(self, leftname = "domain users", rightname = "pulse"):
|
||||||
|
"""Confronts members of the LHS group with the members of the RHS group. LHS group defaults to "domain users"."""
|
||||||
|
self.leftname = leftname
|
||||||
|
self.rightname = rightname
|
||||||
|
self.leftmembers = grp.getgrnam(self.leftname)[3]
|
||||||
|
self.rightmembers = grp.getgrnam(self.rightname)[3]
|
||||||
|
|
||||||
|
# Since there is also a local user already created on the machine but
|
||||||
|
# it is not a domain user, we will add it to leftmembers
|
||||||
|
self.leftmembers.append("bglug")
|
||||||
|
|
||||||
|
self.to_add = list(set(self.leftmembers) - set(self.rightmembers))
|
||||||
|
self.to_remove = list(set(self.rightmembers) - set(self.leftmembers))
|
||||||
|
|
||||||
|
def update_rhs(self):
|
||||||
|
"""Updates the RHS group members to be equal to the LHS group members."""
|
||||||
|
# If RHS is a local group
|
||||||
|
with open('/etc/group', 'r') as group:
|
||||||
|
for grp in group.readlines():
|
||||||
|
if re.match("%s:" % self.rightname, grp):
|
||||||
|
# If to_add is not empty, add each element to group
|
||||||
|
if len(self.to_add) > 0:
|
||||||
|
for user in self.to_add:
|
||||||
|
print(check_output(["gpasswd", "-a", user, self.rightname]))
|
||||||
|
|
||||||
|
# If to_remove is not empty, remove each element to group
|
||||||
|
if len(self.to_remove) > 0:
|
||||||
|
for user in self.to_remove:
|
||||||
|
print(check_output(["gpasswd", "-d", user, self.rightname]))
|
||||||
|
|
||||||
|
def update_lhs(self):
|
||||||
|
"""Updates the LHS group members to be equal to the RHS group members."""
|
||||||
|
# If LHS is a local group
|
||||||
|
with open('/etc/group', 'r') as group:
|
||||||
|
for grp in group.readline():
|
||||||
|
if re.match("%s:" % self.leftname, grp):
|
||||||
|
# If to_remove is not empty, add each element to group
|
||||||
|
if len(self.to_remove) > 0:
|
||||||
|
for user in self.to_remove:
|
||||||
|
print(check_output(["gpasswd", "-a", user, self.leftname]))
|
||||||
|
|
||||||
|
# If to_add is not empty, remove each element to group
|
||||||
|
if len(self.to_add) > 0:
|
||||||
|
for user in self.to_add:
|
||||||
|
print(check_output(["gpasswd", "-d", user, self.leftname]))
|
||||||
|
|
||||||
|
|
||||||
|
def modprint(self):
|
||||||
|
"""Debug function to print only modifications."""
|
||||||
|
print("To add:")
|
||||||
|
print(self.to_add)
|
||||||
|
print("To remove:")
|
||||||
|
print(self.to_remove)
|
||||||
|
|
||||||
|
# When run interactively
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# If the first argument is '--help' or '-h', or number of arguments less than 1 and more than 2, print help.
|
||||||
|
if len(argv) < 2 or len(argv) > 3 or argv[1] == '--help' or argv[1] == '-h':
|
||||||
|
print("Usage: %s <group1> <group2>" % argv[0])
|
||||||
|
|
||||||
|
else:
|
||||||
|
updgrp = UpdateGrp(argv[1], argv[2])
|
||||||
|
updgrp.update_rhs()
|
Loading…
x
Reference in New Issue
Block a user