79
78
self.db.progress('INFO', 'ubiquity/install/blacklist')
80
79
self.generate_blacklist()
83
apt_pkg.Config.set("Dir", self.target)
84
apt_pkg.Config.set("Dir::State::status",
82
apt_pkg.config.set("Dir", self.target)
83
apt_pkg.config.set("Dir::State::status",
85
84
os.path.join(self.target, 'var/lib/dpkg/status'))
86
apt_pkg.Config.set("APT::GPGV::TrustedKeyring",
85
apt_pkg.config.set("APT::GPGV::TrustedKeyring",
87
86
os.path.join(self.target, 'etc/apt/trusted.gpg'))
88
apt_pkg.Config.set("Acquire::gpgv::Options::",
87
apt_pkg.config.set("Acquire::gpgv::Options::",
89
88
"--ignore-time-conflict")
90
apt_pkg.Config.set("DPkg::Options::", "--root=%s" % self.target)
89
apt_pkg.config.set("DPkg::Options::", "--root=%s" % self.target)
91
90
# We don't want apt-listchanges or dpkg-preconfigure, so just clear
92
91
# out the list of pre-installation hooks.
93
apt_pkg.Config.clear("DPkg::Pre-Install-Pkgs")
92
apt_pkg.config.clear("DPkg::Pre-Install-Pkgs")
97
96
"""Run the install stage: copy everything to the target system, then
339
337
self.db.progress('INFO', 'ubiquity/install/copying')
341
339
fs_size = os.path.join(self.casper_path, 'filesystem.size')
342
assert os.path.exists(fs_size), "Missing filesystem.size."
343
with open(fs_size) as total_size_fp:
344
total_size = int(total_size_fp.readline())
340
if os.path.exists(fs_size):
341
with open(fs_size) as total_size_fp:
342
total_size = int(total_size_fp.readline())
344
# Fallback in case an Ubuntu derivative forgets to put
345
# /casper/filesystem.size on the CD, or to account for things
346
# like CD->USB transformation tools that don't copy this file.
347
# This is slower than just reading the size from a file, but
348
# better than crashing.
350
# Obviously doing os.walk() twice is inefficient, but I'd rather
351
# not suck the list into ubiquity's memory, and I'm guessing
352
# that the kernel's dentry cache will avoid most of the slowness
355
for dirpath, dirnames, filenames in os.walk(self.source):
356
for name in dirnames + filenames:
357
fqpath = os.path.join(dirpath, name)
358
total_size += os.lstat(fqpath).st_size
346
360
# Progress bar handling:
347
361
# We sample progress every half-second (assuming time.time() gives
386
400
for name in dirnames + filenames:
387
401
relpath = os.path.join(sp, name)
388
402
# /etc/fstab was legitimately created by partman, and
389
# shouldn't be copied again.
390
if relpath == "etc/fstab":
403
# shouldn't be copied again. Similarly, /etc/crypttab may
404
# have been legitimately created by the user-setup plugin.
405
if relpath in ("etc/fstab", "etc/crypttab"):
392
407
sourcepath = os.path.join(self.source, relpath)
393
408
targetpath = os.path.join(self.target, relpath)
394
409
st = os.lstat(sourcepath)
411
# Is the path blacklisted?
412
if (not stat.S_ISDIR(st.st_mode) and
413
'/%s' % relpath in self.blacklist):
415
syslog.syslog('Not copying %s' % relpath)
418
# Remove the target if necessary and if we can.
419
install_misc.remove_target(
420
self.source, self.target, relpath, st)
422
# Now actually copy source to target.
395
423
mode = stat.S_IMODE(st.st_mode)
396
424
if stat.S_ISLNK(st.st_mode):
398
os.unlink(targetpath)
400
if e.errno == errno.ENOENT:
402
elif e.errno == errno.EISDIR:
406
425
linkto = os.readlink(sourcepath)
407
426
os.symlink(linkto, targetpath)
408
427
elif stat.S_ISDIR(st.st_mode):
409
428
if not os.path.isdir(targetpath):
410
os.mkdir(targetpath, mode)
430
os.mkdir(targetpath, mode)
432
# there is a small window where update-apt-cache
433
# can race with us since it creates
434
# "/target/var/cache/apt/...". Hence, ignore
435
# failure if the directory does now exist where
436
# brief moments before it didn't.
437
if e.errno != errno.EEXIST:
411
439
elif stat.S_ISCHR(st.st_mode):
412
440
os.mknod(targetpath, stat.S_IFCHR | mode, st.st_rdev)
413
441
elif stat.S_ISBLK(st.st_mode):
417
445
elif stat.S_ISSOCK(st.st_mode):
418
446
os.mknod(targetpath, stat.S_IFSOCK | mode)
419
447
elif stat.S_ISREG(st.st_mode):
420
if '/%s' % relpath in self.blacklist:
422
syslog.syslog('Not copying %s' % relpath)
424
osextras.unlink_force(targetpath)
425
448
install_misc.copy_file(self.db, sourcepath, targetpath, md5_check)
427
451
copied_size += st.st_size
428
452
os.lchown(targetpath, st.st_uid, st.st_gid)
429
453
if not stat.S_ISLNK(st.st_mode):
432
456
directory_times.append((targetpath, st.st_atime, st.st_mtime))
433
457
# os.utime() sets timestamp of target, not link
434
458
elif not stat.S_ISLNK(st.st_mode):
435
os.utime(targetpath, (st.st_atime, st.st_mtime))
460
os.utime(targetpath, (st.st_atime, st.st_mtime))
462
# We can live with timestamps being wrong.
437
465
if int((copied_size * 90) / total_size) != copy_progress:
438
466
copy_progress = int((copied_size * 90) / total_size)
462
490
(directory, atime, mtime) = dirtime
464
492
os.utime(directory, (atime, mtime))
466
494
# I have no idea why I've been getting lots of bug reports
467
495
# about this failing, but I really don't care. Ignore it.
488
516
os.lchown(target_kernel, 0, 0)
489
517
os.chmod(target_kernel, 0644)
490
518
st = os.lstat(kernel)
491
os.utime(target_kernel, (st.st_atime, st.st_mtime))
520
os.utime(target_kernel, (st.st_atime, st.st_mtime))
522
# We can live with timestamps being wrong.
493
525
os.umask(old_umask)