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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/GLIPortage.py Revision 1297 branches/qs/src/GLIPortage.py Revision 1909
3# This source code is distributed under the terms of version 2 of the GNU 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 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. 5# of which can be found in the main directory of this project.
6Gentoo Linux Installer 6Gentoo Linux Installer
7 7
8$Id: GLIPortage.py,v 1.40 2006/02/11 17:26:33 agaffney Exp $ 8$Id: GLIPortage.py,v 1.57 2006/09/13 18:29:13 agaffney Exp $
9""" 9"""
10 10
11import re 11import re
12import os 12import os
13import sys
13import GLIUtility 14import GLIUtility
14from GLIException import GLIException 15from GLIException import GLIException
15 16
16class GLIPortage(object): 17class GLIPortage(object):
17 18
18 def __init__(self, chroot_dir, grp_install, logger, debug, cc, compile_logfile): 19 def __init__(self, chroot_dir, logger, debug, cc, compile_logfile):
19 self._chroot_dir = chroot_dir 20 self._chroot_dir = chroot_dir
20 self._grp_install = grp_install
21 self._logger = logger 21 self._logger = logger
22 self._debug = debug 22 self._debug = debug
23 self._cc = cc 23 self._cc = cc
24 self._compile_logfile = compile_logfile 24 self._compile_logfile = compile_logfile
25 25
26 def get_deps(self, pkgs): 26 def get_deps(self, pkgs, grp_install=False):
27 pkglist = [] 27 pkglist = []
28 if isinstance(pkgs, str): 28 if isinstance(pkgs, str):
29 pkgs = pkgs.split() 29 pkgs = pkgs.split()
30 for pkg in pkgs: 30 for pkg in pkgs:
31 if not pkg: continue
31 if self._debug: self._logger.log("get_deps(): pkg is " + pkg) 32 if self._debug: self._logger.log("get_deps(): pkg is " + pkg)
32 if not self._grp_install or not self.get_best_version_vdb(pkg): 33 if not grp_install or not self.get_best_version_vdb(pkg):
33 if self._debug: self._logger.log("get_deps(): grabbing compile deps") 34 if self._debug: self._logger.log("get_deps(): grabbing compile deps")
34 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") 35 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")
35 else: 36 else:
36 if self._debug: self._logger.log("get_deps(): grabbing binary deps") 37 if self._debug: self._logger.log("get_deps(): grabbing binary deps")
37 # The runtimedeps.py script generates a package install order that is *very* different from emerge itself 38 # The runtimedeps.py script generates a package install order that is *very* different from emerge itself
38# tmppkglist = GLIUtility.spawn("python ../../runtimedeps.py " + self._chroot_dir + " " + pkg, return_output=True)[1].strip().split("\n") 39# tmppkglist = GLIUtility.spawn("python ../../runtimedeps.py " + self._chroot_dir + " " + pkg, return_output=True)[1].strip().split("\n")
39 tmppkglist = [] 40 tmppkglist = []
40 for tmppkg in 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"): 41 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"):
41 if self._debug: self._logger.log("get_deps(): looking at " + tmppkg) 42 if self._debug: self._logger.log("get_deps(): looking at " + tmppkg)
42 if self.get_best_version_vdb("=" + tmppkg): 43 if self.get_best_version_vdb("=" + tmppkg):
43 if self._debug: self._logger.log("get_deps(): package " + tmppkg + " in host vdb...adding to tmppkglist") 44 if self._debug: self._logger.log("get_deps(): package " + tmppkg + " in host vdb...adding to tmppkglist")
44 tmppkglist.append(tmppkg) 45 tmppkglist.append(tmppkg)
45 if self._debug: self._logger.log("get_deps(): deplist for " + pkg + ": " + str(tmppkglist)) 46 if self._debug: self._logger.log("get_deps(): deplist for " + pkg + ": " + str(tmppkglist))
47 if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist") 48 if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist")
48 if not tmppkg in pkglist and not self.get_best_version_vdb_chroot("=" + tmppkg): 49 if not tmppkg in pkglist and not self.get_best_version_vdb_chroot("=" + tmppkg):
49 if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist") 50 if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist")
50 pkglist.append(tmppkg) 51 pkglist.append(tmppkg)
51 if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist)) 52 if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist))
53 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")
52 return pkglist 55 return pkglist
53 56
54 def parse_vdb_contents(self, file): 57 def parse_vdb_contents(self, file):
55 entries = [] 58 entries = []
56 try: 59 try:
66 elif parts[0] == "sym": 69 elif parts[0] == "sym":
67 entries.append(" ".join(parts[1:4])) 70 entries.append(" ".join(parts[1:4]))
68 entries.sort() 71 entries.sort()
69 return entries 72 return entries
70 73
74 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 if not os.path.isdir(self._chroot_dir + "/var"):
83 os.mkdir(self._chroot_dir + "/var", 0755)
84 if not os.path.isdir(self._chroot_dir + "/var/cache"):
85 os.mkdir(self._chroot_dir + "/var/cache", 0755)
86 if not os.path.isdir(self._chroot_dir + "/var/cache/edb"):
87 os.mkdir(self._chroot_dir + "/var/cache/edb", 0775)
88 # chown to root:portage
89 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 return counter
96
71 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False): 97 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False):
72 symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/', 98 symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/',
73 '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/', 99 '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/',
74 '/etc/gconf': '/usr/livecd/gconf/' } 100 '/etc/gconf': '/usr/livecd/gconf/' }
75 101
76 tmpdir = "/var/tmp/portage" 102 tmpdir = "/var/tmp"
77 image_dir = tmpdir + "/" + package.split("/")[1] + "/image" 103 image_dir = tmpdir + "/portage/" + package + "/image"
78 root_cmd = "" 104 root_cmd = ""
79 tmp_chroot_dir = self._chroot_dir 105 tmp_chroot_dir = self._chroot_dir
80 portage_tmpdir = "/var/tmp/portage" 106 portage_tmpdir = "/var/tmp"
81 vdb_dir = "/var/db/pkg/" 107 vdb_dir = "/var/db/pkg/"
82 if use_root: 108 if use_root:
83 root_cmd = "ROOT=" + self._chroot_dir 109 root_cmd = "ROOT=" + self._chroot_dir
84 tmp_chroot_dir = "" 110 tmp_chroot_dir = ""
85 portage_tmpdir = self._chroot_dir + "/var/tmp/portage" 111 portage_tmpdir = self._chroot_dir + "/var/tmp"
86 vdb_dir = self._chroot_dir + "/var/db/pkg/" 112 vdb_dir = self._chroot_dir + "/var/db/pkg/"
113
114 # 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)
87 143
88 # Check to see if package is actually in vdb 144 # Check to see if package is actually in vdb
89 if not GLIUtility.is_file("/var/db/pkg/" + package): 145 if not GLIUtility.is_file("/var/db/pkg/" + package):
90 if ignore_missing: 146 if ignore_missing:
91 if self._debug: 147 if self._debug:
94 else: 150 else:
95 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package) 151 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
96 152
97 # Copy the vdb entry for the package from the LiveCD to the chroot 153 # Copy the vdb entry for the package from the LiveCD to the chroot
98 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package) 154 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package)
99 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)): 155 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)):
100 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package) 156 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
157
158 # Update COUNTER
159 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 try:
162 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 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)
101 168
102 # Create the image dir in the chroot 169 # Create the image dir in the chroot
103 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'") 170 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'")
104 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir)): 171 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
105 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package) 172 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
106 173
107 # Create list of files for tar to work with from CONTENTS file in vdb entry 174 # Create list of files for tar to work with from CONTENTS file in vdb entry
108 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS") 175 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
109 if not entries: 176 if not entries:
110 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup") 177 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup")
111 else: 178 else:
112 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries)) 179# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
113 try: 180 try:
114 tarfiles = open("/tmp/tarfilelist", "w") 181 tarfiles = open("/tmp/tarfilelist", "w")
115 for entry in entries: 182 for entry in entries:
116 parts = entry.split(" ") 183 parts = entry.split(" ")
117# # Hack for symlink crappiness 184# # Hack for symlink crappiness
123 except: 190 except:
124 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package) 191 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)
125 192
126 # Use tar to transfer files into IMAGE directory 193 # Use tar to transfer files into IMAGE directory
127 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'") 194 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'")
128 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")): 195 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)):
129 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package) 196 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
197
198 # Fix mode, uid, and gid of directories
199 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])
130 209
131# # More symlink crappiness hacks 210# # More symlink crappiness hacks
132# for symlink in symlinks: 211# for symlink in symlinks:
133## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]): 212## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]):
134# if os.path.islink(self._chroot_dir + image_dir + symlink): 213# if os.path.islink(self._chroot_dir + image_dir + symlink):
137# if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + 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)):
138# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package) 217# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package)
139 218
140 # Run pkg_setup 219 # Run pkg_setup
141 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package) 220 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package)
142 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild setup", chroot=tmp_chroot_dir)): 221 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)):
143 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package) 222 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package)
144 223
145 # Run pkg_preinst 224 # Run pkg_preinst
146 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package) 225 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package)
147 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild preinst", chroot=tmp_chroot_dir)): 226 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)):
148 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package) 227 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
149 228
150 # Copy files from image_dir to chroot 229 # Copy files from image_dir to chroot
151 if not entries: 230 if not entries:
152 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /") 231 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
153 else: 232 else:
154 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package) 233 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package)
155# if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)): 234# if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)):
156 if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -C " + self._chroot_dir + image_dir + "/ -c . | tar -C " + self._chroot_dir + "/ -x")): 235 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)):
157 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package) 236 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
158 237
159 # Run pkg_postinst 238 # Run pkg_postinst
160 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package) 239 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package)
161 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir)): 240 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)):
162 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package) 241 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
163 242
164 # Remove image_dir 243 # Remove image_dir
165 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package) 244 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package)
166 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir)): 245 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
167 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package) 246 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
168 247
169 # Run env-update 248 # Run env-update
170 if not use_root: 249 if not use_root:
171 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot") 250 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot")
172 if not GLIUtility.exitstatus(GLIUtility.spawn("env-update", chroot=self._chroot_dir)): 251 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)):
173 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package) 252 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
174 253
175 def add_pkg_to_world(self, package): 254 def add_pkg_to_world(self, package):
176 if package.find("/") == -1: 255 if package.find("/") == -1:
177 package = self.get_best_version_vdb_chroot(package) 256 package = self.get_best_version_vdb_chroot(package)
178 if not package: return False 257 if not package: return False
179 expr = re.compile('^=?(.+?/.+?)(-\d.+)?$') 258 expr = re.compile('^=?(.+?/.+?)(-\d.+)?$')
180 res = expr.match(package) 259 res = expr.match(package)
181 if res: 260 if res:
182 GLIUtility.spawn("echo " + res.group(1) + " >> " + self._chroot_dir + "/var/lib/portage/world") 261 world_f = open(self._chroot_dir + "/var/lib/portage/world", "a")
262 world_f.write(res.group(1) + "\n")
263 world_f.close()
183 264
184 def get_best_version_vdb(self, package): 265 def get_best_version_vdb(self, package):
185 if package.startswith('='): 266 if package.startswith('='):
186 package = package[1:] 267 package = package[1:]
187 if GLIUtility.is_file("/var/db/pkg/" + package): 268 if GLIUtility.is_file("/var/db/pkg/" + package):
202 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip() 283 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip()
203 284
204# def get_best_version_tree(self, package): 285# def get_best_version_tree(self, package):
205# return portage.best(tree.match(package)) 286# return portage.best(tree.match(package))
206 287
207 def emerge(self, packages, add_to_world=True): 288 def emerge(self, packages, grp_install=False, add_to_world=True):
208 if isinstance(packages, str): 289 if isinstance(packages, str):
209 packages = packages.split() 290 packages = packages.split()
291 if len(packages) > 1:
292 self._cc.addNotification("progress", (0, "Calculating dependencies for your packages"))
293 else:
210 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages))) 294 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages)))
211 pkglist = self.get_deps(packages) 295 pkglist = self.get_deps(packages, grp_install)
212 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist)) 296 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
213 for i, pkg in enumerate(pkglist): 297 for i, pkg in enumerate(pkglist):
298 if not pkg: continue
214 if self._debug: self._logger.log("install_packages(): processing package " + pkg) 299 if self._debug: self._logger.log("install_packages(): processing package " + pkg)
215 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")")) 300 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
216 if not self._grp_install or not self.get_best_version_vdb("=" + pkg): 301 if not grp_install or not self.get_best_version_vdb("=" + pkg):
217 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True) 302 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)
218# status = self._emerge("=" + pkg) 303# status = self._emerge("=" + pkg)
219 if not GLIUtility.exitsuccess(status): 304 if not GLIUtility.exitsuccess(status):
220 raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") 305 raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
221 else: 306 else:
225# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") 310# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
226 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")")) 311 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
227 if add_to_world: 312 if add_to_world:
228 for package in packages: 313 for package in packages:
229 self.add_pkg_to_world(package) 314 self.add_pkg_to_world(package)
315
316 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
326 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
331def usage(progname):
332 print """
333Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help]
334
335Options:
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 -k|--kernel Install kernel and modules from LiveCD into the chroot
347
348 -h|--help Display this help
349""" % (progname)
350
351if __name__ == "__main__":
352 chroot_dir = "/mnt/gentoo"
353 mode = None
354 grp_packages = []
355 progname = sys.argv.pop(0)
356 while len(sys.argv):
357 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 elif arg == "-k" or arg == "--kernel":
365 mode = "kernel"
366 elif arg == "-h" or arg == "--help":
367 usage(progname)
368 sys.exit(0)
369 elif arg[0] == "-":
370 usage(progname)
371 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 systempkgs = gliportage.get_system_packages()
379 except:
380 print "Could not open generate list of system packages!"
381 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 print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
393 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 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 """
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 continue
437 pkglist = gliportage.get_deps(pkg, True)
438 for i, tmppkg in enumerate(pkglist):
439 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
440 gliportage.copy_pkg_to_chroot(tmppkg)
441 gliportage.add_pkg_to_world(pkg)
442 print "GRP install complete!"
443 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 else:
448 print "You must specify an operating mode (-g or -s)!"
449 usage(progname)
450 sys.exit(1)

Legend:
Removed from v.1297  
changed lines
  Added in v.1909

  ViewVC Help
Powered by ViewVC 1.1.20