| 1 |
agaffney |
1181 |
""" |
| 2 |
|
|
# Copyright 1999-2005 Gentoo Foundation |
| 3 |
|
|
# This source code is distributed under the terms of version 2 of the GNU |
| 4 |
|
|
# General Public License as published by the Free Software Foundation, a copy |
| 5 |
|
|
# of which can be found in the main directory of this project. |
| 6 |
|
|
Gentoo Linux Installer |
| 7 |
|
|
|
| 8 |
agaffney |
1527 |
$Id: GLIPortage.py,v 1.57 2006/09/13 18:29:13 agaffney Exp $ |
| 9 |
agaffney |
1181 |
""" |
| 10 |
|
|
|
| 11 |
agaffney |
1182 |
import re |
| 12 |
agaffney |
1216 |
import os |
| 13 |
agaffney |
1306 |
import sys |
| 14 |
agaffney |
1181 |
import GLIUtility |
| 15 |
agaffney |
1204 |
from GLIException import GLIException |
| 16 |
agaffney |
1181 |
|
| 17 |
|
|
class GLIPortage(object): |
| 18 |
|
|
|
| 19 |
agaffney |
1205 |
def __init__(self, chroot_dir, grp_install, logger, debug, cc, compile_logfile): |
| 20 |
agaffney |
1182 |
self._chroot_dir = chroot_dir |
| 21 |
agaffney |
1189 |
self._grp_install = grp_install |
| 22 |
agaffney |
1182 |
self._logger = logger |
| 23 |
|
|
self._debug = debug |
| 24 |
agaffney |
1205 |
self._cc = cc |
| 25 |
|
|
self._compile_logfile = compile_logfile |
| 26 |
agaffney |
1181 |
|
| 27 |
agaffney |
1183 |
def get_deps(self, pkgs): |
| 28 |
agaffney |
1189 |
pkglist = [] |
| 29 |
|
|
if isinstance(pkgs, str): |
| 30 |
|
|
pkgs = pkgs.split() |
| 31 |
|
|
for pkg in pkgs: |
| 32 |
agaffney |
1305 |
if not pkg: continue |
| 33 |
agaffney |
1190 |
if self._debug: self._logger.log("get_deps(): pkg is " + pkg) |
| 34 |
agaffney |
1189 |
if not self._grp_install or not self.get_best_version_vdb(pkg): |
| 35 |
agaffney |
1190 |
if self._debug: self._logger.log("get_deps(): grabbing compile deps") |
| 36 |
agaffney |
1208 |
tmppkglist = GLIUtility.spawn("emerge -p " + pkg + r" 2>/dev/null | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].strip().split("\n") |
| 37 |
agaffney |
1189 |
else: |
| 38 |
agaffney |
1190 |
if self._debug: self._logger.log("get_deps(): grabbing binary deps") |
| 39 |
agaffney |
1210 |
# The runtimedeps.py script generates a package install order that is *very* different from emerge itself |
| 40 |
|
|
# tmppkglist = GLIUtility.spawn("python ../../runtimedeps.py " + self._chroot_dir + " " + pkg, return_output=True)[1].strip().split("\n") |
| 41 |
|
|
tmppkglist = [] |
| 42 |
agaffney |
1214 |
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"): |
| 43 |
agaffney |
1210 |
if self._debug: self._logger.log("get_deps(): looking at " + tmppkg) |
| 44 |
agaffney |
1211 |
if self.get_best_version_vdb("=" + tmppkg): |
| 45 |
agaffney |
1210 |
if self._debug: self._logger.log("get_deps(): package " + tmppkg + " in host vdb...adding to tmppkglist") |
| 46 |
|
|
tmppkglist.append(tmppkg) |
| 47 |
agaffney |
1190 |
if self._debug: self._logger.log("get_deps(): deplist for " + pkg + ": " + str(tmppkglist)) |
| 48 |
agaffney |
1189 |
for tmppkg in tmppkglist: |
| 49 |
agaffney |
1192 |
if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist") |
| 50 |
agaffney |
1194 |
if not tmppkg in pkglist and not self.get_best_version_vdb_chroot("=" + tmppkg): |
| 51 |
agaffney |
1192 |
if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist") |
| 52 |
agaffney |
1189 |
pkglist.append(tmppkg) |
| 53 |
agaffney |
1190 |
if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist)) |
| 54 |
agaffney |
1525 |
if not pkglist: |
| 55 |
|
|
raise GLIException("GetDepListError", 'fatal', 'get_deps', "Dep list is empty. This usually means there is no portage tree in the chroot") |
| 56 |
agaffney |
1189 |
return pkglist |
| 57 |
agaffney |
1182 |
|
| 58 |
agaffney |
1221 |
def parse_vdb_contents(self, file): |
| 59 |
|
|
entries = [] |
| 60 |
|
|
try: |
| 61 |
|
|
vdbfile = open(file, "r") |
| 62 |
|
|
except: |
| 63 |
|
|
return entries |
| 64 |
|
|
for line in vdbfile.readlines(): |
| 65 |
|
|
parts = line.strip().split(" ") |
| 66 |
|
|
if parts[0] == "obj": |
| 67 |
|
|
entries.append(parts[1]) |
| 68 |
agaffney |
1222 |
# elif parts[0] == "dir": |
| 69 |
|
|
# entries.append(parts[1] + "/") |
| 70 |
agaffney |
1221 |
elif parts[0] == "sym": |
| 71 |
|
|
entries.append(" ".join(parts[1:4])) |
| 72 |
|
|
entries.sort() |
| 73 |
|
|
return entries |
| 74 |
|
|
|
| 75 |
agaffney |
1280 |
def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False): |
| 76 |
agaffney |
1221 |
symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/', |
| 77 |
|
|
'/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/', |
| 78 |
|
|
'/etc/gconf': '/usr/livecd/gconf/' } |
| 79 |
agaffney |
1182 |
|
| 80 |
agaffney |
1469 |
tmpdir = "/var/tmp" |
| 81 |
|
|
image_dir = tmpdir + "/portage/" + package.split("/")[1] + "/image" |
| 82 |
agaffney |
1198 |
root_cmd = "" |
| 83 |
|
|
tmp_chroot_dir = self._chroot_dir |
| 84 |
agaffney |
1469 |
portage_tmpdir = "/var/tmp" |
| 85 |
agaffney |
1270 |
vdb_dir = "/var/db/pkg/" |
| 86 |
agaffney |
1198 |
if use_root: |
| 87 |
|
|
root_cmd = "ROOT=" + self._chroot_dir |
| 88 |
agaffney |
1203 |
tmp_chroot_dir = "" |
| 89 |
agaffney |
1469 |
portage_tmpdir = self._chroot_dir + "/var/tmp" |
| 90 |
agaffney |
1270 |
vdb_dir = self._chroot_dir + "/var/db/pkg/" |
| 91 |
agaffney |
1198 |
|
| 92 |
agaffney |
1339 |
# Create /tmp, /var/tmp, and /var/lib/portage with proper permissions |
| 93 |
|
|
oldumask = os.umask(0) |
| 94 |
|
|
if not os.path.exists(self._chroot_dir + "/tmp"): |
| 95 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /tmp doesn't exist in chroot...creating with proper permissions") |
| 96 |
|
|
try: |
| 97 |
|
|
os.mkdir(self._chroot_dir + "/tmp", 01777) |
| 98 |
|
|
except: |
| 99 |
|
|
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /tmp in chroot") |
| 100 |
|
|
if not os.path.exists(self._chroot_dir + "/var/tmp"): |
| 101 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/tmp doesn't exist in chroot...creating with proper permissions") |
| 102 |
|
|
try: |
| 103 |
|
|
os.mkdir(self._chroot_dir + "/var", 0755) |
| 104 |
|
|
except: |
| 105 |
|
|
pass |
| 106 |
|
|
try: |
| 107 |
|
|
os.mkdir(self._chroot_dir + "/var/tmp", 01777) |
| 108 |
|
|
except: |
| 109 |
|
|
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/tmp in chroot") |
| 110 |
|
|
if not os.path.exists(self._chroot_dir + "/var/lib/portage"): |
| 111 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/lib/portage doesn't exist in chroot...creating with proper permissions") |
| 112 |
|
|
try: |
| 113 |
|
|
os.mkdir(self._chroot_dir + "/var/lib", 0755) |
| 114 |
|
|
except: |
| 115 |
|
|
pass |
| 116 |
|
|
try: |
| 117 |
|
|
os.mkdir(self._chroot_dir + "/var/lib/portage", 02750) |
| 118 |
|
|
except: |
| 119 |
|
|
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/lib/portage in chroot") |
| 120 |
|
|
os.umask(oldumask) |
| 121 |
|
|
|
| 122 |
agaffney |
1280 |
# Check to see if package is actually in vdb |
| 123 |
|
|
if not GLIUtility.is_file("/var/db/pkg/" + package): |
| 124 |
|
|
if ignore_missing: |
| 125 |
|
|
if self._debug: |
| 126 |
|
|
self._logger.log("DEBUG: copy_pkg_to_chroot(): package " + package + " does not have a vdb entry but ignore_missing=True...ignoring error") |
| 127 |
|
|
return |
| 128 |
|
|
else: |
| 129 |
|
|
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package) |
| 130 |
|
|
|
| 131 |
agaffney |
1182 |
# Copy the vdb entry for the package from the LiveCD to the chroot |
| 132 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package) |
| 133 |
agaffney |
1314 |
if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + "/var/db/pkg/" + package + " && cp -a /var/db/pkg/" + package + "/* " + self._chroot_dir + "/var/db/pkg/" + package, logfile=self._compile_logfile, append_log=True)): |
| 134 |
agaffney |
1182 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package) |
| 135 |
|
|
|
| 136 |
agaffney |
1208 |
# Create the image dir in the chroot |
| 137 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'") |
| 138 |
agaffney |
1314 |
if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)): |
| 139 |
agaffney |
1208 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package) |
| 140 |
|
|
|
| 141 |
agaffney |
1182 |
# Create list of files for tar to work with from CONTENTS file in vdb entry |
| 142 |
agaffney |
1221 |
entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS") |
| 143 |
agaffney |
1208 |
if not entries: |
| 144 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup") |
| 145 |
|
|
else: |
| 146 |
agaffney |
1342 |
# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries)) |
| 147 |
agaffney |
1208 |
try: |
| 148 |
|
|
tarfiles = open("/tmp/tarfilelist", "w") |
| 149 |
|
|
for entry in entries: |
| 150 |
|
|
parts = entry.split(" ") |
| 151 |
agaffney |
1222 |
# # Hack for symlink crappiness |
| 152 |
agaffney |
1221 |
# for symlink in symlinks: |
| 153 |
|
|
# if parts[0].startswith(symlink): |
| 154 |
|
|
# parts[0] = symlinks[symlink] + parts[0][len(symlink):] |
| 155 |
agaffney |
1208 |
tarfiles.write(parts[0] + "\n") |
| 156 |
|
|
tarfiles.close() |
| 157 |
|
|
except: |
| 158 |
|
|
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package) |
| 159 |
agaffney |
1182 |
|
| 160 |
agaffney |
1208 |
# Use tar to transfer files into IMAGE directory |
| 161 |
agaffney |
1222 |
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp'") |
| 162 |
agaffney |
1314 |
if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp", logfile=self._compile_logfile, append_log=True)): |
| 163 |
agaffney |
1208 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package) |
| 164 |
agaffney |
1182 |
|
| 165 |
agaffney |
1338 |
# Fix mode, uid, and gid of directories |
| 166 |
agaffney |
1469 |
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running find " + self._chroot_dir + image_dir + " -mindepth 1 -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'") |
| 167 |
|
|
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") |
| 168 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): found the following directories: " + str(dirlist)) |
| 169 |
|
|
if not dirlist or dirlist[0] == "": |
| 170 |
|
|
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!") |
| 171 |
|
|
for dir in dirlist: |
| 172 |
|
|
dirstat = os.stat(dir) |
| 173 |
|
|
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) |
| 174 |
|
|
os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5]) |
| 175 |
|
|
os.chmod(self._chroot_dir + image_dir + dir, dirstat[0]) |
| 176 |
agaffney |
1338 |
|
| 177 |
agaffney |
1221 |
# # More symlink crappiness hacks |
| 178 |
|
|
# for symlink in symlinks: |
| 179 |
|
|
## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]): |
| 180 |
|
|
# if os.path.islink(self._chroot_dir + image_dir + symlink): |
| 181 |
|
|
# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): fixing " + symlink + " symlink ickiness stuff in " + image_dir + " for " + package) |
| 182 |
|
|
# GLIUtility.spawn("rm " + self._chroot_dir + image_dir + symlink) |
| 183 |
|
|
# if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)): |
| 184 |
|
|
# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package) |
| 185 |
agaffney |
1182 |
|
| 186 |
|
|
# Run pkg_setup |
| 187 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package) |
| 188 |
agaffney |
1474 |
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)): |
| 189 |
agaffney |
1182 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package) |
| 190 |
|
|
|
| 191 |
|
|
# Run pkg_preinst |
| 192 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package) |
| 193 |
agaffney |
1474 |
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)): |
| 194 |
agaffney |
1182 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package) |
| 195 |
|
|
|
| 196 |
|
|
# Copy files from image_dir to chroot |
| 197 |
agaffney |
1208 |
if not entries: |
| 198 |
agaffney |
1209 |
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /") |
| 199 |
agaffney |
1208 |
else: |
| 200 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package) |
| 201 |
agaffney |
1291 |
# if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)): |
| 202 |
agaffney |
1338 |
if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -C " + self._chroot_dir + image_dir + "/ -cp . | tar -C " + self._chroot_dir + "/ -xp", logfile=self._compile_logfile, append_log=True)): |
| 203 |
agaffney |
1208 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package) |
| 204 |
agaffney |
1182 |
|
| 205 |
|
|
# Run pkg_postinst |
| 206 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package) |
| 207 |
agaffney |
1474 |
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)): |
| 208 |
agaffney |
1182 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package) |
| 209 |
|
|
|
| 210 |
|
|
# Remove image_dir |
| 211 |
agaffney |
1208 |
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package) |
| 212 |
agaffney |
1314 |
if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)): |
| 213 |
agaffney |
1182 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package) |
| 214 |
|
|
|
| 215 |
agaffney |
1297 |
# Run env-update |
| 216 |
|
|
if not use_root: |
| 217 |
|
|
if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot") |
| 218 |
agaffney |
1314 |
if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)): |
| 219 |
agaffney |
1297 |
raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package) |
| 220 |
|
|
|
| 221 |
agaffney |
1182 |
def add_pkg_to_world(self, package): |
| 222 |
|
|
if package.find("/") == -1: |
| 223 |
agaffney |
1195 |
package = self.get_best_version_vdb_chroot(package) |
| 224 |
agaffney |
1182 |
if not package: return False |
| 225 |
agaffney |
1205 |
expr = re.compile('^=?(.+?/.+?)(-\d.+)?$') |
| 226 |
agaffney |
1182 |
res = expr.match(package) |
| 227 |
|
|
if res: |
| 228 |
|
|
GLIUtility.spawn("echo " + res.group(1) + " >> " + self._chroot_dir + "/var/lib/portage/world") |
| 229 |
|
|
|
| 230 |
agaffney |
1185 |
def get_best_version_vdb(self, package): |
| 231 |
agaffney |
1285 |
if package.startswith('='): |
| 232 |
|
|
package = package[1:] |
| 233 |
|
|
if GLIUtility.is_file("/var/db/pkg/" + package): |
| 234 |
|
|
return package |
| 235 |
agaffney |
1286 |
else: |
| 236 |
|
|
return "" |
| 237 |
agaffney |
1285 |
else: |
| 238 |
|
|
return GLIUtility.spawn("portageq best_version / " + package, return_output=True)[1].strip() |
| 239 |
agaffney |
1189 |
|
| 240 |
agaffney |
1194 |
def get_best_version_vdb_chroot(self, package): |
| 241 |
agaffney |
1287 |
if package.startswith('='): |
| 242 |
|
|
package = package[1:] |
| 243 |
|
|
if GLIUtility.is_file(self._chroot_dir + "/var/db/pkg/" + package): |
| 244 |
|
|
return package |
| 245 |
|
|
else: |
| 246 |
|
|
return "" |
| 247 |
|
|
else: |
| 248 |
|
|
return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip() |
| 249 |
agaffney |
1194 |
|
| 250 |
agaffney |
1184 |
# def get_best_version_tree(self, package): |
| 251 |
|
|
# return portage.best(tree.match(package)) |
| 252 |
agaffney |
1205 |
|
| 253 |
|
|
def emerge(self, packages, add_to_world=True): |
| 254 |
|
|
if isinstance(packages, str): |
| 255 |
|
|
packages = packages.split() |
| 256 |
agaffney |
1223 |
self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages))) |
| 257 |
agaffney |
1205 |
pkglist = self.get_deps(packages) |
| 258 |
|
|
if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist)) |
| 259 |
|
|
for i, pkg in enumerate(pkglist): |
| 260 |
agaffney |
1305 |
if not pkg: continue |
| 261 |
agaffney |
1205 |
if self._debug: self._logger.log("install_packages(): processing package " + pkg) |
| 262 |
agaffney |
1208 |
self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")")) |
| 263 |
|
|
if not self._grp_install or not self.get_best_version_vdb("=" + pkg): |
| 264 |
agaffney |
1205 |
status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True) |
| 265 |
|
|
# status = self._emerge("=" + pkg) |
| 266 |
|
|
if not GLIUtility.exitsuccess(status): |
| 267 |
|
|
raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") |
| 268 |
|
|
else: |
| 269 |
|
|
# try: |
| 270 |
|
|
self.copy_pkg_to_chroot(pkg) |
| 271 |
|
|
# except: |
| 272 |
|
|
# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") |
| 273 |
agaffney |
1208 |
self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")")) |
| 274 |
agaffney |
1205 |
if add_to_world: |
| 275 |
|
|
for package in packages: |
| 276 |
|
|
self.add_pkg_to_world(package) |
| 277 |
agaffney |
1306 |
|
| 278 |
|
|
|
| 279 |
agaffney |
1311 |
def usage(progname): |
| 280 |
agaffney |
1306 |
print """ |
| 281 |
agaffney |
1311 |
Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help] |
| 282 |
agaffney |
1306 |
|
| 283 |
|
|
Options: |
| 284 |
|
|
|
| 285 |
|
|
-c|--chroot-dir Specifies the directory where your chroot is. This is |
| 286 |
|
|
"/mnt/gentoo" by default. |
| 287 |
|
|
|
| 288 |
|
|
-g|--grp Install specified packages and dependencies into chroot |
| 289 |
|
|
by using files from the LiveCD. |
| 290 |
|
|
|
| 291 |
|
|
-s|--stage3 Create a stage3 equivelant in the chroot directory by using |
| 292 |
|
|
files from the LiveCD. |
| 293 |
|
|
|
| 294 |
agaffney |
1527 |
-k|--kernel Install kernel and modules from LiveCD into the chroot |
| 295 |
|
|
|
| 296 |
agaffney |
1306 |
-h|--help Display this help |
| 297 |
agaffney |
1311 |
""" % (progname) |
| 298 |
agaffney |
1306 |
|
| 299 |
|
|
if __name__ == "__main__": |
| 300 |
|
|
chroot_dir = "/mnt/gentoo" |
| 301 |
|
|
mode = None |
| 302 |
|
|
grp_packages = [] |
| 303 |
agaffney |
1311 |
progname = sys.argv.pop(0) |
| 304 |
agaffney |
1307 |
while len(sys.argv): |
| 305 |
agaffney |
1306 |
arg = sys.argv.pop(0) |
| 306 |
|
|
if arg == "-c" or arg == "--chroot-dir": |
| 307 |
|
|
chroot_dir = sys.argv.pop(0) |
| 308 |
|
|
elif arg == "-g" or arg == "--grp": |
| 309 |
|
|
mode = "grp" |
| 310 |
|
|
elif arg == "-s" or arg == "--stage3": |
| 311 |
|
|
mode = "stage3" |
| 312 |
agaffney |
1526 |
elif arg == "-k" or arg == "--kernel": |
| 313 |
|
|
mode = "kernel" |
| 314 |
agaffney |
1306 |
elif arg == "-h" or arg == "--help": |
| 315 |
agaffney |
1311 |
usage(progname) |
| 316 |
agaffney |
1306 |
sys.exit(0) |
| 317 |
|
|
elif arg[0] == "-": |
| 318 |
agaffney |
1311 |
usage(progname) |
| 319 |
agaffney |
1306 |
sys.exit(1) |
| 320 |
|
|
else: |
| 321 |
|
|
grp_packages.append(arg) |
| 322 |
|
|
|
| 323 |
|
|
gliportage = GLIPortage(chroot_dir, True, None, False, None, None) |
| 324 |
|
|
if mode == "stage3": |
| 325 |
|
|
if not GLIUtility.is_file("/usr/livecd/systempkgs.txt"): |
| 326 |
|
|
print "Required file /usr/livecd/systempkgs.txt does not exist!" |
| 327 |
|
|
sys.exit(1) |
| 328 |
|
|
try: |
| 329 |
|
|
syspkgs = open("/usr/livecd/systempkgs.txt", "r") |
| 330 |
|
|
systempkgs = syspkgs.readlines() |
| 331 |
|
|
syspkgs.close() |
| 332 |
|
|
except: |
| 333 |
|
|
print "Could not open /usr/livecd/systempkgs.txt!" |
| 334 |
|
|
sys.exit(1) |
| 335 |
|
|
|
| 336 |
|
|
# Pre-create /lib (and possible /lib32 and /lib64) |
| 337 |
|
|
if os.path.islink("/lib") and os.readlink("/lib") == "lib64": |
| 338 |
|
|
if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")): |
| 339 |
|
|
print "Could not precreate /lib64 dir and /lib -> /lib64 symlink" |
| 340 |
|
|
sys.exit(1) |
| 341 |
|
|
|
| 342 |
|
|
syspkglen = len(systempkgs) |
| 343 |
|
|
for i, pkg in enumerate(systempkgs): |
| 344 |
|
|
pkg = pkg.strip() |
| 345 |
agaffney |
1310 |
print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")" |
| 346 |
agaffney |
1306 |
gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True) |
| 347 |
|
|
GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf") |
| 348 |
|
|
GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile") |
| 349 |
|
|
GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab") |
| 350 |
|
|
|
| 351 |
|
|
# Nasty, nasty, nasty hack because vapier is a tool |
| 352 |
|
|
for tmpfile in ("/etc/passwd", "/etc/group", "/etc/shadow"): |
| 353 |
|
|
GLIUtility.spawn("grep -ve '^gentoo' " + tmpfile + " > " + chroot_dir + tmpfile) |
| 354 |
|
|
|
| 355 |
|
|
chrootscript = r""" |
| 356 |
|
|
#!/bin/bash |
| 357 |
|
|
|
| 358 |
|
|
source /etc/make.conf |
| 359 |
|
|
export LDPATH="/usr/lib/gcc-lib/${CHOST}/$(cd /usr/lib/gcc-lib/${CHOST} && ls -1 | head -n 1)" |
| 360 |
|
|
|
| 361 |
|
|
ldconfig $LDPATH |
| 362 |
|
|
gcc-config 1 |
| 363 |
|
|
env-update |
| 364 |
|
|
source /etc/profile |
| 365 |
|
|
modules-update |
| 366 |
|
|
[ -f /usr/bin/binutils-config ] && binutils-config 1 |
| 367 |
|
|
source /etc/profile |
| 368 |
|
|
#mount -t proc none /proc |
| 369 |
|
|
#cd /dev |
| 370 |
|
|
#/sbin/MAKEDEV generic-i386 |
| 371 |
|
|
#umount /proc |
| 372 |
|
|
[ -f /lib/udev-state/devices.tar.bz2 ] && tar -C /dev -xjf /lib/udev-state/devices.tar.bz2 |
| 373 |
|
|
""" |
| 374 |
|
|
script = open(chroot_dir + "/tmp/extrastuff.sh", "w") |
| 375 |
|
|
script.write(chrootscript) |
| 376 |
|
|
script.close() |
| 377 |
|
|
GLIUtility.spawn("chmod 755 /tmp/extrastuff.sh && /tmp/extrastuff.sh", chroot=chroot_dir) |
| 378 |
|
|
GLIUtility.spawn("rm -rf /var/tmp/portage/* /usr/portage /tmp/*", chroot=chroot_dir) |
| 379 |
|
|
print "Stage3 equivelant generation complete!" |
| 380 |
|
|
elif mode == "grp": |
| 381 |
|
|
for pkg in grp_packages: |
| 382 |
|
|
if not gliportage.get_best_version_vdb(pkg): |
| 383 |
|
|
print "Package " + pkg + " is not available for install from the LiveCD" |
| 384 |
agaffney |
1311 |
continue |
| 385 |
agaffney |
1306 |
pkglist = gliportage.get_deps(pkg) |
| 386 |
agaffney |
1311 |
for i, tmppkg in enumerate(pkglist): |
| 387 |
|
|
print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")" |
| 388 |
agaffney |
1306 |
gliportage.copy_pkg_to_chroot(tmppkg) |
| 389 |
|
|
gliportage.add_pkg_to_world(pkg) |
| 390 |
|
|
print "GRP install complete!" |
| 391 |
agaffney |
1526 |
elif mode == "kernel": |
| 392 |
|
|
kernelpkg = gliportage.get_best_version_vdb("sys-kernel/livecd-kernel") |
| 393 |
|
|
gliportage.copy_pkg_to_chroot(kernelpkg) |
| 394 |
|
|
print "LiveCD kernel installed!" |
| 395 |
agaffney |
1306 |
else: |
| 396 |
|
|
print "You must specify an operating mode (-g or -s)!" |
| 397 |
agaffney |
1311 |
usage(progname) |
| 398 |
agaffney |
1306 |
sys.exit(1) |