From 23472daeba30dd9946230f8e0e8652715350a3f3 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 22 Feb 2016 02:06:03 +0100 Subject: Add config file for user to include or exclude --- spline-startup | 31 ++++++++++++++++++++++++++++--- 1 file 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) -- cgit v1.2.3-1-g7c22