| 1 | # Copyright: 2005 Gentoo Foundation |
|---|
| 2 | # License: GPL2 |
|---|
| 3 | |
|---|
| 4 | """ |
|---|
| 5 | Avoid using- os data- root uid/gid, pkgcore uid/gid, etc. |
|---|
| 6 | |
|---|
| 7 | This will be killed off and bound into configuration subsystem at some point |
|---|
| 8 | """ |
|---|
| 9 | |
|---|
| 10 | import os, pwd, grp |
|---|
| 11 | |
|---|
| 12 | ostype = os.uname()[0] |
|---|
| 13 | |
|---|
| 14 | if ostype == "Linux": |
|---|
| 15 | userland = "GNU" |
|---|
| 16 | xargs = os.environ["XARGS"] = "xargs -r" |
|---|
| 17 | lchown = os.lchown |
|---|
| 18 | elif ostype == "Darwin": |
|---|
| 19 | userland = "Darwin" |
|---|
| 20 | xargs = os.environ["XARGS"] = "xargs" |
|---|
| 21 | def lchown(*pos_args, **key_args): |
|---|
| 22 | pass |
|---|
| 23 | elif ostype in ["FreeBSD", "OpenBSD", "NetBSD"]: |
|---|
| 24 | userland = "BSD" |
|---|
| 25 | xargs = os.environ["XARGS"] = "xargs" |
|---|
| 26 | lchown = os.lchown |
|---|
| 27 | else: |
|---|
| 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. |
|---|
| 34 | secpass = 0 |
|---|
| 35 | |
|---|
| 36 | uid = os.getuid() |
|---|
| 37 | # hard coding sucks. |
|---|
| 38 | root_uid = 0 |
|---|
| 39 | root_gid = wheelgid = 0 |
|---|
| 40 | |
|---|
| 41 | if uid == 0: |
|---|
| 42 | secpass = 2 |
|---|
| 43 | try: |
|---|
| 44 | wheelgid = grp.getgrnam("wheel")[2] |
|---|
| 45 | if (not secpass) and (wheelgid in os.getgroups()): |
|---|
| 46 | secpass = 1 |
|---|
| 47 | except 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 |
|---|
| 54 | try: |
|---|
| 55 | portage_uid = pwd.getpwnam("portage")[2] |
|---|
| 56 | portage_gid = grp.getgrnam("portage")[2] |
|---|
| 57 | if (secpass == 0): |
|---|
| 58 | secpass = 1 |
|---|
| 59 | except 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" |
|---|