root/releases/pkgcore/0.1.1/pkgcore/os_data.py @ marienz%2540gentoo.org-20060906153927-5506d9364cc30862

Revision marienz%2540gentoo.org-20060906153927-5506d9364cc30862, 2.1 KB (checked in by Marien Zwart <marienz@…>, 2 years ago)

Merge.

Line 
1# Copyright: 2005 Gentoo Foundation
2# License: GPL2
3
4"""
5Avoid using- os data- root uid/gid, pkgcore uid/gid, etc.
6
7This will be killed off and bound into configuration subsystem at some point
8"""
9
10import os, pwd, grp
11
12ostype = os.uname()[0]
13
14if ostype == "Linux":
15    userland = "GNU"
16    xargs = os.environ["XARGS"] = "xargs -r"
17    lchown = os.lchown
18elif ostype == "Darwin":
19    userland = "Darwin"
20    xargs = os.environ["XARGS"] = "xargs"
21    def lchown(*pos_args, **key_args):
22        pass
23elif ostype in ["FreeBSD", "OpenBSD", "NetBSD"]:
24    userland = "BSD"
25    xargs = os.environ["XARGS"] = "xargs"
26    lchown = os.lchown
27else:
28    raise Exception("Operating system unsupported, '%s'" % ostype)
29
30
31#os.environ["USERLAND"] = userland
32
33#Secpass will be set to 1 if the user is root or in the portage group.
34secpass = 0
35
36uid = os.getuid()
37# hard coding sucks.
38root_uid = 0
39root_gid = wheelgid = 0
40
41if uid == 0:
42    secpass = 2
43try:
44    wheelgid = grp.getgrnam("wheel")[2]
45    if (not secpass) and (wheelgid in os.getgroups()):
46        secpass = 1
47except KeyError:
48    print "portage initialization: your system doesn't have a 'wheel' group."
49    print ("Please fix this as it is a normal system requirement. "
50           "'wheel' is GID 10")
51    print "'emerge baselayout' and an 'etc-update' should remedy this problem."
52
53#Discover the uid and gid of the portage user/group
54try:
55    portage_uid = pwd.getpwnam("portage")[2]
56    portage_gid = grp.getgrnam("portage")[2]
57    if (secpass == 0):
58        secpass = 1
59except KeyError:
60    portage_uid = 0
61    portage_gid = wheelgid
62    print
63    print "'portage' user or group missing. Please update baselayout"
64    print "and merge portage user(250) and group(250) into your passwd"
65    print "and group files. Non-root compilation is disabled until then."
66    print "Also note that non-root/wheel users will need to be added to"
67    print "the portage group to do portage commands.\n"
68    print "For the defaults, line 1 goes into passwd, and 2 into group."
69    print "portage:x:250:250:portage:/var/tmp/portage:/bin/false"
70    print "portage::250:portage"
Note: See TracBrowser for help on using the browser.