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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1912 - (hide annotations) (download) (as text)
Mon Jul 28 03:48:15 2008 UTC (6 years, 1 month 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 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 codeman 1912 import GLILogger
16 agaffney 1204 from GLIException import GLIException
17 agaffney 1181
18     class GLIPortage(object):
19    
20 agaffney 1674 def __init__(self, chroot_dir, logger, debug, cc, compile_logfile):
21 agaffney 1182 self._chroot_dir = chroot_dir
22     self._logger = logger
23     self._debug = debug
24 agaffney 1205 self._cc = cc
25     self._compile_logfile = compile_logfile
26 agaffney 1181
27 agaffney 1674 def get_deps(self, pkgs, grp_install=False):
28 agaffney 1189 pkglist = []
29     if isinstance(pkgs, str):
30     pkgs = pkgs.split()
31     for pkg in pkgs:
32 agaffney 1305 if not pkg: continue
33 agaffney 1190 if self._debug: self._logger.log("get_deps(): pkg is " + pkg)
34 agaffney 1674 if not grp_install or not self.get_best_version_vdb(pkg):
35 agaffney 1190 if self._debug: self._logger.log("get_deps(): grabbing compile deps")
36 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")
37 agaffney 1189 else:
38 agaffney 1190 if self._debug: self._logger.log("get_deps(): grabbing binary deps")
39 agaffney 1210 # 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 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"):
43 agaffney 1210 if self._debug: self._logger.log("get_deps(): looking at " + tmppkg)
44 agaffney 1211 if self.get_best_version_vdb("=" + tmppkg):
45 agaffney 1210 if self._debug: self._logger.log("get_deps(): package " + tmppkg + " in host vdb...adding to tmppkglist")
46     tmppkglist.append(tmppkg)
47 agaffney 1190 if self._debug: self._logger.log("get_deps(): deplist for " + pkg + ": " + str(tmppkglist))
48 agaffney 1189 for tmppkg in tmppkglist:
49 agaffney 1192 if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist")
50 agaffney 1194 if not tmppkg in pkglist and not self.get_best_version_vdb_chroot("=" + tmppkg):
51 agaffney 1192 if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist")
52 agaffney 1189 pkglist.append(tmppkg)
53 agaffney 1190 if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist))
54 agaffney 1525 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 agaffney 1189 return pkglist
57 agaffney 1182
58 agaffney 1221 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 agaffney 1222 # elif parts[0] == "dir":
69     # entries.append(parts[1] + "/")
70 agaffney 1221 elif parts[0] == "sym":
71     entries.append(" ".join(parts[1:4]))
72     entries.sort()
73     return entries
74    
75 agaffney 1757 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 agaffney 1760 if not os.path.isdir(self._chroot_dir + "/var"):
84 agaffney 1762 os.mkdir(self._chroot_dir + "/var", 0755)
85 agaffney 1760 if not os.path.isdir(self._chroot_dir + "/var/cache"):
86 agaffney 1762 os.mkdir(self._chroot_dir + "/var/cache", 0755)
87 agaffney 1760 if not os.path.isdir(self._chroot_dir + "/var/cache/edb"):
88 agaffney 1762 os.mkdir(self._chroot_dir + "/var/cache/edb", 0775)
89 agaffney 1760 # chown to root:portage
90 agaffney 1761 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 agaffney 1757 return counter
97    
98 agaffney 1280 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False):
99 agaffney 1221 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 agaffney 1182
103 agaffney 1469 tmpdir = "/var/tmp"
104 agaffney 1790 image_dir = tmpdir + "/portage/" + package + "/image"
105 agaffney 1198 root_cmd = ""
106     tmp_chroot_dir = self._chroot_dir
107 agaffney 1469 portage_tmpdir = "/var/tmp"
108 agaffney 1270 vdb_dir = "/var/db/pkg/"
109 agaffney 1198 if use_root:
110     root_cmd = "ROOT=" + self._chroot_dir
111 agaffney 1203 tmp_chroot_dir = ""
112 agaffney 1469 portage_tmpdir = self._chroot_dir + "/var/tmp"
113 agaffney 1270 vdb_dir = self._chroot_dir + "/var/db/pkg/"
114 agaffney 1198
115 agaffney 1339 # 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 agaffney 1280 # 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 agaffney 1182 # 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 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)):
157 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
158    
159 agaffney 1757 # Update COUNTER
160 agaffney 1761 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 agaffney 1757 try:
163 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))
164 agaffney 1757 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 agaffney 1208 # 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 agaffney 1314 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
173 agaffney 1208 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
174    
175 agaffney 1182 # Create list of files for tar to work with from CONTENTS file in vdb entry
176 agaffney 1221 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
177 agaffney 1208 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 agaffney 1342 # if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
181 agaffney 1208 try:
182     tarfiles = open("/tmp/tarfilelist", "w")
183     for entry in entries:
184     parts = entry.split(" ")
185 agaffney 1222 # # Hack for symlink crappiness
186 agaffney 1221 # for symlink in symlinks:
187     # if parts[0].startswith(symlink):
188     # parts[0] = symlinks[symlink] + parts[0][len(symlink):]
189 agaffney 1208 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 agaffney 1182
194 agaffney 1208 # Use tar to transfer files into IMAGE directory
195 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'")
196 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)):
197 agaffney 1208 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
198 agaffney 1182
199 agaffney 1338 # Fix mode, uid, and gid of directories
200 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 '^$'")
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 agaffney 1338
211 agaffney 1221 # # 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 agaffney 1182
220     # Run pkg_setup
221     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package)
222 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)):
223 agaffney 1182 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 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)):
228 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
229    
230     # Copy files from image_dir to chroot
231 agaffney 1208 if not entries:
232 agaffney 1209 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
233 agaffney 1208 else:
234     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package)
235 agaffney 1291 # if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)):
236 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)):
237 agaffney 1208 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
238 agaffney 1182
239     # Run pkg_postinst
240     if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package)
241 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)):
242 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
243    
244     # Remove image_dir
245 agaffney 1208 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package)
246 agaffney 1314 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
247 agaffney 1182 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
248    
249 agaffney 1297 # 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 agaffney 1314 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)):
253 agaffney 1297 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
254    
255 agaffney 1182 def add_pkg_to_world(self, package):
256     if package.find("/") == -1:
257 agaffney 1195 package = self.get_best_version_vdb_chroot(package)
258 agaffney 1182 if not package: return False
259 agaffney 1205 expr = re.compile('^=?(.+?/.+?)(-\d.+)?$')
260 agaffney 1182 res = expr.match(package)
261     if res:
262 agaffney 1767 world_f = open(self._chroot_dir + "/var/lib/portage/world", "a")
263     world_f.write(res.group(1) + "\n")
264     world_f.close()
265 agaffney 1182
266 agaffney 1185 def get_best_version_vdb(self, package):
267 agaffney 1285 if package.startswith('='):
268     package = package[1:]
269     if GLIUtility.is_file("/var/db/pkg/" + package):
270     return package
271 agaffney 1286 else:
272     return ""
273 agaffney 1285 else:
274     return GLIUtility.spawn("portageq best_version / " + package, return_output=True)[1].strip()
275 agaffney 1189
276 agaffney 1194 def get_best_version_vdb_chroot(self, package):
277 agaffney 1287 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 agaffney 1194
286 agaffney 1184 # def get_best_version_tree(self, package):
287     # return portage.best(tree.match(package))
288 agaffney 1205
289 codeman 1675 def emerge(self, packages, grp_install=False, add_to_world=True):
290 agaffney 1205 if isinstance(packages, str):
291     packages = packages.split()
292 codeman 1899 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 agaffney 1700 pkglist = self.get_deps(packages, grp_install)
297 agaffney 1205 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
298     for i, pkg in enumerate(pkglist):
299 agaffney 1305 if not pkg: continue
300 agaffney 1205 if self._debug: self._logger.log("install_packages(): processing package " + pkg)
301 agaffney 1208 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
302 agaffney 1674 if not grp_install or not self.get_best_version_vdb("=" + pkg):
303 agaffney 1205 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 agaffney 1208 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
313 agaffney 1205 if add_to_world:
314     for package in packages:
315     self.add_pkg_to_world(package)
316 agaffney 1306
317 agaffney 1886 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 agaffney 1306
327 agaffney 1886 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 agaffney 1311 def usage(progname):
333 agaffney 1306 print """
334 codeman 1912 Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-l|--logfile <logfile>] [-h|--help]
335 agaffney 1306
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 agaffney 1527 -k|--kernel Install kernel and modules from LiveCD into the chroot
348    
349 codeman 1912 -l|--logfile Sets the logfile for the ouput. defaults to cwd/install.log
350    
351 agaffney 1306 -h|--help Display this help
352 agaffney 1311 """ % (progname)
353 agaffney 1306
354     if __name__ == "__main__":
355     chroot_dir = "/mnt/gentoo"
356 codeman 1912 logfile = None
357 agaffney 1306 mode = None
358     grp_packages = []
359 agaffney 1311 progname = sys.argv.pop(0)
360 agaffney 1307 while len(sys.argv):
361 agaffney 1306 arg = sys.argv.pop(0)
362     if arg == "-c" or arg == "--chroot-dir":
363     chroot_dir = sys.argv.pop(0)
364 codeman 1912 elif arg == "-l" or arg == "--logfile":
365     logfile = sys.argv.pop(0)
366 agaffney 1306 elif arg == "-g" or arg == "--grp":
367     mode = "grp"
368     elif arg == "-s" or arg == "--stage3":
369     mode = "stage3"
370 agaffney 1526 elif arg == "-k" or arg == "--kernel":
371     mode = "kernel"
372 agaffney 1306 elif arg == "-h" or arg == "--help":
373 agaffney 1311 usage(progname)
374 agaffney 1306 sys.exit(0)
375     elif arg[0] == "-":
376 agaffney 1311 usage(progname)
377 agaffney 1306 sys.exit(1)
378     else:
379     grp_packages.append(arg)
380 codeman 1912 logger = GLILogger.Logger(logfile)
381     gliportage = GLIPortage(chroot_dir, logger, True, None, False)
382 agaffney 1306 if mode == "stage3":
383     try:
384 agaffney 1886 systempkgs = gliportage.get_system_packages()
385 agaffney 1306 except:
386 agaffney 1886 print "Could not open generate list of system packages!"
387 agaffney 1306 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 agaffney 1310 print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
399 agaffney 1306 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 agaffney 1888 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 agaffney 1306 """
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 agaffney 1311 continue
443 agaffney 1700 pkglist = gliportage.get_deps(pkg, True)
444 agaffney 1311 for i, tmppkg in enumerate(pkglist):
445     print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
446 agaffney 1306 gliportage.copy_pkg_to_chroot(tmppkg)
447     gliportage.add_pkg_to_world(pkg)
448     print "GRP install complete!"
449 agaffney 1526 elif mode == "kernel":
450 codeman 1912 #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 agaffney 1526 print "LiveCD kernel installed!"
533 agaffney 1306 else:
534     print "You must specify an operating mode (-g or -s)!"
535 agaffney 1311 usage(progname)
536 agaffney 1306 sys.exit(1)

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20