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

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

  ViewVC Help
Powered by ViewVC 1.1.20