/[gentoo-alt]/trunk/overlay/sys-devel/distcc/files/distcc-config
Gentoo

Contents of /trunk/overlay/sys-devel/distcc/files/distcc-config

Parent Directory Parent Directory | Revision Log Revision Log


Revision 832 - (show annotations) (download)
Sat Oct 15 14:32:27 2005 UTC (8 years, 11 months ago) by flameeyes
File size: 4874 byte(s)
Added distcc that does not check for useradd to work on Gentoo/FreeBSD. Also remove shadow dependency.
1 #!/usr/bin/env python
2 # Copyright 1999-2004 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-x86/sys-devel/distcc/files/distcc-config,v 1.1 2004/08/27 11:05:10 pyrania Exp $
5
6 import os, re, signal, sys, commands, pwd
7 from string import rstrip
8
9 options=[
10 '--get-hosts',
11 '--set-hosts',
12 '--get-verbose',
13 '--set-verbose',
14 '--get-log',
15 '--set-log',
16 '--install',
17 '--help',
18 '--get-env',
19 '--set-env'
20 ]
21
22 tmpcmdline=sys.argv[1:]
23 cmdline=[]
24 envfile = '/etc/env.d/02distcc'
25
26 def exithandler(foo,bar):
27 os.kill(0,signal.SIGKILL)
28 sys.exit(1)
29
30 signal.signal(signal.SIGINT,exithandler)
31
32 def isroot(ret=0):
33 if os.getuid() != 0:
34 if ret == 0:
35 print '!!!',sys.argv[:1][0],tmpcmdline[0],'must be run as root'
36 sys.exit(1)
37 else:
38 retval = 0
39 else:
40 retval = 1
41 return retval
42
43 def writeenv(var,value):
44 isroot()
45 distcc_env = []
46 distcc_env = open(envfile, 'r').readlines()
47 distcc_env_new = open(envfile, 'w')
48 for i in range(len(distcc_env)):
49 if re.compile(var+'="(.*)"').match(distcc_env[i]):
50 distcc_env[i] = var+'="'+value+'"\n'
51 distcc_env_new.write(distcc_env[i])
52 #print 'Set',var,'to:',value
53 os.popen('/usr/sbin/env-update')
54 print 'If you want to use these new settings in an existing shell,'
55 print 'you need to "source /etc/profile" to get the changes.'
56
57 def readenv(var):
58 distcc_env = open(envfile, 'r').read()
59 match = re.compile(var+'="(.*)"').search(distcc_env)
60 if match:
61 print var+'='+match.group(1)
62 else:
63 print var,'not set.'
64
65 def permissions(path,user,group):
66 for file in os.listdir(path):
67 #print 'Configuring',path+file+'...'
68 os.chown(path+file,user,group)
69
70 def installlinks(chost=''):
71 for file in ['gcc', 'cc', 'c++', 'g++']:
72 path = '/usr/lib/distcc/bin/'
73 if not chost == '':
74 file = chost+'-'+file
75 if os.path.exists('/usr/bin/'+file):
76 #print 'Creating',path+file,'symlink...'
77 if not os.path.exists(path+file):
78 os.symlink('/usr/bin/distcc',path+file)
79 #else:
80 # print 'Already exists. Skipping...'
81
82 def createdistccdir(dir):
83 if not os.path.exists(dir):
84 os.mkdir(dir)
85 os.chmod(dir, 1777)
86
87 for x in tmpcmdline:
88 if not x:
89 continue
90 if x[0:2]=="--":
91 if not x in options:
92 print "!!! Error:",x,"is an invalid option."
93 sys.exit(1)
94 else:
95 cmdline = x
96
97 if '--get-hosts' in tmpcmdline:
98 HOSTS_ENV = os.environ.get('DISTCC_HOSTS')
99 HOSTS_HOME = os.environ.get('HOME')+'/hosts'
100 if HOSTS_ENV:
101 print HOSTS_ENV
102 elif os.path.isfile(HOSTS_HOME) and os.path.getsize(HOSTS_HOME) != 0:
103 print HOSTS_HOME
104 elif os.path.exists('/etc/distcc/hosts'):
105 print rstrip(open('/etc/distcc/hosts', 'r').read())
106 else:
107 print 'No configuration file found. Setup your hosts with --set-hosts.'
108 elif '--set-hosts' in tmpcmdline:
109 if isroot(1):
110 PATH = '/etc/distcc'
111 else:
112 PATH = os.environ.get('HOME')
113 createdistccdir(PATH)
114 open(PATH+'/hosts', 'w').write(cmdline + '\n')
115 elif '--get-verbose' in tmpcmdline:
116 readenv('DISTCC_VERBOSE')
117 elif '--set-verbose' in tmpcmdline:
118 writeenv('DISTCC_VERBOSE',tmpcmdline[1])
119 elif '--get-log' in tmpcmdline:
120 readenv('DISTCC_LOG')
121 elif '--set-log' in tmpcmdline:
122 writeenv('DISTCC_LOG',tmpcmdline[1])
123 elif '--install' in tmpcmdline:
124 isroot()
125 print 'Creating',envfile+'...'
126 distcc_env = open(envfile, 'w')
127 distcc_env.write('# This file is managed by distcc-config; use it to change these settings.\n')
128 distcc_env.write('DISTCC_LOG=""\n')
129 distcc_env.write('DCCC_PATH="/usr/lib/distcc/bin"\n')
130 distcc_env.write('DISTCC_VERBOSE="0"\n')
131
132 if os.WEXITSTATUS(commands.getstatusoutput('/usr/sbin/useradd -u 240 -g daemon -s /bin/false -d /dev/null -c "distccd" distcc')[0]) == 9:
133 os.WEXITSTATUS(commands.getstatusoutput('/usr/sbin/usermod -g daemon -s /bin/false -d /dev/null -c "distccd" distcc')[0])
134
135 foobar = pwd.getpwnam('distcc')
136 user = foobar[2]
137 group = foobar[3]
138
139 makeconf = open('/etc/make.conf', 'r').read()
140 chost = re.compile('CHOST="(.*)"').search(makeconf).group(1)
141 print 'Creating symlinks...'
142 installlinks()
143 installlinks(chost)
144
145 print 'Checking permissions...'
146 permissions('/usr/lib/distcc/bin/',user,group)
147 permissions('/var/run/distccd/',user,group)
148 elif '--get-env' in tmpcmdline:
149 if len(tmpcmdline) == 1:
150 print rstrip(open(envfile, 'r').read())
151 elif len(tmpcmdline) == 2:
152 readenv(tmpcmdline[1])
153 else:
154 print '!!! Error: Specify only one variable.'
155 elif '--set-env' in tmpcmdline:
156 if len(tmpcmdline) > 2 and len(tmpcmdline) <= 3:
157 isroot()
158 writeenv(tmpcmdline[1],tmpcmdline[2])
159 else:
160 print '!!! Error: Awaiting two parameters.'
161 else:
162 print 'Usage: /usr/bin/distcc-config --set-hosts DISTCC_HOSTS | --get-hosts'
163 print ' /usr/bin/distcc-config --set-verbose { 0 | 1 } | --get-verbose'
164 print ' /usr/bin/distcc-config --set-log FILE | --get-log'
165 print ' /usr/bin/distcc-config --set-env VARIABLE VALUE | --get-env [VARIABLE]'

  ViewVC Help
Powered by ViewVC 1.1.20