|
Zbigniew Jędrzejewski-Szmek |
c56891 |
#!/usr/bin/python
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
import sys
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
def parse_sysusers_file(filename):
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
users, groups = set(), set()
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
for line in open(filename):
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
line = line.strip()
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
if not line or line.startswith('#'):
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
continue
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
words = line.split()
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
match words[0]:
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
case 'u':
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
users.add(words[1])
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
case 'g':
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
groups.add(words[1])
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
case 'm'|'r':
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
continue
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
case _:
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
assert False
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
return users, groups
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
setup_users, setup_groups = parse_sysusers_file(sys.argv[1])
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
setup_users2, setup_groups2 = parse_sysusers_file(sys.argv[2])
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
setup_users |= setup_users2
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
setup_groups |= setup_groups2
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
basic_users, basic_groups = parse_sysusers_file(sys.argv[3])
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
if d := basic_users - setup_users:
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
exit(f'We have new users: {d}')
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
if d := basic_groups - setup_groups:
|
|
Zbigniew Jędrzejewski-Szmek |
c56891 |
exit(f'We have new groups: {d}')
|