/[gli]/trunk/src/GLIPortage.py
Gentoo

Contents of /trunk/src/GLIPortage.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1899 - (hide annotations) (download) (as text)
Sun May 11 00:50:23 2008 UTC (6 years, 4 months ago) by codeman
File MIME type: text/x-python
File size: 22462 byte(s)
fix to progress bar overflow bug.

1 agaffney 1181 """
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 agaffney 1527 $Id: GLIPortage.py,v 1.57 2006/09/13 18:29:13 agaffney Exp $
9 agaffney 1181 """
10    
11 agaffney 1182 import re
12 agaffney 1216 import os
13 agaffney 1306 import sys
14 agaffney 1181 import GLIUtility
15 agaffney 1204 from GLIException import GLIException
16 agaffney 1181
17     class GLIPortage(object):
18    
19 agaffney 1674 def __init__(self, chroot_dir, logger, debug, cc, compile_logfile):
20 agaffney 1182 self._chroot_dir = chroot_dir
21     self._logger = logger
22     self._debug = debug
23 agaffney 1205 self._cc = cc
24     self._compile_logfile = compile_logfile
25 agaffney 1181
26 agaffney 1674 def get_deps(self, pkgs, grp_install=False):
27 agaffney 1189 pkglist = []
28     if isinstance(pkgs, str):
29     pkgs = pkgs.split()
30     for pkg in pkgs:
31 agaffney 1305 if not pkg: continue
32 agaffney 1190 if self._debug: self._logger.log("get_deps(): pkg is " + pkg)
33 agaffney 1674 if not grp_install or not self.get_best_version_vdb(pkg):
34 agaffney 1190 if self._debug: self._logger.log("get_deps(): grabbing compile deps")
35 agaffney 1208 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")
36 agaffney 1189 else:
37 agaffney 1190 if self._debug: self._logger.log("get_deps(): grabbing binary deps")
38 agaffney 1210 # The runtimedeps.py script generates a package install order that is *very* different from emerge itself
39     # tmppkglist = GLIUtility.spawn("python ../../runtimedeps.py " + self._chroot_dir + " " + pkg, return_output=True)[1].strip().split("\n")
40     tmppkglist = []
41 agaffney 1882 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"):
42 agaffney 1210 if self._debug: self._logger.log("get_deps(): looking at " + tmppkg)
43 agaffney 1211 if self.get_best_version_vdb("=" + tmppkg):
44 agaffney 1210 if self._debug: self._logger.log("get_deps(): package " + tmppkg + " in host vdb...adding to tmppkglist")
45     tmppkglist.append(tmppkg)
46 agaffney 1190 if self._debug: self._logger.log("get_deps(): deplist for " + pkg + ": " + str(tmppkglist))
47 agaffney 1189 for tmppkg in tmppkglist:
48 agaffney 1192 if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist")
49 agaffney 1194 if not tmppkg in pkglist and not self.get_best_version_vdb_chroot("=" + tmppkg):
50 agaffney 1192 if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist")
51 agaffney 1189 pkglist.append(tmppkg)
52 agaffney 1190 if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist))
53 agaffney 1525 if not pkglist:
54     raise GLIException("GetDepListError", 'fatal', 'get_deps', "Dep list is empty. This usually means there is no portage tree in the chroot")
55 agaffney 1189 return pkglist
56 agaffney 1182
57 agaffney 1221 def parse_vdb_contents(self, file):
58     entries = []
59     try:
60     vdbfile = open(file, "r")
61     except:
62     return entries
63     for line in vdbfile.readlines():
64     parts = line.strip().split(" ")
65     if parts[0] == "obj":
66     entries.append(parts[1])
67 agaffney 1222 # elif parts[0] == "dir":
68     # entries.append(parts[1] + "/")
69 agaffney 1221 elif parts[0] == "sym":
70     entries.append(" ".join(parts[1:4]))
71     entries.sort()
72     return entries
73    
74 agaffney 1757 def update_counter(self):
75     try:
76     counter_f = open(self._chroot_dir + "/var/cache/edb/counter", "r")
77     counter = int(counter_f.readline().strip())
78     counter_f.close()
79     except:
80     counter = 0
81     counter += 1
82 agaffney 1760 if not os.path.isdir(self._chroot_dir + "/var"):
83 agaffney 1762 os.mkdir(self._chroot_dir + "/var", 0755)
84 agaffney 1760 if not os.path.isdir(self._chroot_dir + "/var/cache"):
85 agaffney 1762 os.mkdir(self._chroot_dir + "/var/cache", 0755)
86 agaffney 1760 if not os.path.isdir(self._chroot_dir + "/var/cache/edb"):
87 agaffney 1762 os.mkdir(self._chroot_dir + "/var/cache/edb", 0775)
88 agaffney 1760 # chown to root:portage
89 agaffney 1761 try:
90     counter_f = open(self._chroot_dir + "/var/cache/edb/counter", "w")
91     counter_f.write(str(counter))
92     counter_f.close()
93     except:
94     raise GLIException("UpdateCounterError", 'fatal', 'update_counter', "could not write new counter value")
95 agaffney 1757 return counter
96    
97 agaffney 1280 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False):
98 agaffney 1221 symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/',
99     '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/',
100     '/etc/gconf': '/usr/livecd/gconf/' }
101 agaffney 1182
102 agaffney 1469 tmpdir = "/var/tmp"
103 agaffney 1790 image_dir = tmpdir + "/portage/" + package + "/image"
104 agaffney 1198 root_cmd = ""
105     tmp_chroot_dir = self._chroot_dir
106 agaffney 1469 portage_tmpdir = "/var/tmp"
107 agaffney 1270 vdb_dir = "/var/db/pkg/"
108 agaffney 1198 if use_root:
109     root_cmd = "ROOT=" + self._chroot_dir
110 agaffney 1203 tmp_chroot_dir = ""
111 agaffney 1469 portage_tmpdir = self._chroot_dir + "/var/tmp"
112 agaffney 1270 vdb_dir = self._chroot_dir + "/var/db/pkg/"
113 agaffney 1198
114 agaffney 1339 # Create /tmp, /var/tmp, and /var/lib/portage with proper permissions
115     oldumask = os.umask(0)
116     if not os.path.exists(self._chroot_dir + "/tmp"):
117     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /tmp doesn't exist in chroot...creating with proper permissions")
118     try:
119     os.mkdir(self._chroot_dir + "/tmp", 01777)
120     except:
121     raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /tmp in chroot")
122     if not os.path.exists(self._chroot_dir + "/var/tmp"):
123     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/tmp doesn't exist in chroot...creating with proper permissions")
124     try:
125     os.mkdir(self._chroot_dir + "/var", 0755)
126     except:
127     pass
128     try:
129     os.mkdir(self._chroot_dir + "/var/tmp", 01777)
130     except:
131     raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/tmp in chroot")
132     if not os.path.exists(self._chroot_dir + "/var/lib/portage"):
133     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/lib/portage doesn't exist in chroot...creating with proper permissions")
134     try:
135     os.mkdir(self._chroot_dir + "/var/lib", 0755)
136     except:
137     pass
138     try:
139     os.mkdir(self._chroot_dir + "/var/lib/portage", 02750)
140     except:
141     raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/lib/portage in chroot")
142     os.umask(oldumask)
143    
144 agaffney 1280 # Check to see if package is actually in vdb
145     if not GLIUtility.is_file("/var/db/pkg/" + package):
146     if ignore_missing:
147     if self._debug:
148     self._logger.log("DEBUG: copy_pkg_to_chroot(): package " + package + " does not have a vdb entry but ignore_missing=True...ignoring error")
149     return
150     else:
151     raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
152    
153 agaffney 1182 # Copy the vdb entry for the package from the LiveCD to the chroot
154     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package)
155 agaffney 1314 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)):
156 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
157    
158 agaffney 1757 # Update COUNTER
159 agaffney 1761 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): calling update_counter() to get updated COUNTER value for " + package)
160     counter = self.update_counter()
161 agaffney 1757 try:
162 agaffney 1761 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))
163 agaffney 1757 counter_f = open(self._chroot_dir + "/var/db/pkg/" + package + "/COUNTER", "w")
164     counter_f.write(str(counter))
165     counter_f.close()
166     except:
167     raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not update COUNTER for " + package)
168    
169 agaffney 1208 # Create the image dir in the chroot
170     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'")
171 agaffney 1314 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
172 agaffney 1208 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
173    
174 agaffney 1182 # Create list of files for tar to work with from CONTENTS file in vdb entry
175 agaffney 1221 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
176 agaffney 1208 if not entries:
177     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup")
178     else:
179 agaffney 1342 # if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
180 agaffney 1208 try:
181     tarfiles = open("/tmp/tarfilelist", "w")
182     for entry in entries:
183     parts = entry.split(" ")
184 agaffney 1222 # # Hack for symlink crappiness
185 agaffney 1221 # for symlink in symlinks:
186     # if parts[0].startswith(symlink):
187     # parts[0] = symlinks[symlink] + parts[0][len(symlink):]
188 agaffney 1208 tarfiles.write(parts[0] + "\n")
189     tarfiles.close()
190     except:
191     raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)
192 agaffney 1182
193 agaffney 1208 # Use tar to transfer files into IMAGE directory
194 agaffney 1222 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'")
195 agaffney 1314 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)):
196 agaffney 1208 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
197 agaffney 1182
198 agaffney 1338 # Fix mode, uid, and gid of directories
199 agaffney 1469 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 '^$'")
200     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")
201     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): found the following directories: " + str(dirlist))
202     if not dirlist or dirlist[0] == "":
203     raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!")
204     for dir in dirlist:
205     dirstat = os.stat(dir)
206     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)
207     os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5])
208     os.chmod(self._chroot_dir + image_dir + dir, dirstat[0])
209 agaffney 1338
210 agaffney 1221 # # More symlink crappiness hacks
211     # for symlink in symlinks:
212     ## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]):
213     # if os.path.islink(self._chroot_dir + image_dir + symlink):
214     # if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): fixing " + symlink + " symlink ickiness stuff in " + image_dir + " for " + package)
215     # GLIUtility.spawn("rm " + self._chroot_dir + image_dir + symlink)
216     # if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)):
217     # raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package)
218 agaffney 1182
219     # Run pkg_setup
220     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package)
221 agaffney 1882 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)):
222 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package)
223    
224     # Run pkg_preinst
225     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package)
226 agaffney 1882 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)):
227 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
228    
229     # Copy files from image_dir to chroot
230 agaffney 1208 if not entries:
231 agaffney 1209 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
232 agaffney 1208 else:
233     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package)
234 agaffney 1291 # if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)):
235 agaffney 1338 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)):
236 agaffney 1208 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
237 agaffney 1182
238     # Run pkg_postinst
239     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package)
240 agaffney 1882 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)):
241 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
242    
243     # Remove image_dir
244 agaffney 1208 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package)
245 agaffney 1314 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
246 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
247    
248 agaffney 1297 # Run env-update
249     if not use_root:
250     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot")
251 agaffney 1314 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)):
252 agaffney 1297 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
253    
254 agaffney 1182 def add_pkg_to_world(self, package):
255     if package.find("/") == -1:
256 agaffney 1195 package = self.get_best_version_vdb_chroot(package)
257 agaffney 1182 if not package: return False
258 agaffney 1205 expr = re.compile('^=?(.+?/.+?)(-\d.+)?$')
259 agaffney 1182 res = expr.match(package)
260     if res:
261 agaffney 1767 world_f = open(self._chroot_dir + "/var/lib/portage/world", "a")
262     world_f.write(res.group(1) + "\n")
263     world_f.close()
264 agaffney 1182
265 agaffney 1185 def get_best_version_vdb(self, package):
266 agaffney 1285 if package.startswith('='):
267     package = package[1:]
268     if GLIUtility.is_file("/var/db/pkg/" + package):
269     return package
270 agaffney 1286 else:
271     return ""
272 agaffney 1285 else:
273     return GLIUtility.spawn("portageq best_version / " + package, return_output=True)[1].strip()
274 agaffney 1189
275 agaffney 1194 def get_best_version_vdb_chroot(self, package):
276 agaffney 1287 if package.startswith('='):
277     package = package[1:]
278     if GLIUtility.is_file(self._chroot_dir + "/var/db/pkg/" + package):
279     return package
280     else:
281     return ""
282     else:
283     return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip()
284 agaffney 1194
285 agaffney 1184 # def get_best_version_tree(self, package):
286     # return portage.best(tree.match(package))
287 agaffney 1205
288 codeman 1675 def emerge(self, packages, grp_install=False, add_to_world=True):
289 agaffney 1205 if isinstance(packages, str):
290     packages = packages.split()
291 codeman 1899 if len(packages) > 1:
292     self._cc.addNotification("progress", (0, "Calculating dependencies for your packages"))
293     else:
294     self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages)))
295 agaffney 1700 pkglist = self.get_deps(packages, grp_install)
296 agaffney 1205 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
297     for i, pkg in enumerate(pkglist):
298 agaffney 1305 if not pkg: continue
299 agaffney 1205 if self._debug: self._logger.log("install_packages(): processing package " + pkg)
300 agaffney 1208 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
301 agaffney 1674 if not grp_install or not self.get_best_version_vdb("=" + pkg):
302 agaffney 1205 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)
303     # status = self._emerge("=" + pkg)
304     if not GLIUtility.exitsuccess(status):
305     raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
306     else:
307     # try:
308     self.copy_pkg_to_chroot(pkg)
309     # except:
310     # raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
311 agaffney 1208 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
312 agaffney 1205 if add_to_world:
313     for package in packages:
314     self.add_pkg_to_world(package)
315 agaffney 1306
316 agaffney 1886 def create_binpkg_repo_from_vdb(self):
317     if not os.path.exists("/tmp/fake_binpkg"):
318     try:
319     os.mkdir("/tmp/fake_binpkg")
320     except:
321     raise GLIException("VDBToBinpkgError", "fatal", "create_binpkg_repo_from_vdb", "Could not not create /tmp/fake_binpkg!")
322     status = GLIUtility.spawn("PKGDIR=/tmp/fake_binpkg ../../vdb_to_fake_binrepo.py", logfile=self._compile_logfile, append_log=True)
323     if not GLIUtility.exitsuccess(status):
324     raise GLIException("VDBToBinpkgError", "fatal", "create_binpkg_repo_from_vdb", "Failure while running vdb_to_fake_binrepo.py")
325 agaffney 1306
326 agaffney 1886 def get_system_packages(self):
327     self.create_binpkg_repo_from_vdb()
328     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")
329     return systempkgs
330    
331 agaffney 1311 def usage(progname):
332 agaffney 1306 print """
333 agaffney 1311 Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help]
334 agaffney 1306
335     Options:
336    
337     -c|--chroot-dir Specifies the directory where your chroot is. This is
338     "/mnt/gentoo" by default.
339    
340     -g|--grp Install specified packages and dependencies into chroot
341     by using files from the LiveCD.
342    
343     -s|--stage3 Create a stage3 equivelant in the chroot directory by using
344     files from the LiveCD.
345    
346 agaffney 1527 -k|--kernel Install kernel and modules from LiveCD into the chroot
347    
348 agaffney 1306 -h|--help Display this help
349 agaffney 1311 """ % (progname)
350 agaffney 1306
351     if __name__ == "__main__":
352     chroot_dir = "/mnt/gentoo"
353     mode = None
354     grp_packages = []
355 agaffney 1311 progname = sys.argv.pop(0)
356 agaffney 1307 while len(sys.argv):
357 agaffney 1306 arg = sys.argv.pop(0)
358     if arg == "-c" or arg == "--chroot-dir":
359     chroot_dir = sys.argv.pop(0)
360     elif arg == "-g" or arg == "--grp":
361     mode = "grp"
362     elif arg == "-s" or arg == "--stage3":
363     mode = "stage3"
364 agaffney 1526 elif arg == "-k" or arg == "--kernel":
365     mode = "kernel"
366 agaffney 1306 elif arg == "-h" or arg == "--help":
367 agaffney 1311 usage(progname)
368 agaffney 1306 sys.exit(0)
369     elif arg[0] == "-":
370 agaffney 1311 usage(progname)
371 agaffney 1306 sys.exit(1)
372     else:
373     grp_packages.append(arg)
374    
375     gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
376     if mode == "stage3":
377     try:
378 agaffney 1886 systempkgs = gliportage.get_system_packages()
379 agaffney 1306 except:
380 agaffney 1886 print "Could not open generate list of system packages!"
381 agaffney 1306 sys.exit(1)
382    
383     # Pre-create /lib (and possible /lib32 and /lib64)
384     if os.path.islink("/lib") and os.readlink("/lib") == "lib64":
385     if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")):
386     print "Could not precreate /lib64 dir and /lib -> /lib64 symlink"
387     sys.exit(1)
388    
389     syspkglen = len(systempkgs)
390     for i, pkg in enumerate(systempkgs):
391     pkg = pkg.strip()
392 agaffney 1310 print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
393 agaffney 1306 gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True)
394     GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf")
395     GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile")
396     GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab")
397    
398     # Nasty, nasty, nasty hack because vapier is a tool
399     for tmpfile in ("/etc/passwd", "/etc/group", "/etc/shadow"):
400     GLIUtility.spawn("grep -ve '^gentoo' " + tmpfile + " > " + chroot_dir + tmpfile)
401    
402     chrootscript = r"""
403     #!/bin/bash
404    
405     source /etc/make.conf
406     export LDPATH="/usr/lib/gcc-lib/${CHOST}/$(cd /usr/lib/gcc-lib/${CHOST} && ls -1 | head -n 1)"
407    
408     ldconfig $LDPATH
409     gcc-config 1
410     env-update
411     source /etc/profile
412     modules-update
413     [ -f /usr/bin/binutils-config ] && binutils-config 1
414     source /etc/profile
415 agaffney 1888 cd /dev
416     rm console null tty1
417     mknod console c 5 1
418     mknod null c 1 3
419     mknod tty1 c 4 1
420     mkdir -m 755 /mnt
421     mkdir -m 700 /mnt/cdrom
422     mkdir -m 700 /mnt/floppy
423     [ -f /usr/sbin/create-cracklib-dict ] && /usr/sbin/create-cracklib-dict /usr/share/dict/* > /dev/null
424     # [ -f /lib/udev-state/devices.tar.bz2 ] && tar -C /dev -xjf /lib/udev-state/devices.tar.bz2
425 agaffney 1306 """
426     script = open(chroot_dir + "/tmp/extrastuff.sh", "w")
427     script.write(chrootscript)
428     script.close()
429     GLIUtility.spawn("chmod 755 /tmp/extrastuff.sh && /tmp/extrastuff.sh", chroot=chroot_dir)
430     GLIUtility.spawn("rm -rf /var/tmp/portage/* /usr/portage /tmp/*", chroot=chroot_dir)
431     print "Stage3 equivelant generation complete!"
432     elif mode == "grp":
433     for pkg in grp_packages:
434     if not gliportage.get_best_version_vdb(pkg):
435     print "Package " + pkg + " is not available for install from the LiveCD"
436 agaffney 1311 continue
437 agaffney 1700 pkglist = gliportage.get_deps(pkg, True)
438 agaffney 1311 for i, tmppkg in enumerate(pkglist):
439     print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
440 agaffney 1306 gliportage.copy_pkg_to_chroot(tmppkg)
441     gliportage.add_pkg_to_world(pkg)
442     print "GRP install complete!"
443 agaffney 1526 elif mode == "kernel":
444     kernelpkg = gliportage.get_best_version_vdb("sys-kernel/livecd-kernel")
445     gliportage.copy_pkg_to_chroot(kernelpkg)
446     print "LiveCD kernel installed!"
447 agaffney 1306 else:
448     print "You must specify an operating mode (-g or -s)!"
449 agaffney 1311 usage(progname)
450 agaffney 1306 sys.exit(1)

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20