summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-02-22 02:07:38 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2016-02-22 02:07:38 +0100
commit08ab606586cd4714755edfb68dd8dbc5186c51fe (patch)
tree59a31115bf13e479e6a938e2ca3380d757dd3c6a
parentd0bdf15a2bd0bf266b07eec67385f448b3a23ce9 (diff)
parentf0f387708fb34359039fe36ed1b61f14eab6a263 (diff)
downloadspline-startup-08ab606586cd4714755edfb68dd8dbc5186c51fe.tar.gz
spline-startup-08ab606586cd4714755edfb68dd8dbc5186c51fe.tar.bz2
spline-startup-08ab606586cd4714755edfb68dd8dbc5186c51fe.zip
Merge commit '1.2' into debian
* commit '1.2': Bump version Add config file for user to include or exclude Code style Remove trailing whitespace
-rwxr-xr-xspline-startup58
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()