-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjurt-setup
executable file
·76 lines (67 loc) · 2.6 KB
/
jurt-setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python
#
# Copyright (c) 2011 Bogdano Arendartchuk <[email protected]>
#
# Written by Bogdano Arendartchuk <[email protected]>
#
# This file is part of Jurt Build Bot.
#
# Jurt Build Bot is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Jurt Build Bot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Jurt Build Bot; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
import os
from jurtlib.command import JurtCommand, CliError
from jurtlib import cmd
DESCR = """\
Helper for initial configuration.
Currently it only sets up sudoers configuration.
"""
# TODO ask for base url and try to discover distributions and automatically
# populate targets using it
SUDOERS_LINE = "%(target)s ALL=(ALL) NOPASSWD: %(command)s\n"
JURT_COMMAND = "/usr/sbin/jurt-root-command"
class Setup(JurtCommand):
descr = ""
def init_parser(self, parser):
JurtCommand.init_parser(self, parser)
parser.add_option("--user", "-u", default=None,
help="allow USER to use jurt")
def run(self):
if os.geteuid() != 0:
raise CliError, "you must invoke this program as root "\
"(see --help)"
target = None
if not os.path.exists(JURT_COMMAND):
raise CliError, ("%s does not exist, check if jurt is "
"properly installed" % (JURT_COMMAND))
path = self.config.root.sudoers
group = self.config.root.jurt_group
target = "%" + group
env = {"target": target, "command": JURT_COMMAND}
newline = SUDOERS_LINE % env
f = open(path)
contents = f.readlines()
f.close()
if not newline in contents:
print "added to %s: %s" % (path, newline)
f = open(path, "a")
f.write("\n")
f.write(newline)
f.close()
if self.opts.user:
print "adding %s to group %s" % (self.opts.user, group)
cmd.run(["/usr/sbin/usermod", "-aG", group, self.opts.user])
print "done. just be sure you are effective member of the group "\
"%s before running jurt commands" % (group)
Setup().main()