1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from VMBuilder import register_distro_plugin, Plugin, VMBuilderUserError
20
21 import logging
22 import os
23
25 """
26 Plugin to provide --firstboot and --firstlogin scripts capabilities
27 """
28 name = 'First-Scripts plugin'
29
31 group = self.context.setting_group('Scripts')
32 group.add_option('--firstboot', metavar='PATH', default='', help='Specify a script that will be copied into the guest and executed the first time the machine boots. This script must not be interactive.')
33 group.add_option('--firstlogin', metavar='PATH', default='', help='Specify a script that will be copied into the guest and will be executed the first time the user logs in. This script can be interactive.')
34 self.context.register_setting_group(group)
35
37
38 if self.context.firstboot:
39 logging.debug("Checking if firstboot script %s exists" % (self.context.firstboot,))
40 if not(os.path.isfile(self.context.firstboot)):
41 raise VMBuilderUserError('The path to the first-boot script is invalid: %s. Make sure you are providing a full path.' % self.context.firstboot)
42
43 if self.context.firstlogin:
44 logging.debug("Checking if first login script %s exists" % (self.context.firstlogin,))
45 if not(os.path.isfile(self.context.firstlogin)):
46 raise VMBuilderUserError('The path to the first-login script is invalid: %s. Make sure you are providing a full path.' % self.context.firstlogin)
47
48 - def post_install(self):
49 logging.debug("Installing firstboot script %s" % (self.context.firstboot,))
50 if self.context.firstboot:
51 self.context.install_file('/root/firstboot.sh', source=self.vm.firstboot, mode=0700)
52 os.rename('%s/etc/rc.local' % self.context.installdir, '%s/etc/rc.local.orig' % self.vm.installdir)
53 self.install_from_template('/etc/rc.local', 'firstbootrc', mode=0755)
54
55 logging.debug("Installing first login script %s" % (self.context.firstlogin,))
56 if self.context.firstlogin:
57 self.context.install_file('/root/firstlogin.sh', source=self.vm.firstlogin, mode=0755)
58 os.rename('%s/etc/bash.bashrc' % self.context.installdir, '%s/etc/bash.bashrc.orig' % self.vm.installdir)
59 self.install_from_template('/etc/bash.bashrc', 'firstloginrc')
60
61 return True
62
63
64