/[gli]/branches/qs/src/GLIPortage.py
Gentoo

Contents of /branches/qs/src/GLIPortage.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1912 - (show annotations) (download) (as text)
Mon Jul 28 03:48:15 2008 UTC (5 years, 11 months ago) by codeman
File MIME type: text/x-python
File size: 26330 byte(s)
updates to GLIPortage to increase capabilities of it's command-line mode.

1 """
2 # Copyright 1999-2005 Gentoo Foundation
3 # This source code is distributed under the terms of version 2 of the GNU
4 # General Public License as published by the Free Software Foundation, a copy
5 # of which can be found in the main directory of this project.
6 Gentoo Linux Installer
7
8 $Id: GLIPortage.py,v 1.57 2006/09/13 18:29:13 agaffney Exp $
9 """
10
11 import re
12 import os
13 import sys
14 import GLIUtility
15 import GLILogger
16 from GLIException import GLIException
17
18 class GLIPortage(object):
19
20 def __init__(self, chroot_dir, logger, debug, cc, compile_logfile):
21 self._chroot_dir = chroot_dir
22 self._logger = logger
23 self._debug = debug
24 self._cc = cc
25 self._compile_logfile = compile_logfile
26
27 def get_deps(self, pkgs, grp_install=False):
28 pkglist = []
29 if isinstance(pkgs, str):
30 pkgs = pkgs.split()
31 for pkg in pkgs:
32 if not pkg: continue
33 if self._debug: self._logger.log("get_deps(): pkg is " + pkg)
34 if not grp_install or not self.get_best_version_vdb(pkg):
35 if self._debug: self._logger.log("get_deps(): grabbing compile deps")
36 tmppkglist = GLIUtility.spawn("emerge -p " + pkg + r" 2>/dev/null | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].strip().split("\n")
37 else:
38 if self._debug: self._logger.log("get_deps(): grabbing binary deps")
39 # The runtimedeps.py script generates a package install order that is *very* different from emerge itself
40 # tmppkglist = GLIUtility.spawn("python ../../runtimedeps.py " + self._chroot_dir + " " + pkg, return_output=True)[1].strip().split("\n")
41 tmppkglist = []
42 for tmppkg in GLIUtility.spawn("env USE='livecd bindist' emerge -p " + pkg + r" 2>/dev/null | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].strip().split("\n"):
43 if self._debug: self._logger.log("get_deps(): looking at " + tmppkg)
44 if self.get_best_version_vdb("=" + tmppkg):
45 if self._debug: self._logger.log("get_deps(): package " + tmppkg + " in host vdb...adding to tmppkglist")
46 tmppkglist.append(tmppkg)
47 if self._debug: self._logger.log("get_deps(): deplist for " + pkg + ": " + str(tmppkglist))
48 for tmppkg in tmppkglist:
49 if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist")
50 if not tmppkg in pkglist and not self.get_best_version_vdb_chroot("=" + tmppkg):
51 if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist")
52 pkglist.append(tmppkg)
53 if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist))
54 if not pkglist:
55 raise GLIException("GetDepListError", 'fatal', 'get_deps', "Dep list is empty. This usually means there is no portage tree in the chroot")
56 return pkglist
57
58 def parse_vdb_contents(self, file):
59 entries = []
60 try:
61 vdbfile = open(file, "r")
62 except:
63 return entries
64 for line in vdbfile.readlines():
65 parts = line.strip().split(" ")
66 if parts[0] == "obj":
67 entries.append(parts[1])
68 # elif parts[0] == "dir":
69 # entries.append(parts[1] + "/")
70 elif parts[0] == "sym":
71 entries.append(" ".join(parts[1:4]))
72 entries.sort()
73 return entries
74
75 def update_counter(self):
76 try:
77 counter_f = open(self._chroot_dir + "/var/cache/edb/counter", "r")
78 counter = int(counter_f.readline().strip())
79 counter_f.close()
80 except:
81 counter = 0
82 counter += 1
83 if not os.path.isdir(self._chroot_dir + "/var"):
84 os.mkdir(self._chroot_dir + "/var", 0755)
85 if not os.path.isdir(self._chroot_dir + "/var/cache"):
86 os.mkdir(self._chroot_dir + "/var/cache", 0755)
87 if not os.path.isdir(self._chroot_dir + "/var/cache/edb"):
88 os.mkdir(self._chroot_dir + "/var/cache/edb", 0775)
89 # chown to root:portage
90 try:
91 counter_f = open(self._chroot_dir + "/var/cache/edb/counter", "w")
92 counter_f.write(str(counter))
93 counter_f.close()
94 except:
95 raise GLIException("UpdateCounterError", 'fatal', 'update_counter', "could not write new counter value")
96 return counter
97
98 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False):
99 symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/',
100 '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/',
101 '/etc/gconf': '/usr/livecd/gconf/' }
102
103 tmpdir = "/var/tmp"
104 image_dir = tmpdir + "/portage/" + package + "/image"
105 root_cmd = ""
106 tmp_chroot_dir = self._chroot_dir
107 portage_tmpdir = "/var/tmp"
108 vdb_dir = "/var/db/pkg/"
109 if use_root:
110 root_cmd = "ROOT=" + self._chroot_dir
111 tmp_chroot_dir = ""
112 portage_tmpdir = self._chroot_dir + "/var/tmp"
113 vdb_dir = self._chroot_dir + "/var/db/pkg/"
114
115 # Create /tmp, /var/tmp, and /var/lib/portage with proper permissions
116 oldumask = os.umask(0)
117 if not os.path.exists(self._chroot_dir + "/tmp"):
118 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /tmp doesn't exist in chroot...creating with proper permissions")
119 try:
120 os.mkdir(self._chroot_dir + "/tmp", 01777)
121 except:
122 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /tmp in chroot")
123 if not os.path.exists(self._chroot_dir + "/var/tmp"):
124 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/tmp doesn't exist in chroot...creating with proper permissions")
125 try:
126 os.mkdir(self._chroot_dir + "/var", 0755)
127 except:
128 pass
129 try:
130 os.mkdir(self._chroot_dir + "/var/tmp", 01777)
131 except:
132 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/tmp in chroot")
133 if not os.path.exists(self._chroot_dir + "/var/lib/portage"):
134 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/lib/portage doesn't exist in chroot...creating with proper permissions")
135 try:
136 os.mkdir(self._chroot_dir + "/var/lib", 0755)
137 except:
138 pass
139 try:
140 os.mkdir(self._chroot_dir + "/var/lib/portage", 02750)
141 except:
142 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/lib/portage in chroot")
143 os.umask(oldumask)
144
145 # Check to see if package is actually in vdb
146 if not GLIUtility.is_file("/var/db/pkg/" + package):
147 if ignore_missing:
148 if self._debug:
149 self._logger.log("DEBUG: copy_pkg_to_chroot(): package " + package + " does not have a vdb entry but ignore_missing=True...ignoring error")
150 return
151 else:
152 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
153
154 # Copy the vdb entry for the package from the LiveCD to the chroot
155 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package)
156 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + "/var/db/pkg/" + package + " && cp -a /var/db/pkg/" + package + "/* " + self._chroot_dir + "/var/db/pkg/" + package, logfile=self._compile_logfile, append_log=True)):
157 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
158
159 # Update COUNTER
160 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): calling update_counter() to get updated COUNTER value for " + package)
161 counter = self.update_counter()
162 try:
163 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): updating COUNTER value (%s) in vdb entry for %s" % (self._chroot_dir + "/var/db/pkg/" + package + "/COUNTER", package))
164 counter_f = open(self._chroot_dir + "/var/db/pkg/" + package + "/COUNTER", "w")
165 counter_f.write(str(counter))
166 counter_f.close()
167 except:
168 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not update COUNTER for " + package)
169
170 # Create the image dir in the chroot
171 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'")
172 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
173 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
174
175 # Create list of files for tar to work with from CONTENTS file in vdb entry
176 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
177 if not entries:
178 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup")
179 else:
180 # if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
181 try:
182 tarfiles = open("/tmp/tarfilelist", "w")
183 for entry in entries:
184 parts = entry.split(" ")
185 # # Hack for symlink crappiness
186 # for symlink in symlinks:
187 # if parts[0].startswith(symlink):
188 # parts[0] = symlinks[symlink] + parts[0][len(symlink):]
189 tarfiles.write(parts[0] + "\n")
190 tarfiles.close()
191 except:
192 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)
193
194 # Use tar to transfer files into IMAGE directory
195 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp'")
196 if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp", logfile=self._compile_logfile, append_log=True)):
197 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
198
199 # Fix mode, uid, and gid of directories
200 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running find " + self._chroot_dir + image_dir + " -mindepth 1 -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'")
201 dirlist = GLIUtility.spawn("find " + self._chroot_dir + image_dir + " -mindepth 1 -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'", return_output=True)[1].strip().split("\n")
202 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): found the following directories: " + str(dirlist))
203 if not dirlist or dirlist[0] == "":
204 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!")
205 for dir in dirlist:
206 dirstat = os.stat(dir)
207 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): setting mode " + str(dirstat[0]) + " and uid/gid " + str(dirstat[4]) + "/" + str(dirstat[5]) + " for directory " + self._chroot_dir + image_dir + dir)
208 os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5])
209 os.chmod(self._chroot_dir + image_dir + dir, dirstat[0])
210
211 # # More symlink crappiness hacks
212 # for symlink in symlinks:
213 ## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]):
214 # if os.path.islink(self._chroot_dir + image_dir + symlink):
215 # if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): fixing " + symlink + " symlink ickiness stuff in " + image_dir + " for " + package)
216 # GLIUtility.spawn("rm " + self._chroot_dir + image_dir + symlink)
217 # if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)):
218 # raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package)
219
220 # Run pkg_setup
221 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package)
222 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " FEATURES=noauto USE='livecd bindist' ebuild " + vdb_dir + package + "/*.ebuild setup", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
223 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package)
224
225 # Run pkg_preinst
226 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package)
227 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " FEATURES=noauto USE='livecd bindist' ebuild " + vdb_dir + package + "/*.ebuild preinst", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
228 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
229
230 # Copy files from image_dir to chroot
231 if not entries:
232 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
233 else:
234 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package)
235 # if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)):
236 if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -C " + self._chroot_dir + image_dir + "/ -cp . | tar -C " + self._chroot_dir + "/ -xp", logfile=self._compile_logfile, append_log=True)):
237 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
238
239 # Run pkg_postinst
240 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package)
241 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " FEATURES=noauto USE='livecd bindist' ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
242 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
243
244 # Remove image_dir
245 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package)
246 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
247 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
248
249 # Run env-update
250 if not use_root:
251 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot")
252 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)):
253 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
254
255 def add_pkg_to_world(self, package):
256 if package.find("/") == -1:
257 package = self.get_best_version_vdb_chroot(package)
258 if not package: return False
259 expr = re.compile('^=?(.+?/.+?)(-\d.+)?$')
260 res = expr.match(package)
261 if res:
262 world_f = open(self._chroot_dir + "/var/lib/portage/world", "a")
263 world_f.write(res.group(1) + "\n")
264 world_f.close()
265
266 def get_best_version_vdb(self, package):
267 if package.startswith('='):
268 package = package[1:]
269 if GLIUtility.is_file("/var/db/pkg/" + package):
270 return package
271 else:
272 return ""
273 else:
274 return GLIUtility.spawn("portageq best_version / " + package, return_output=True)[1].strip()
275
276 def get_best_version_vdb_chroot(self, package):
277 if package.startswith('='):
278 package = package[1:]
279 if GLIUtility.is_file(self._chroot_dir + "/var/db/pkg/" + package):
280 return package
281 else:
282 return ""
283 else:
284 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip()
285
286 # def get_best_version_tree(self, package):
287 # return portage.best(tree.match(package))
288
289 def emerge(self, packages, grp_install=False, add_to_world=True):
290 if isinstance(packages, str):
291 packages = packages.split()
292 if len(packages) > 1:
293 self._cc.addNotification("progress", (0, "Calculating dependencies for your packages"))
294 else:
295 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages)))
296 pkglist = self.get_deps(packages, grp_install)
297 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
298 for i, pkg in enumerate(pkglist):
299 if not pkg: continue
300 if self._debug: self._logger.log("install_packages(): processing package " + pkg)
301 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
302 if not grp_install or not self.get_best_version_vdb("=" + pkg):
303 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)
304 # status = self._emerge("=" + pkg)
305 if not GLIUtility.exitsuccess(status):
306 raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
307 else:
308 # try:
309 self.copy_pkg_to_chroot(pkg)
310 # except:
311 # raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
312 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
313 if add_to_world:
314 for package in packages:
315 self.add_pkg_to_world(package)
316
317 def create_binpkg_repo_from_vdb(self):
318 if not os.path.exists("/tmp/fake_binpkg"):
319 try:
320 os.mkdir("/tmp/fake_binpkg")
321 except:
322 raise GLIException("VDBToBinpkgError", "fatal", "create_binpkg_repo_from_vdb", "Could not not create /tmp/fake_binpkg!")
323 status = GLIUtility.spawn("PKGDIR=/tmp/fake_binpkg ../../vdb_to_fake_binrepo.py", logfile=self._compile_logfile, append_log=True)
324 if not GLIUtility.exitsuccess(status):
325 raise GLIException("VDBToBinpkgError", "fatal", "create_binpkg_repo_from_vdb", "Failure while running vdb_to_fake_binrepo.py")
326
327 def get_system_packages(self):
328 self.create_binpkg_repo_from_vdb()
329 systempkgs = GLIUtility.spawn(r"PKGDIR=/tmp/fake_binpkg emerge -eqKp system | grep -e '^\[binary' | sed -e 's:^\[binary .\+\] ::' -e 's: .\+$::'", return_output=True)[1].strip().split("\n")
330 return systempkgs
331
332 def usage(progname):
333 print """
334 Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-l|--logfile <logfile>] [-h|--help]
335
336 Options:
337
338 -c|--chroot-dir Specifies the directory where your chroot is. This is
339 "/mnt/gentoo" by default.
340
341 -g|--grp Install specified packages and dependencies into chroot
342 by using files from the LiveCD.
343
344 -s|--stage3 Create a stage3 equivelant in the chroot directory by using
345 files from the LiveCD.
346
347 -k|--kernel Install kernel and modules from LiveCD into the chroot
348
349 -l|--logfile Sets the logfile for the ouput. defaults to cwd/install.log
350
351 -h|--help Display this help
352 """ % (progname)
353
354 if __name__ == "__main__":
355 chroot_dir = "/mnt/gentoo"
356 logfile = None
357 mode = None
358 grp_packages = []
359 progname = sys.argv.pop(0)
360 while len(sys.argv):
361 arg = sys.argv.pop(0)
362 if arg == "-c" or arg == "--chroot-dir":
363 chroot_dir = sys.argv.pop(0)
364 elif arg == "-l" or arg == "--logfile":
365 logfile = sys.argv.pop(0)
366 elif arg == "-g" or arg == "--grp":
367 mode = "grp"
368 elif arg == "-s" or arg == "--stage3":
369 mode = "stage3"
370 elif arg == "-k" or arg == "--kernel":
371 mode = "kernel"
372 elif arg == "-h" or arg == "--help":
373 usage(progname)
374 sys.exit(0)
375 elif arg[0] == "-":
376 usage(progname)
377 sys.exit(1)
378 else:
379 grp_packages.append(arg)
380 logger = GLILogger.Logger(logfile)
381 gliportage = GLIPortage(chroot_dir, logger, True, None, False)
382 if mode == "stage3":
383 try:
384 systempkgs = gliportage.get_system_packages()
385 except:
386 print "Could not open generate list of system packages!"
387 sys.exit(1)
388
389 # Pre-create /lib (and possible /lib32 and /lib64)
390 if os.path.islink("/lib") and os.readlink("/lib") == "lib64":
391 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")):
392 print "Could not precreate /lib64 dir and /lib -> /lib64 symlink"
393 sys.exit(1)
394
395 syspkglen = len(systempkgs)
396 for i, pkg in enumerate(systempkgs):
397 pkg = pkg.strip()
398 print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
399 gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True)
400 GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf")
401 GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile")
402 GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab")
403
404 # Nasty, nasty, nasty hack because vapier is a tool
405 for tmpfile in ("/etc/passwd", "/etc/group", "/etc/shadow"):
406 GLIUtility.spawn("grep -ve '^gentoo' " + tmpfile + " > " + chroot_dir + tmpfile)
407
408 chrootscript = r"""
409 #!/bin/bash
410
411 source /etc/make.conf
412 export LDPATH="/usr/lib/gcc-lib/${CHOST}/$(cd /usr/lib/gcc-lib/${CHOST} && ls -1 | head -n 1)"
413
414 ldconfig $LDPATH
415 gcc-config 1
416 env-update
417 source /etc/profile
418 modules-update
419 [ -f /usr/bin/binutils-config ] && binutils-config 1
420 source /etc/profile
421 cd /dev
422 rm console null tty1
423 mknod console c 5 1
424 mknod null c 1 3
425 mknod tty1 c 4 1
426 mkdir -m 755 /mnt
427 mkdir -m 700 /mnt/cdrom
428 mkdir -m 700 /mnt/floppy
429 [ -f /usr/sbin/create-cracklib-dict ] && /usr/sbin/create-cracklib-dict /usr/share/dict/* > /dev/null
430 # [ -f /lib/udev-state/devices.tar.bz2 ] && tar -C /dev -xjf /lib/udev-state/devices.tar.bz2
431 """
432 script = open(chroot_dir + "/tmp/extrastuff.sh", "w")
433 script.write(chrootscript)
434 script.close()
435 GLIUtility.spawn("chmod 755 /tmp/extrastuff.sh && /tmp/extrastuff.sh", chroot=chroot_dir)
436 GLIUtility.spawn("rm -rf /var/tmp/portage/* /usr/portage /tmp/*", chroot=chroot_dir)
437 print "Stage3 equivelant generation complete!"
438 elif mode == "grp":
439 for pkg in grp_packages:
440 if not gliportage.get_best_version_vdb(pkg):
441 print "Package " + pkg + " is not available for install from the LiveCD"
442 continue
443 pkglist = gliportage.get_deps(pkg, True)
444 for i, tmppkg in enumerate(pkglist):
445 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
446 gliportage.copy_pkg_to_chroot(tmppkg)
447 gliportage.add_pkg_to_world(pkg)
448 print "GRP install complete!"
449 elif mode == "kernel":
450 #Code copied from GLIArchTemplate
451 GLIUtility.spawn(r"find /var/db/pkg -type f -name CONTENTS | xargs awk '/^obj \/lib\/modules\// { print $2; }' > /tmp/kernel_modules")
452 files = GLIUtility.spawn('ls -1 --color=no /boot/System* /boot/kernel* /boot/initr* $(for i in $(find "/lib/modules/" -type f); do grep --quiet "^${i}$" /tmp/kernel_modules || echo ${i}; done); rm /tmp/kernel_modules 2>/dev/null', return_output=True)[1].strip().split("\n")
453 if not files:
454 print "Error: could not determine files to copy for livecd-kernel"
455 sys.exit(1)
456 if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -p --parents %s %s/" % (" ".join(files), chroot_dir))):
457 print "Error: could not copy kernel, initramfs, or modules"
458 sys.exit(1)
459 GLIUtility.spawn("depmod -a")
460 portage_info = {}
461 for line in GLIUtility.spawn(r"emerge --info 2>/dev/null | grep '^[A-Z0-9_]\+=' | sed -e 's:\" \([A-Z]\):\"\n\1:g'", chroot=chroot_dir, return_output=True)[1].strip().split("\n"):
462 parts = line.split("=", 1)
463 portage_info[parts[0]] = parts[1].strip("'\"")
464 arch = portage_info["ACCEPT_KEYWORDS"].split(" ")[0].strip("~")
465 values = {
466 'CATEGORY': "sys-kernel",
467 'CBUILD': portage_info['CHOST'],
468 'CFLAGS': portage_info['CFLAGS'],
469 'CHOST': portage_info['CHOST'],
470 'CONTENTS': "",
471 # 'COUNTER': "0",
472 'CXXFLAGS': portage_info.get("CXXFLAGS", ""),
473 'DEPEND': "",
474 'DESCRIPTION': "LiveCD kernel as installed by GLI",
475 'EAPI': "0",
476 'FEATURES': "",
477 'HOMEPAGE': "http://www.gentoo.org/proj/en/releng/installer/",
478 'INHERITED': "eutils",
479 'KEYWORDS': arch,
480 'LICENSE': "",
481 'NEEDED': "",
482 'PDEPEND': "",
483 'PF': "livecd-kernel-1",
484 'PROVIDE': "virtual/alsa",
485 'RDEPEND': "",
486 'SLOT': "0",
487 'USE': arch
488 }
489 vdbdir = chroot_dir + "/var/db/pkg/sys-kernel/livecd-kernel-1"
490 os.mkdir(vdbdir)
491 for tmpfile in values:
492 fileout = open(vdbdir + "/" + tmpfile, "w")
493 fileout.write(values[tmpfile] + "\n")
494 fileout.close()
495 fileout = open(vdbdir + "/livecd-kernel-1.ebuild", "w")
496 fileout.write("inherit eutils\n\nDESCRIPTION=\"LiveCD kernel as installed by GLI\"\nHOMEPAGE=\"http://www.gentoo.org/proj/en/releng/installer/\"\nSRC_URI=\nLICENSE=\nSLOT=0\nKEYWORDS=\"%s\"\nIUSE=\nDEPEND=\nPROVIDE=virtual/alsa\n" % arch)
497 fileout.close()
498 print "wrote ebuild"
499 counter = gliportage.update_counter()
500 counter_f = open(vdbdir + "/COUNTER", "w")
501 counter_f.write(str(counter))
502 counter_f.close()
503 GLIUtility.spawn("echo | bzip2 > %s/environment.bz2" % vdbdir)
504 print "counter stuff done"
505 kernelpkg = gliportage.get_best_version_vdb_chroot("sys-kernel/livecd-kernel")
506 # print "Copying "+kernelpkg+" to chroot environment"
507 # gliportage.copy_pkg_to_chroot(kernelpkg)
508 print "Normally we would've copied the livecd-kernel via the GRP process, but now done a different way"
509 #20:05 <+agaffney> dberkholz: you can't do the kernel anymore, since it's not a binpkg
510 #20:05 <+agaffney> I got rid of that behavior
511 #20:05 <+agaffney> just copy the contents of /boot and /lib/modules
512 #20:05 <+agaffney> that's what the installer does
513
514 gliportage.add_pkg_to_world(kernelpkg)
515
516 try:
517 os.stat(chroot_dir + "/usr/src/linux")
518 except:
519 kernels = os.listdir(chroot_dir+"/usr/src")
520 found_a_kernel = False
521 counter = 0
522 while not found_a_kernel:
523 if (len(kernels[counter]) > 6) and (kernels[counter][0:6]=="linux-"):
524 exitstatus = GLIUtility.spawn("ln -s /usr/src/"+kernels[counter]+ " /usr/src/linux",chroot=chroot_dir)
525 if not GLIUtility.exitsuccess(exitstatus):
526 print "Error: Could not make a /usr/src/linux symlink"
527 sys.exit(1)
528 found_a_kernel = True
529 else :
530 counter = counter + 1
531 print "Kernel sources:"+kernel_pkg+" emerged and /usr/src/linux symlinked."
532 print "LiveCD kernel installed!"
533 else:
534 print "You must specify an operating mode (-g or -s)!"
535 usage(progname)
536 sys.exit(1)

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20