wrapper: pass runtime settings down here

Previously we set these variables in the generated config, but that meant
things did not adapt on the fly to changing behavior.  So if you tried to
move the code from one user to another, you'd have to regenerate things.
Instead, just detect it from the active env.  This makes things a little
more robust as well.

BUG=24614250
TEST=building packages works w/out errors

Change-Id: I563fef50d9e15c19769b570e33e8688d425521ec
diff --git a/wrapper.py b/wrapper.py
index e9556fe..4da2fac 100755
--- a/wrapper.py
+++ b/wrapper.py
@@ -11,6 +11,9 @@
 
 from __future__ import print_function
 
+import getpass
+import grp
+import multiprocessing
 import os
 import sys
 
@@ -20,4 +23,14 @@
 sys.path.insert(0, os.path.join(portage_path, 'pym'))
 os.environ['PYTHONPATH'] = ':'.join(sys.path)
 os.environ['EPREFIX'] = '/'
+
+os.environ.update({
+    'MAKEOPTS': '-j%i' % multiprocessing.cpu_count(),
+    'PORTAGE_USER': getpass.getuser(),
+    'PORTAGE_GROUP': grp.getgrgid(os.getgid()).gr_name,
+    'PORTAGE_ROOT_USER': getpass.getuser(),
+    'PORTAGE_INST_UID': str(os.getuid()),
+    'PORTAGE_INST_GID': str(os.getgid()),
+})
+
 os.execv(os.path.join(portage_path, 'bin', os.path.basename(__file__)), sys.argv)