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

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

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

Revision 1307 Revision 1339
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.44 2006/02/20 17:11:41 agaffney Exp $ 8$Id: GLIPortage.py,v 1.50 2006/03/05 04:16:04 agaffney Exp $
9""" 9"""
10 10
11import re 11import re
12import os 12import os
13import sys 13import sys
85 root_cmd = "ROOT=" + self._chroot_dir 85 root_cmd = "ROOT=" + self._chroot_dir
86 tmp_chroot_dir = "" 86 tmp_chroot_dir = ""
87 portage_tmpdir = self._chroot_dir + "/var/tmp/portage" 87 portage_tmpdir = self._chroot_dir + "/var/tmp/portage"
88 vdb_dir = self._chroot_dir + "/var/db/pkg/" 88 vdb_dir = self._chroot_dir + "/var/db/pkg/"
89 89
90 # Create /tmp, /var/tmp, and /var/lib/portage with proper permissions
91 oldumask = os.umask(0)
92 if not os.path.exists(self._chroot_dir + "/tmp"):
93 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /tmp doesn't exist in chroot...creating with proper permissions")
94 try:
95 os.mkdir(self._chroot_dir + "/tmp", 01777)
96 except:
97 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /tmp in chroot")
98 if not os.path.exists(self._chroot_dir + "/var/tmp"):
99 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/tmp doesn't exist in chroot...creating with proper permissions")
100 try:
101 os.mkdir(self._chroot_dir + "/var", 0755)
102 except:
103 pass
104 try:
105 os.mkdir(self._chroot_dir + "/var/tmp", 01777)
106 except:
107 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/tmp in chroot")
108 if not os.path.exists(self._chroot_dir + "/var/lib/portage"):
109 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/lib/portage doesn't exist in chroot...creating with proper permissions")
110 try:
111 os.mkdir(self._chroot_dir + "/var/lib", 0755)
112 except:
113 pass
114 try:
115 os.mkdir(self._chroot_dir + "/var/lib/portage", 02750)
116 except:
117 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/lib/portage in chroot")
118 os.umask(oldumask)
119
90 # Check to see if package is actually in vdb 120 # Check to see if package is actually in vdb
91 if not GLIUtility.is_file("/var/db/pkg/" + package): 121 if not GLIUtility.is_file("/var/db/pkg/" + package):
92 if ignore_missing: 122 if ignore_missing:
93 if self._debug: 123 if self._debug:
94 self._logger.log("DEBUG: copy_pkg_to_chroot(): package " + package + " does not have a vdb entry but ignore_missing=True...ignoring error") 124 self._logger.log("DEBUG: copy_pkg_to_chroot(): package " + package + " does not have a vdb entry but ignore_missing=True...ignoring error")
96 else: 126 else:
97 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package) 127 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
98 128
99 # Copy the vdb entry for the package from the LiveCD to the chroot 129 # Copy the vdb entry for the package from the LiveCD to the chroot
100 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package) 130 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package)
101 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)): 131 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)):
102 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package) 132 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
103 133
104 # Create the image dir in the chroot 134 # Create the image dir in the chroot
105 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'") 135 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'")
106 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir)): 136 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
107 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package) 137 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
108 138
109 # Create list of files for tar to work with from CONTENTS file in vdb entry 139 # Create list of files for tar to work with from CONTENTS file in vdb entry
110 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS") 140 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
111 if not entries: 141 if not entries:
125 except: 155 except:
126 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package) 156 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)
127 157
128 # Use tar to transfer files into IMAGE directory 158 # Use tar to transfer files into IMAGE directory
129 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'") 159 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'")
130 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")): 160 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)):
131 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package) 161 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
162
163 # Fix mode, uid, and gid of directories
164 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running find " + self._chroot_dir + image_dir + " -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'")
165 dirlist = GLIUtility.spawn("find " + self._chroot_dir + image_dir + " -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'", return_output=True)[1].strip().split("\n")
166 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): found the following directories: " + str(dirlist))
167 if not dirlist or dirlist[0] == "":
168 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!")
169 for dir in dirlist:
170 dirstat = os.stat(dir)
171 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)
172 os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5])
173 os.chmod(self._chroot_dir + image_dir + dir, dirstat[0])
132 174
133# # More symlink crappiness hacks 175# # More symlink crappiness hacks
134# for symlink in symlinks: 176# for symlink in symlinks:
135## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]): 177## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]):
136# if os.path.islink(self._chroot_dir + image_dir + symlink): 178# if os.path.islink(self._chroot_dir + image_dir + symlink):
139# if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)): 181# if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)):
140# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package) 182# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package)
141 183
142 # Run pkg_setup 184 # Run pkg_setup
143 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package) 185 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package)
144 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild setup", chroot=tmp_chroot_dir)): 186 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild setup", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
145 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package) 187 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package)
146 188
147 # Run pkg_preinst 189 # Run pkg_preinst
148 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package) 190 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package)
149 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild preinst", chroot=tmp_chroot_dir)): 191 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild preinst", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
150 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package) 192 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
151 193
152 # Copy files from image_dir to chroot 194 # Copy files from image_dir to chroot
153 if not entries: 195 if not entries:
154 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /") 196 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
155 else: 197 else:
156 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package) 198 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package)
157# if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)): 199# if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)):
158 if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -C " + self._chroot_dir + image_dir + "/ -c . | tar -C " + self._chroot_dir + "/ -x")): 200 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)):
159 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package) 201 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
160 202
161 # Run pkg_postinst 203 # Run pkg_postinst
162 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package) 204 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package)
163 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir)): 205 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
164 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package) 206 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
165 207
166 # Remove image_dir 208 # Remove image_dir
167 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package) 209 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package)
168 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir)): 210 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
169 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package) 211 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
170 212
171 # Run env-update 213 # Run env-update
172 if not use_root: 214 if not use_root:
173 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot") 215 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot")
174 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir)): 216 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)):
175 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package) 217 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
176 218
177 def add_pkg_to_world(self, package): 219 def add_pkg_to_world(self, package):
178 if package.find("/") == -1: 220 if package.find("/") == -1:
179 package = self.get_best_version_vdb_chroot(package) 221 package = self.get_best_version_vdb_chroot(package)
230 if add_to_world: 272 if add_to_world:
231 for package in packages: 273 for package in packages:
232 self.add_pkg_to_world(package) 274 self.add_pkg_to_world(package)
233 275
234 276
235def usage(): 277def usage(progname):
236 print """ 278 print """
237Usage: GLIPortage.py [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help] 279Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help]
238 280
239Options: 281Options:
240 282
241 -c|--chroot-dir Specifies the directory where your chroot is. This is 283 -c|--chroot-dir Specifies the directory where your chroot is. This is
242 "/mnt/gentoo" by default. 284 "/mnt/gentoo" by default.
246 288
247 -s|--stage3 Create a stage3 equivelant in the chroot directory by using 289 -s|--stage3 Create a stage3 equivelant in the chroot directory by using
248 files from the LiveCD. 290 files from the LiveCD.
249 291
250 -h|--help Display this help 292 -h|--help Display this help
251""" 293""" % (progname)
252 294
253if __name__ == "__main__": 295if __name__ == "__main__":
254 chroot_dir = "/mnt/gentoo" 296 chroot_dir = "/mnt/gentoo"
255 mode = None 297 mode = None
256 grp_packages = [] 298 grp_packages = []
299 progname = sys.argv.pop(0)
257 while len(sys.argv): 300 while len(sys.argv):
258 arg = sys.argv.pop(0) 301 arg = sys.argv.pop(0)
259 if arg == "-c" or arg == "--chroot-dir": 302 if arg == "-c" or arg == "--chroot-dir":
260 chroot_dir = sys.argv.pop(0) 303 chroot_dir = sys.argv.pop(0)
261 elif arg == "-g" or arg == "--grp": 304 elif arg == "-g" or arg == "--grp":
262 mode = "grp" 305 mode = "grp"
263 elif arg == "-s" or arg == "--stage3": 306 elif arg == "-s" or arg == "--stage3":
264 mode = "stage3" 307 mode = "stage3"
265 elif arg == "-h" or arg == "--help": 308 elif arg == "-h" or arg == "--help":
266 usage() 309 usage(progname)
267 sys.exit(0) 310 sys.exit(0)
268 elif arg[0] == "-": 311 elif arg[0] == "-":
269 usage() 312 usage(progname)
270 sys.exit(1) 313 sys.exit(1)
271 else: 314 else:
272 grp_packages.append(arg) 315 grp_packages.append(arg)
273 316
274 gliportage = GLIPortage(chroot_dir, True, None, False, None, None) 317 gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
291 sys.exit(1) 334 sys.exit(1)
292 335
293 syspkglen = len(systempkgs) 336 syspkglen = len(systempkgs)
294 for i, pkg in enumerate(systempkgs): 337 for i, pkg in enumerate(systempkgs):
295 pkg = pkg.strip() 338 pkg = pkg.strip()
339 print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
296 gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True) 340 gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True)
297 GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf") 341 GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf")
298 GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile") 342 GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile")
299 GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab") 343 GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab")
300 344
329 print "Stage3 equivelant generation complete!" 373 print "Stage3 equivelant generation complete!"
330 elif mode == "grp": 374 elif mode == "grp":
331 for pkg in grp_packages: 375 for pkg in grp_packages:
332 if not gliportage.get_best_version_vdb(pkg): 376 if not gliportage.get_best_version_vdb(pkg):
333 print "Package " + pkg + " is not available for install from the LiveCD" 377 print "Package " + pkg + " is not available for install from the LiveCD"
378 continue
334 pkglist = gliportage.get_deps(pkg) 379 pkglist = gliportage.get_deps(pkg)
335 for tmppkg in pkglist: 380 for i, tmppkg in enumerate(pkglist):
381 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
336 gliportage.copy_pkg_to_chroot(tmppkg) 382 gliportage.copy_pkg_to_chroot(tmppkg)
337 gliportage.add_pkg_to_world(pkg) 383 gliportage.add_pkg_to_world(pkg)
338 print "GRP install complete!" 384 print "GRP install complete!"
339 else: 385 else:
340 print "You must specify an operating mode (-g or -s)!" 386 print "You must specify an operating mode (-g or -s)!"
341 usage() 387 usage(progname)
342 sys.exit(1) 388 sys.exit(1)

Legend:
Removed from v.1307  
changed lines
  Added in v.1339

  ViewVC Help
Powered by ViewVC 1.1.20