diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2016-02-22 02:06:03 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2016-02-22 02:06:03 +0100 |
commit | 23472daeba30dd9946230f8e0e8652715350a3f3 (patch) | |
tree | e0d0019e1cb943f5c9c53a6f74197bbec2d342bc | |
parent | 4646aef9f05165635176015a639b44d8c4f314eb (diff) | |
download | spline-startup-23472daeba30dd9946230f8e0e8652715350a3f3.tar.gz spline-startup-23472daeba30dd9946230f8e0e8652715350a3f3.tar.bz2 spline-startup-23472daeba30dd9946230f8e0e8652715350a3f3.zip |
Add config file for user to include or exclude
-rwxr-xr-x | spline-startup | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/spline-startup b/spline-startup index 545dee9..0240a01 100755 --- a/spline-startup +++ b/spline-startup @@ -17,6 +17,29 @@ def is_root(): return os.getuid() == 0 +def _get_users(config): + config_lines = list() + if os.path.exists(config): + with open(config, 'r') as config_file: + for raw_line in config_file: + line = raw_line.strip() + if line == '' or line.startswith('#'): + continue + + config_lines.append(line.strip()) + + users = list() + for user in pwd.getpwall(): + if user.pw_uid < 1000 or user.pw_uid >= 2000: + if user.pw_name not in config_lines: + continue + elif '!' + user.pw_name in config_lines: + continue + users.append(user) + + return users + + class SplineStartup(object): def __init__(self): @@ -50,6 +73,9 @@ class SplineStartup(object): action='append', help='user to execute scripts (by default all ' 'users with 1000 <= uid < 2000 are used)') + parser.add_argument('-c', '--config', metavar='CONFIG', + help='path to config file for additional users', + default='/etc/spline-startup.conf') self.options = parser.parse_args() @@ -119,9 +145,8 @@ class SplineStartup(object): except KeyError: self._perror("Invalid user '%s'" % user) else: - for user in pwd.getpwall(): - if user.pw_uid < 1000 or user.pw_uid >= 2000: - continue + userlist = _get_users(self.options.config) + for user in userlist: self._run_scripts(user, self.options.action) |