/[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/overhaul/src/GLIPortage.py Revision 1760
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
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", mode=0755)
84 if not os.path.isdir(self._chroot_dir + "/var/cache"):
85 os.mkdir(self._chroot_dir + "/var/cache", mode=0755)
86 if not os.path.isdir(self._chroot_dir + "/var/cache/edb"):
87 os.mkdir(self._chroot_dir + "/var/cache/edb", mode=0775)
88 # chown to root:portage
89 counter_f = open(self._chroot_dir + "/var/cache/edb/counter", "w")
90 counter_f.write(str(counter))
91 counter_f.close()
92 return counter
93
71 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False): 94 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/', 95 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/', 96 '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/',
74 '/etc/gconf': '/usr/livecd/gconf/' } 97 '/etc/gconf': '/usr/livecd/gconf/' }
75 98
76 tmpdir = "/var/tmp/portage" 99 tmpdir = "/var/tmp"
77 image_dir = tmpdir + "/" + package.split("/")[1] + "/image" 100 image_dir = tmpdir + "/portage/" + package.split("/")[1] + "/image"
78 root_cmd = "" 101 root_cmd = ""
79 tmp_chroot_dir = self._chroot_dir 102 tmp_chroot_dir = self._chroot_dir
80 portage_tmpdir = "/var/tmp/portage" 103 portage_tmpdir = "/var/tmp"
81 vdb_dir = "/var/db/pkg/" 104 vdb_dir = "/var/db/pkg/"
82 if use_root: 105 if use_root:
83 root_cmd = "ROOT=" + self._chroot_dir 106 root_cmd = "ROOT=" + self._chroot_dir
84 tmp_chroot_dir = "" 107 tmp_chroot_dir = ""
85 portage_tmpdir = self._chroot_dir + "/var/tmp/portage" 108 portage_tmpdir = self._chroot_dir + "/var/tmp"
86 vdb_dir = self._chroot_dir + "/var/db/pkg/" 109 vdb_dir = self._chroot_dir + "/var/db/pkg/"
110
111 # Create /tmp, /var/tmp, and /var/lib/portage with proper permissions
112 oldumask = os.umask(0)
113 if not os.path.exists(self._chroot_dir + "/tmp"):
114 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /tmp doesn't exist in chroot...creating with proper permissions")
115 try:
116 os.mkdir(self._chroot_dir + "/tmp", 01777)
117 except:
118 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /tmp in chroot")
119 if not os.path.exists(self._chroot_dir + "/var/tmp"):
120 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/tmp doesn't exist in chroot...creating with proper permissions")
121 try:
122 os.mkdir(self._chroot_dir + "/var", 0755)
123 except:
124 pass
125 try:
126 os.mkdir(self._chroot_dir + "/var/tmp", 01777)
127 except:
128 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/tmp in chroot")
129 if not os.path.exists(self._chroot_dir + "/var/lib/portage"):
130 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/lib/portage doesn't exist in chroot...creating with proper permissions")
131 try:
132 os.mkdir(self._chroot_dir + "/var/lib", 0755)
133 except:
134 pass
135 try:
136 os.mkdir(self._chroot_dir + "/var/lib/portage", 02750)
137 except:
138 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/lib/portage in chroot")
139 os.umask(oldumask)
87 140
88 # Check to see if package is actually in vdb 141 # Check to see if package is actually in vdb
89 if not GLIUtility.is_file("/var/db/pkg/" + package): 142 if not GLIUtility.is_file("/var/db/pkg/" + package):
90 if ignore_missing: 143 if ignore_missing:
91 if self._debug: 144 if self._debug:
94 else: 147 else:
95 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package) 148 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
96 149
97 # Copy the vdb entry for the package from the LiveCD to the chroot 150 # 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) 151 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)): 152 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) 153 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
154
155 # Update COUNTER
156 try:
157 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): calling update_counter() to get updated COUNTER value for " + package)
158 counter = self.update_counter()
159 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): updating COUNTER value in vdb entry for " + package)
160 counter_f = open(self._chroot_dir + "/var/db/pkg/" + package + "/COUNTER", "w")
161 counter_f.write(str(counter))
162 counter_f.close()
163 except:
164 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not update COUNTER for " + package)
101 165
102 # Create the image dir in the chroot 166 # 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 + "'") 167 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)): 168 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) 169 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
106 170
107 # Create list of files for tar to work with from CONTENTS file in vdb entry 171 # 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") 172 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
109 if not entries: 173 if not entries:
110 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup") 174 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup")
111 else: 175 else:
112 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries)) 176# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
113 try: 177 try:
114 tarfiles = open("/tmp/tarfilelist", "w") 178 tarfiles = open("/tmp/tarfilelist", "w")
115 for entry in entries: 179 for entry in entries:
116 parts = entry.split(" ") 180 parts = entry.split(" ")
117# # Hack for symlink crappiness 181# # Hack for symlink crappiness
123 except: 187 except:
124 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package) 188 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)
125 189
126 # Use tar to transfer files into IMAGE directory 190 # 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'") 191 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")): 192 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) 193 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
194
195 # Fix mode, uid, and gid of directories
196 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 '^$'")
197 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")
198 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): found the following directories: " + str(dirlist))
199 if not dirlist or dirlist[0] == "":
200 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!")
201 for dir in dirlist:
202 dirstat = os.stat(dir)
203 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)
204 os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5])
205 os.chmod(self._chroot_dir + image_dir + dir, dirstat[0])
130 206
131# # More symlink crappiness hacks 207# # More symlink crappiness hacks
132# for symlink in symlinks: 208# for symlink in symlinks:
133## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]): 209## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]):
134# if os.path.islink(self._chroot_dir + image_dir + symlink): 210# 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)): 213# 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) 214# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package)
139 215
140 # Run pkg_setup 216 # Run pkg_setup
141 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package) 217 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)): 218 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " FEATURES=noauto 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) 219 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package)
144 220
145 # Run pkg_preinst 221 # Run pkg_preinst
146 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package) 222 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)): 223 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " FEATURES=noauto 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) 224 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
149 225
150 # Copy files from image_dir to chroot 226 # Copy files from image_dir to chroot
151 if not entries: 227 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 /") 228 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
153 else: 229 else:
154 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package) 230 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)): 231# 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")): 232 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) 233 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
158 234
159 # Run pkg_postinst 235 # Run pkg_postinst
160 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package) 236 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)): 237 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " FEATURES=noauto 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) 238 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
163 239
164 # Remove image_dir 240 # Remove image_dir
165 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package) 241 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)): 242 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) 243 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
168 244
169 # Run env-update 245 # Run env-update
170 if not use_root: 246 if not use_root:
171 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot") 247 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)): 248 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) 249 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
174 250
175 def add_pkg_to_world(self, package): 251 def add_pkg_to_world(self, package):
176 if package.find("/") == -1: 252 if package.find("/") == -1:
177 package = self.get_best_version_vdb_chroot(package) 253 package = self.get_best_version_vdb_chroot(package)
202 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip() 278 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip()
203 279
204# def get_best_version_tree(self, package): 280# def get_best_version_tree(self, package):
205# return portage.best(tree.match(package)) 281# return portage.best(tree.match(package))
206 282
207 def emerge(self, packages, add_to_world=True): 283 def emerge(self, packages, grp_install=False, add_to_world=True):
208 if isinstance(packages, str): 284 if isinstance(packages, str):
209 packages = packages.split() 285 packages = packages.split()
210 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages))) 286 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages)))
211 pkglist = self.get_deps(packages) 287 pkglist = self.get_deps(packages, grp_install)
212 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist)) 288 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
213 for i, pkg in enumerate(pkglist): 289 for i, pkg in enumerate(pkglist):
290 if not pkg: continue
214 if self._debug: self._logger.log("install_packages(): processing package " + pkg) 291 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)) + ")")) 292 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): 293 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) 294 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) 295# status = self._emerge("=" + pkg)
219 if not GLIUtility.exitsuccess(status): 296 if not GLIUtility.exitsuccess(status):
220 raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") 297 raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
221 else: 298 else:
225# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") 302# 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)) + ")")) 303 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
227 if add_to_world: 304 if add_to_world:
228 for package in packages: 305 for package in packages:
229 self.add_pkg_to_world(package) 306 self.add_pkg_to_world(package)
307
308
309def usage(progname):
310 print """
311Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help]
312
313Options:
314
315 -c|--chroot-dir Specifies the directory where your chroot is. This is
316 "/mnt/gentoo" by default.
317
318 -g|--grp Install specified packages and dependencies into chroot
319 by using files from the LiveCD.
320
321 -s|--stage3 Create a stage3 equivelant in the chroot directory by using
322 files from the LiveCD.
323
324 -k|--kernel Install kernel and modules from LiveCD into the chroot
325
326 -h|--help Display this help
327""" % (progname)
328
329if __name__ == "__main__":
330 chroot_dir = "/mnt/gentoo"
331 mode = None
332 grp_packages = []
333 progname = sys.argv.pop(0)
334 while len(sys.argv):
335 arg = sys.argv.pop(0)
336 if arg == "-c" or arg == "--chroot-dir":
337 chroot_dir = sys.argv.pop(0)
338 elif arg == "-g" or arg == "--grp":
339 mode = "grp"
340 elif arg == "-s" or arg == "--stage3":
341 mode = "stage3"
342 elif arg == "-k" or arg == "--kernel":
343 mode = "kernel"
344 elif arg == "-h" or arg == "--help":
345 usage(progname)
346 sys.exit(0)
347 elif arg[0] == "-":
348 usage(progname)
349 sys.exit(1)
350 else:
351 grp_packages.append(arg)
352
353 gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
354 if mode == "stage3":
355 if not GLIUtility.is_file("/usr/livecd/systempkgs.txt"):
356 print "Required file /usr/livecd/systempkgs.txt does not exist!"
357 sys.exit(1)
358 try:
359 syspkgs = open("/usr/livecd/systempkgs.txt", "r")
360 systempkgs = syspkgs.readlines()
361 syspkgs.close()
362 except:
363 print "Could not open /usr/livecd/systempkgs.txt!"
364 sys.exit(1)
365
366 # Pre-create /lib (and possible /lib32 and /lib64)
367 if os.path.islink("/lib") and os.readlink("/lib") == "lib64":
368 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")):
369 print "Could not precreate /lib64 dir and /lib -> /lib64 symlink"
370 sys.exit(1)
371
372 syspkglen = len(systempkgs)
373 for i, pkg in enumerate(systempkgs):
374 pkg = pkg.strip()
375 print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
376 gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True)
377 GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf")
378 GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile")
379 GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab")
380
381 # Nasty, nasty, nasty hack because vapier is a tool
382 for tmpfile in ("/etc/passwd", "/etc/group", "/etc/shadow"):
383 GLIUtility.spawn("grep -ve '^gentoo' " + tmpfile + " > " + chroot_dir + tmpfile)
384
385 chrootscript = r"""
386 #!/bin/bash
387
388 source /etc/make.conf
389 export LDPATH="/usr/lib/gcc-lib/${CHOST}/$(cd /usr/lib/gcc-lib/${CHOST} && ls -1 | head -n 1)"
390
391 ldconfig $LDPATH
392 gcc-config 1
393 env-update
394 source /etc/profile
395 modules-update
396 [ -f /usr/bin/binutils-config ] && binutils-config 1
397 source /etc/profile
398 #mount -t proc none /proc
399 #cd /dev
400 #/sbin/MAKEDEV generic-i386
401 #umount /proc
402 [ -f /lib/udev-state/devices.tar.bz2 ] && tar -C /dev -xjf /lib/udev-state/devices.tar.bz2
403 """
404 script = open(chroot_dir + "/tmp/extrastuff.sh", "w")
405 script.write(chrootscript)
406 script.close()
407 GLIUtility.spawn("chmod 755 /tmp/extrastuff.sh && /tmp/extrastuff.sh", chroot=chroot_dir)
408 GLIUtility.spawn("rm -rf /var/tmp/portage/* /usr/portage /tmp/*", chroot=chroot_dir)
409 print "Stage3 equivelant generation complete!"
410 elif mode == "grp":
411 for pkg in grp_packages:
412 if not gliportage.get_best_version_vdb(pkg):
413 print "Package " + pkg + " is not available for install from the LiveCD"
414 continue
415 pkglist = gliportage.get_deps(pkg, True)
416 for i, tmppkg in enumerate(pkglist):
417 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
418 gliportage.copy_pkg_to_chroot(tmppkg)
419 gliportage.add_pkg_to_world(pkg)
420 print "GRP install complete!"
421 elif mode == "kernel":
422 kernelpkg = gliportage.get_best_version_vdb("sys-kernel/livecd-kernel")
423 gliportage.copy_pkg_to_chroot(kernelpkg)
424 print "LiveCD kernel installed!"
425 else:
426 print "You must specify an operating mode (-g or -s)!"
427 usage(progname)
428 sys.exit(1)

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

  ViewVC Help
Powered by ViewVC 1.1.20