50
50
from ubiquity.components import apt_setup, hw_detect, check_kernels
53
INTERFACES_TEXT = """\
54
# This file describes the network interfaces available on your system
55
# and how to activate them. For more information, see interfaces(5).
57
# The loopback network interface
59
iface lo inet loopback"""
64
# The following lines are desirable for IPv6 capable hosts
65
::1 ip6-localhost ip6-loopback
67
ff00::0 ip6-mcastprefix
69
ff02::2 ip6-allrouters"""
73
# This file assigns persistent names to network interfaces.
74
# See iftab(5) for syntax.
53
78
def cleanup_after(func):
414
440
# Make sure there's at least something here so that ifupdown
415
441
# doesn't get upset at boot.
416
442
with open('/etc/network/interfaces', 'w') as interfaces:
417
print(textwrap.dedent("""\
418
# This file describes the network interfaces available on your system
419
# and how to activate them. For more information, see interfaces(5).
421
# The loopback network interface
423
iface lo inet loopback"""), file=interfaces)
443
print(INTERFACES_TEXT, file=interfaces)
426
446
hostname = self.db.get('netcfg/get_hostname')
442
462
print("127.0.1.1\t%s" % hostname, file=hosts)
443
print(textwrap.dedent("""\
445
# The following lines are desirable for IPv6 capable hosts
446
::1 ip6-localhost ip6-loopback
448
ff00::0 ip6-mcastprefix
450
ff02::2 ip6-allrouters"""), file=hosts)
463
print(HOSTS_TEXT, file=hosts)
452
465
# Network Manager's ifupdown plugin has an inotify watch on
453
466
# /etc/hostname, which can trigger a race condition if /etc/hostname is
540
550
inst = plugin.Install(None, db=self.db)
541
551
ret = inst.install(self.target, Progress(self.db))
543
raise install_misc.InstallStepError("Plugin %s failed with code %s" % (plugin.NAME, ret))
553
raise install_misc.InstallStepError(
554
"Plugin %s failed with code %s" % (plugin.NAME, ret))
545
556
def configure_apt(self):
546
557
"""Configure /etc/apt/sources.list."""
548
558
if 'UBIQUITY_OEM_USER_CONFIG' in os.environ:
549
return # apt will already be setup as the OEM wants
559
return # apt will already be setup as the OEM wants
551
561
# TODO cjwatson 2007-07-06: Much of the following is
552
562
# cloned-and-hacked from base-installer/debian/postinst. Perhaps we
626
636
dbfilter = apt_setup.AptSetup(None, self.db)
627
637
ret = dbfilter.run_command(auto_process=True)
629
raise install_misc.InstallStepError("AptSetup failed with code %d" % ret)
639
raise install_misc.InstallStepError(
640
"AptSetup failed with code %d" % ret)
631
642
def run_target_config_hooks(self):
632
"""Run hook scripts from /usr/lib/ubiquity/target-config. This allows
633
casper to hook into us and repeat bits of its configuration in the
643
"""Run hook scripts from /usr/lib/ubiquity/target-config.
645
This allows casper to hook into us and repeat bits of its
646
configuration in the target system.
636
648
if 'UBIQUITY_OEM_USER_CONFIG' in os.environ:
637
return # These were already run once during install
649
return # These were already run once during install
639
651
hookdir = '/usr/lib/ubiquity/target-config'
817
828
return biggest_partition
819
830
def configure_hardware(self):
820
"""reconfiguring several packages which depends on the
821
hardware system in which has been installed on and need some
822
automatic configurations to get work."""
831
"""Reconfigure several hardware-specific packages.
833
These packages depend on the hardware of the system where the live
834
filesystem was built, and must be reconfigured to work properly on
835
the installed system.
824
837
self.nested_progress_start()
825
838
install_misc.chroot_setup(self.target)
827
840
dbfilter = hw_detect.HwDetect(None, self.db)
828
841
ret = dbfilter.run_command(auto_process=True)
830
raise install_misc.InstallStepError("HwDetect failed with code %d" % ret)
843
raise install_misc.InstallStepError(
844
"HwDetect failed with code %d" % ret)
832
846
install_misc.chroot_cleanup(self.target)
833
847
self.nested_progress_end()
867
881
osextras.unlink_force(self.target_file('etc/popularity-contest.conf'))
869
883
participate = self.db.get('popularity-contest/participate')
870
install_misc.set_debconf(self.target, 'popularity-contest/participate', participate, self.db)
884
install_misc.set_debconf(
885
self.target, 'popularity-contest/participate', participate,
871
887
except debconf.DebconfError:
874
890
osextras.unlink_force(self.target_file('etc/papersize'))
875
891
subprocess.call(['log-output', '-t', 'ubiquity', 'chroot', self.target,
876
892
'ucf', '--purge', '/etc/papersize'],
877
preexec_fn=install_misc.debconf_disconnect, close_fds=True)
893
preexec_fn=install_misc.debconf_disconnect,
879
install_misc.set_debconf(self.target, 'libpaper/defaultpaper', '', self.db)
896
install_misc.set_debconf(
897
self.target, 'libpaper/defaultpaper', '', self.db)
880
898
except debconf.DebconfError:
886
904
self.target_file('etc/ssl/private/ssl-cert-snakeoil.key'))
888
906
install_misc.chroot_setup(self.target, x11=True)
889
install_misc.chrex(self.target,'dpkg-divert', '--package', 'ubiquity', '--rename',
890
'--quiet', '--add', '/usr/sbin/update-initramfs')
908
self.target, 'dpkg-divert', '--package', 'ubiquity', '--rename',
909
'--quiet', '--add', '/usr/sbin/update-initramfs')
893
912
'/bin/true', self.target_file('usr/sbin/update-initramfs'))
908
927
osextras.unlink_force(
909
928
self.target_file('usr/sbin/update-initramfs'))
910
install_misc.chrex(self.target,'dpkg-divert', '--package', 'ubiquity', '--rename',
911
'--quiet', '--remove', '/usr/sbin/update-initramfs')
912
install_misc.chrex(self.target,'update-initramfs', '-c', '-k', self.kernel_version)
930
self.target, 'dpkg-divert', '--package', 'ubiquity',
931
'--rename', '--quiet', '--remove',
932
'/usr/sbin/update-initramfs')
934
self.target, 'update-initramfs', '-c',
935
'-k', self.kernel_version)
913
936
install_misc.chroot_cleanup(self.target, x11=True)
915
938
# Fix up kernel symlinks now that the initrd exists. Depending on
957
980
os.symlink(linksrc, linkdst)
959
982
def configure_bootloader(self):
960
"""configuring and installing boot loader into installed
983
"""Configure and install the boot loader."""
963
984
if 'UBIQUITY_OEM_USER_CONFIG' in os.environ:
964
985
#the language might be different than initial install.
965
986
#recopy translations if we have them now
966
987
full_lang = self.db.get('debian-installer/locale').split('.')[0]
967
988
for lang in [full_lang.split('.')[0], full_lang.split('_')[0]]:
968
source = '/usr/share/locale-langpack/%s/LC_MESSAGES/grub.mo' % lang
969
if os.path.exists(source) and os.path.isdir('/boot/grub/locale'):
990
'/usr/share/locale-langpack/%s/LC_MESSAGES/grub.mo' % lang)
991
if (os.path.exists(source) and
992
os.path.isdir('/boot/grub/locale')):
970
993
shutil.copy(source, '/boot/grub/locale/%s.mo' % lang)
1028
1051
raise install_misc.InstallStepError(
1029
1052
"YabootInstaller failed with code %d" % ret)
1031
raise install_misc.InstallStepError("No bootloader installer found")
1054
raise install_misc.InstallStepError(
1055
"No bootloader installer found")
1032
1056
except ImportError:
1033
raise install_misc.InstallStepError("No bootloader installer found")
1057
raise install_misc.InstallStepError(
1058
"No bootloader installer found")
1035
1060
misc.execute('umount', '-f', self.target + '/proc')
1036
1061
misc.execute('umount', '-f', self.target + '/sys')
1228
1250
with open(self.target_file('home/oem/.hwdb'), 'w'):
1253
apps_dir = 'usr/share/applications'
1231
1254
for desktop_file in (
1232
'usr/share/applications/oem-config-prepare-gtk.desktop',
1233
'usr/share/applications/kde4/oem-config-prepare-kde.desktop'):
1255
apps_dir + '/oem-config-prepare-gtk.desktop',
1256
apps_dir + '/kde4/oem-config-prepare-kde.desktop'):
1234
1257
if os.path.exists(self.target_file(desktop_file)):
1235
1258
desktop_base = os.path.basename(desktop_file)
1236
install_misc.chrex(self.target,'install', '-d',
1237
'-o', 'oem', '-g', 'oem',
1238
'/home/oem/Desktop')
1239
install_misc.chrex(self.target,'install', '-o', 'oem', '-g', 'oem',
1240
'/%s' % desktop_file,
1241
'/home/oem/Desktop/%s' % desktop_base)
1260
self.target, 'install', '-d',
1261
'-o', 'oem', '-g', 'oem',
1262
'/home/oem/Desktop')
1264
self.target, 'install',
1265
'-o', 'oem', '-g', 'oem',
1266
'/%s' % desktop_file,
1267
'/home/oem/Desktop/%s' % desktop_base)
1244
1270
# Carry the locale setting over to the installed system.
1245
1271
# This mimics the behavior in 01oem-config-udeb.
1246
1272
di_locale = self.db.get('debian-installer/locale')
1248
install_misc.set_debconf(self.target, 'debian-installer/locale', di_locale, self.db)
1249
#in an automated install, this key needs to carry over
1250
installable_lang = self.db.get('ubiquity/only-show-installable-languages')
1274
install_misc.set_debconf(
1275
self.target, 'debian-installer/locale', di_locale,
1277
# in an automated install, this key needs to carry over
1278
installable_lang = self.db.get(
1279
'ubiquity/only-show-installable-languages')
1251
1280
if installable_lang:
1252
1281
install_misc.set_debconf(self.target,
1253
1282
'ubiquity/only-show-installable-languages',
1258
1287
def remove_oem_extras(self):
1259
'''Try to remove packages that were not part of the base install and
1288
"""Remove unnecessary packages in OEM mode.
1290
Try to remove packages that were not part of the base install and
1260
1291
are not needed by the final system.
1262
This is roughly the set of packages installed by ubiquity + packages we
1263
explicitly installed in oem-config (langpacks, for example) -
1293
This is roughly the set of packages installed by ubiquity + packages
1294
we explicitly installed in oem-config (langpacks, for example) -
1266
1297
manifest = '/var/lib/ubiquity/installed-packages'
1267
1298
if not os.path.exists(manifest):
1271
1302
with open(manifest) as manifest_file:
1272
1303
for line in manifest_file:
1279
1310
cache = Cache()
1280
1311
# TODO cjwatson 2012-05-04: It would be nice to use a set
1281
1312
# comprehension here, but that causes:
1282
# SyntaxError: can not delete variable 'cache' referenced in nested scope
1313
# SyntaxError: can not delete variable 'cache' referenced in nested
1283
1315
remove = set([pkg for pkg in cache.keys() if cache[pkg].is_installed])
1284
1316
# Keep packages we explicitly installed.
1285
1317
keep |= install_misc.query_recorded_installed()
1286
1318
remove -= install_misc.expand_dependencies_simple(cache, keep, remove)
1289
1321
install_misc.record_removed(remove)
1290
1322
(regular, recursive) = install_misc.query_recorded_removed()
1291
1323
self.do_remove(regular)
1328
1360
elif stat.S_ISSOCK(st.st_mode):
1329
1361
os.mknod(targetpath, stat.S_IFSOCK | mode)
1330
1362
elif stat.S_ISREG(st.st_mode):
1331
install_misc.copy_file(self.db, sourcepath, targetpath, True)
1363
install_misc.copy_file(
1364
self.db, sourcepath, targetpath, True)
1333
1366
os.lchown(targetpath, uid, gid)
1334
1367
if not stat.S_ISLNK(st.st_mode):
1335
1368
os.chmod(targetpath, mode)
1336
1369
if stat.S_ISDIR(st.st_mode):
1337
directory_times.append((targetpath, st.st_atime, st.st_mtime))
1370
directory_times.append(
1371
(targetpath, st.st_atime, st.st_mtime))
1338
1372
# os.utime() sets timestamp of target, not link
1339
1373
elif not stat.S_ISLNK(st.st_mode):
1527
1565
shutil.copytree(source_bluetooth, target_bluetooth)
1529
1567
def recache_apparmor(self):
1530
"""Generate an apparmor cache in /etc/apparmor.d/cache to speed up boot
1568
"""Generate an apparmor cache to speed up boot time."""
1533
1569
if 'UBIQUITY_OEM_USER_CONFIG' in os.environ:
1535
1571
if not os.path.exists(self.target_file('etc/init.d/apparmor')):
1536
syslog.syslog('Apparmor is not installed, so not generating cache.')
1573
'Apparmor is not installed, so not generating cache.')
1538
install_misc.chrex(self.target,'mount', '-t', 'proc', 'proc', '/proc')
1539
install_misc.chrex(self.target,'mount', '-t', 'sysfs', 'sysfs', '/sys')
1540
install_misc.chrex(self.target,'mount', '-t', 'securityfs',
1541
'securityfs', '/sys/kernel/security')
1542
install_misc.chrex(self.target,'/etc/init.d/apparmor', 'recache')
1543
install_misc.chrex(self.target,'umount', '/proc')
1544
install_misc.chrex(self.target,'umount', '/sys/kernel/security')
1545
install_misc.chrex(self.target,'umount', '/sys')
1575
install_misc.chrex(self.target, 'mount', '-t', 'proc', 'proc', '/proc')
1577
self.target, 'mount', '-t', 'sysfs', 'sysfs', '/sys')
1579
self.target, 'mount', '-t', 'securityfs',
1580
'securityfs', '/sys/kernel/security')
1581
install_misc.chrex(self.target, '/etc/init.d/apparmor', 'recache')
1582
install_misc.chrex(self.target, 'umount', '/proc')
1583
install_misc.chrex(self.target, 'umount', '/sys/kernel/security')
1584
install_misc.chrex(self.target, 'umount', '/sys')
1547
1586
def copy_wallpaper_cache(self):
1548
"""Copy wallpaper cache for libgnome desktop so that it's taken into
1549
account by ureadahead. Only install on system having g-s-d."""
1587
"""Copy GNOME wallpaper cache for the benefit of ureadahead.
1589
Only do this on systems with gnome-settings-daemon.
1551
1591
if 'UBIQUITY_OEM_USER_CONFIG' in os.environ:
1554
# we don't use copy_network_config casper user trick as it's not and not
1555
# ubuntu in install mode
1594
# We don't use the copy_network_config casper user trick as it's not
1595
# ubuntu in install mode.
1557
1597
casper_user = pwd.getpwuid(999).pw_name
1558
1598
except KeyError:
1594
1634
os.chmod(target_user_wallpaper_cache_dir, 0o700)
1596
1636
def copy_dcd(self):
1597
"""Copy the Distribution Channel Descriptor (DCD) file into the
1598
installed system."""
1637
"""Install the Distribution Channel Descriptor (DCD) file."""
1600
1638
dcd = '/cdrom/.disk/ubuntu_dist_channel'
1601
1639
if os.path.exists(dcd):
1602
1640
shutil.copy(dcd, self.target_file('var/lib/ubuntu_dist_channel'))
1604
1642
def copy_logs(self):
1605
"""copy log files into installed system."""
1643
"""Copy log files to the installed system."""
1607
1644
if 'UBIQUITY_OEM_USER_CONFIG' in os.environ: