summaryrefslogtreecommitdiff
path: root/sys-devel/distcc/files/distcc-config
diff options
context:
space:
mode:
Diffstat (limited to 'sys-devel/distcc/files/distcc-config')
-rw-r--r--sys-devel/distcc/files/distcc-config148
1 files changed, 82 insertions, 66 deletions
diff --git a/sys-devel/distcc/files/distcc-config b/sys-devel/distcc/files/distcc-config
index 094307c10507..974620d107fb 100644
--- a/sys-devel/distcc/files/distcc-config
+++ b/sys-devel/distcc/files/distcc-config
@@ -1,9 +1,8 @@
#!/usr/bin/env python
-# Copyright 1999-2004 Gentoo Foundation
+# Copyright 1999-2018 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-import os, re, signal, sys, commands, pwd
-from string import rstrip
+import os, re, signal, subprocess, sys
options=[
'--get-hosts',
@@ -12,7 +11,8 @@ options=[
'--set-verbose',
'--get-log',
'--set-log',
- '--install',
+ '--update-masquerade',
+ '--update-masquerade-with-crossdev',
'--help',
'--get-env',
'--set-env'
@@ -20,7 +20,20 @@ options=[
tmpcmdline=sys.argv[1:]
cmdline=[]
-envfile = '/etc/env.d/02distcc'
+
+eprefix = '@EPREFIX@'
+bindir = os.path.join(eprefix, 'usr', 'bin')
+sbindir = os.path.join(eprefix, 'usr', 'sbin')
+libdir = os.path.join(eprefix, '@libdir@')
+sysconfdir = os.path.join(eprefix, 'etc')
+
+gcc_config = os.path.join(bindir, 'gcc-config')
+env_update = os.path.join(sbindir, 'env-update')
+envfile = os.path.join(sysconfdir, 'env.d', '02distcc')
+default_distcc_dir = os.path.join(sysconfdir, 'distcc')
+hostfile = os.path.join(default_distcc_dir, 'hosts')
+distcc_path = os.path.join(bindir, 'distcc')
+dccc_dir = os.path.join(libdir, 'distcc', 'bin')
def exithandler(foo,bar):
os.kill(0,signal.SIGKILL)
@@ -31,7 +44,7 @@ signal.signal(signal.SIGINT,exithandler)
def isroot(ret=0):
if os.getuid() != 0:
if ret == 0:
- print '!!!',sys.argv[:1][0],tmpcmdline[0],'must be run as root'
+ print('!!! %s %s must be run as root' % (sys.argv[:1][0],tmpcmdline[0]))
sys.exit(1)
else:
retval = 0
@@ -48,69 +61,83 @@ def writeenv(var,value):
if re.compile(var+'="(.*)"').match(distcc_env[i]):
distcc_env[i] = var+'="'+value+'"\n'
distcc_env_new.write(distcc_env[i])
- #print 'Set',var,'to:',value
- os.popen('/usr/sbin/env-update')
- print 'If you want to use these new settings in an existing shell,'
- print 'you need to "source /etc/profile" to get the changes.'
+ #print('Set %s to: %s ' % (var,value))
+ subprocess.Popen(env_update, shell=True)
+ print('If you want to use these new settings in an existing shell,')
+ print('you need to "source /etc/profile" to get the changes.')
def readenv(var):
distcc_env = open(envfile, 'r').read()
match = re.compile(var+'="(.*)"').search(distcc_env)
if match:
- print var+'='+match.group(1)
+ print(var+'='+match.group(1))
else:
- print var,'not set.'
-
-def permissions(path,user,group):
- for file in os.listdir(path):
- #print 'Configuring',path+file+'...'
- os.chown(path+file,user,group)
+ print(var,'not set.')
-def installlinks(chost=''):
+def installlink(chost='', version=''):
for file in ['gcc', 'cc', 'c++', 'g++']:
- path = '/usr/lib/distcc/bin/'
if not chost == '':
- file = chost+'-'+file
- if os.path.exists('/usr/bin/'+file):
- #print 'Creating',path+file,'symlink...'
- if not os.path.exists(path+file):
- os.symlink('/usr/bin/distcc',path+file)
+ file = '%s-%s' % (chost,file)
+ if not version == '':
+ file = '%s-%s' % (file,version)
+ path = os.path.join(dccc_dir,file)
+ if os.path.exists(os.path.join(bindir,file)):
+ if not os.path.exists(path):
+ print('Creating %s symlink...' % (path))
+ os.symlink(distcc_path,path)
#else:
- # print 'Already exists. Skipping...'
+ # print('Already exists. Skipping...')
+
+def installlinks():
+ p = subprocess.Popen([gcc_config+" -C -l"], shell=True, stdout=subprocess.PIPE)
+ lines = p.stdout.read().decode().rstrip().split('\n')
+ for line in lines:
+ columns = line.split()
+ if len(columns) >= 2:
+ matches = re.match("(.*)-(.*)", columns[1])
+ chost = matches.group(1)
+ version = matches.group(2)
+ installlink(chost)
+ installlink(chost, version)
+
+def uninstalllinks():
+ for root, dirs, files in os.walk(dccc_dir):
+ for file in files:
+ os.remove(os.path.join(root, file))
def createdistccdir(dir):
if not os.path.exists(dir):
os.mkdir(dir)
- os.chmod(dir, 1777)
+ os.chmod(dir, 0o755)
for x in tmpcmdline:
if not x:
continue
if x[0:2]=="--":
if not x in options:
- print "!!! Error:",x,"is an invalid option."
+ print("!!! Error: %s is an invalid option." % (x))
sys.exit(1)
else:
cmdline = x
if '--get-hosts' in tmpcmdline:
HOSTS_ENV = os.environ.get('DISTCC_HOSTS')
- HOSTS_HOME = os.environ.get('HOME')+'/hosts'
+ HOSTS_HOME = os.path.join(os.environ.get('HOME'), '.distcc', 'hosts')
if HOSTS_ENV:
- print HOSTS_ENV
+ print(HOSTS_ENV)
elif os.path.isfile(HOSTS_HOME) and os.path.getsize(HOSTS_HOME) != 0:
- print HOSTS_HOME
- elif os.path.exists('/etc/distcc/hosts'):
- print rstrip(open('/etc/distcc/hosts', 'r').read())
+ print(HOSTS_HOME)
+ elif os.path.exists(hostfile):
+ print(open(hostfile, 'r').read().rstrip())
else:
- print 'No configuration file found. Setup your hosts with --set-hosts.'
+ print('No configuration file found. Setup your hosts with --set-hosts.')
elif '--set-hosts' in tmpcmdline:
if isroot(1):
- PATH = '/etc/distcc'
+ PATH = default_distcc_dir
else:
- PATH = os.environ.get('HOME')
+ PATH = os.path.join(os.environ.get('HOME'), '.distcc')
createdistccdir(PATH)
- open(PATH+'/hosts', 'w').write(cmdline + '\n')
+ open(os.path.join(PATH, 'hosts'), 'w').write(cmdline + '\n')
elif '--get-verbose' in tmpcmdline:
readenv('DISTCC_VERBOSE')
elif '--set-verbose' in tmpcmdline:
@@ -119,46 +146,35 @@ elif '--get-log' in tmpcmdline:
readenv('DISTCC_LOG')
elif '--set-log' in tmpcmdline:
writeenv('DISTCC_LOG',tmpcmdline[1])
-elif '--install' in tmpcmdline:
+elif '--update-masquerade' in tmpcmdline:
isroot()
- print 'Creating',envfile+'...'
- distcc_env = open(envfile, 'w')
- distcc_env.write('# This file is managed by distcc-config; use it to change these settings.\n')
- distcc_env.write('DISTCC_LOG=""\n')
- distcc_env.write('DCCC_PATH="/usr/lib/distcc/bin"\n')
- distcc_env.write('DISTCC_VERBOSE="0"\n')
-
- if os.WEXITSTATUS(commands.getstatusoutput('/usr/sbin/useradd -u 240 -g daemon -s /bin/false -d /dev/null -c "distccd" distcc')[0]) == 9:
- os.WEXITSTATUS(commands.getstatusoutput('/usr/sbin/usermod -g daemon -s /bin/false -d /dev/null -c "distccd" distcc')[0])
-
- foobar = pwd.getpwnam('distcc')
- user = foobar[2]
- group = foobar[3]
-
- makeconf = open('/etc/make.conf', 'r').read()
- chost = re.compile('CHOST="(.*)"').search(makeconf).group(1)
- print 'Creating symlinks...'
+ uninstalllinks()
+ print('Creating symlinks...')
+ installlink()
+ installlinks()
+elif '--update-masquerade-with-crossdev' in tmpcmdline:
+ isroot()
+ uninstalllinks()
+ print('Creating symlinks...')
installlinks()
- installlinks(chost)
-
- print 'Checking permissions...'
- permissions('/usr/lib/distcc/bin/',user,group)
- permissions('/var/run/distccd/',user,group)
elif '--get-env' in tmpcmdline:
if len(tmpcmdline) == 1:
- print rstrip(open(envfile, 'r').read())
+ print(open(envfile, 'r').read().rstrip())
elif len(tmpcmdline) == 2:
readenv(tmpcmdline[1])
else:
- print '!!! Error: Specify only one variable.'
+ print('!!! Error: Specify only one variable.')
elif '--set-env' in tmpcmdline:
if len(tmpcmdline) > 2 and len(tmpcmdline) <= 3:
isroot()
writeenv(tmpcmdline[1],tmpcmdline[2])
else:
- print '!!! Error: Awaiting two parameters.'
+ print('!!! Error: Awaiting two parameters.')
else:
- print 'Usage: /usr/bin/distcc-config --set-hosts DISTCC_HOSTS | --get-hosts'
- print ' /usr/bin/distcc-config --set-verbose { 0 | 1 } | --get-verbose'
- print ' /usr/bin/distcc-config --set-log FILE | --get-log'
- print ' /usr/bin/distcc-config --set-env VARIABLE VALUE | --get-env [VARIABLE]'
+ cmd = sys.argv[:1][0]
+ print('Usage: %s --set-hosts DISTCC_HOSTS | --get-hosts' % (cmd))
+ print(' %s --set-verbose { 0 | 1 } | --get-verbose' % (cmd))
+ print(' %s --set-log FILE | --get-log' % (cmd))
+ print(' %s --set-env VARIABLE VALUE | --get-env [VARIABLE]' % (cmd))
+ print(' %s --update-masquerade' % (cmd))
+ print(' %s --update-masquerade-with-crossdev' % (cmd))