diff options
-rwxr-xr-x | spline-startup | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/spline-startup b/spline-startup index 22b325f..72c306e 100755 --- a/spline-startup +++ b/spline-startup @@ -10,18 +10,41 @@ from subprocess import Popen, PIPE, STDOUT from pipes import quote -VERSION = '1.1' +VERSION = '1.2' 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): self.options = None - + self._parse_args() if self.options.syslog: syslog.openlog(logoption=syslog.LOG_PID) @@ -44,12 +67,15 @@ class SplineStartup(object): "but don't run them") parser.add_argument('-s', '--syslog', action='store_true', help='log to syslog and not to stderr') - + if is_root(): parser.add_argument('-u', '--user', metavar='USER', 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() @@ -84,23 +110,24 @@ class SplineStartup(object): else: return 0 - def _run_scripts(self, user, action, su=True): + def _run_scripts(self, user, action, use_su=True): self._pdebug("Running scripts for user '%s'" % user.pw_name) - dir = os.path.join(user.pw_dir, 'etc', 'rc.d') + directory = os.path.join(user.pw_dir, 'etc', 'rc.d') args = ['--arg=%s' % quote(action)] if action == 'stop': args.append('--reverse') - if not os.path.isdir(dir): + if not os.path.isdir(directory): return True - if su: + if use_su: returnvalue = self._call(['su', '-', user.pw_name, '-c', 'run-parts %s -- %s' % - (' '.join(args), quote(dir))]) + (' '.join(args), + quote(directory))]) else: - returnvalue = self._call(['run-parts'] + args + ['--', dir]) + returnvalue = self._call(['run-parts'] + args + ['--', directory]) return returnvalue == 0 @@ -118,12 +145,15 @@ 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) -if __name__ == '__main__': +def main(): app = SplineStartup() app.run() + + +if __name__ == '__main__': + main() |