2013-08-10 16:51:42 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
2013-12-01 14:34:38 +01:00
|
|
|
from common.exceptions import TaskError
|
2013-10-06 13:20:39 +02:00
|
|
|
from common.tools import log_check_call
|
2013-12-29 23:21:50 +01:00
|
|
|
from . import assets
|
2013-08-10 16:51:42 +02:00
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
|
|
class InstallInitScripts(Task):
|
|
|
|
description = 'Installing startup scripts'
|
|
|
|
phase = phases.system_modification
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-08-10 16:51:42 +02:00
|
|
|
import stat
|
|
|
|
rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
|
|
|
|
stat.S_IRGRP | stat.S_IXGRP |
|
|
|
|
stat.S_IROTH | stat.S_IXOTH)
|
|
|
|
from shutil import copy
|
|
|
|
for name, src in info.initd['install'].iteritems():
|
|
|
|
dst = os.path.join(info.root, 'etc/init.d', name)
|
|
|
|
copy(src, dst)
|
|
|
|
os.chmod(dst, rwxr_xr_x)
|
2014-02-23 22:16:10 +01:00
|
|
|
log_check_call(['chroot', info.root, 'insserv', '--default', name])
|
2013-08-10 16:51:42 +02:00
|
|
|
|
|
|
|
for name in info.initd['disable']:
|
2014-02-23 22:16:10 +01:00
|
|
|
log_check_call(['chroot', info.root, 'insserv', '--remove', name])
|
2013-11-21 16:58:21 +01:00
|
|
|
|
|
|
|
|
2013-12-01 14:34:38 +01:00
|
|
|
class AddExpandRoot(Task):
|
|
|
|
description = 'Adding init script to expand the root volume'
|
|
|
|
phase = phases.system_modification
|
|
|
|
successors = [InstallInitScripts]
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 23:21:50 +01:00
|
|
|
init_scripts_dir = os.path.join(assets, 'init.d')
|
2013-12-01 14:34:38 +01:00
|
|
|
info.initd['install']['expand-root'] = os.path.join(init_scripts_dir, 'expand-root')
|
|
|
|
|
|
|
|
|
|
|
|
class AddSSHKeyGeneration(Task):
|
|
|
|
description = 'Adding SSH private key generation init scripts'
|
|
|
|
phase = phases.system_modification
|
|
|
|
successors = [InstallInitScripts]
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 23:21:50 +01:00
|
|
|
init_scripts_dir = os.path.join(assets, 'init.d')
|
2013-12-01 14:34:38 +01:00
|
|
|
install = info.initd['install']
|
|
|
|
from subprocess import CalledProcessError
|
|
|
|
try:
|
2014-02-23 22:16:10 +01:00
|
|
|
log_check_call(['chroot', info.root,
|
|
|
|
'dpkg-query', '-W', 'openssh-server'])
|
2013-12-01 14:34:38 +01:00
|
|
|
if info.manifest.system['release'] == 'squeeze':
|
|
|
|
install['generate-ssh-hostkeys'] = os.path.join(init_scripts_dir, 'squeeze/generate-ssh-hostkeys')
|
|
|
|
else:
|
|
|
|
install['generate-ssh-hostkeys'] = os.path.join(init_scripts_dir, 'generate-ssh-hostkeys')
|
|
|
|
except CalledProcessError:
|
2013-12-15 19:23:56 +01:00
|
|
|
import logging
|
|
|
|
logging.getLogger(__name__).warn('The OpenSSH server has not been installed, '
|
|
|
|
'not installing SSH host key generation script.')
|
2013-12-01 14:34:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RemoveHWClock(Task):
|
|
|
|
description = 'Removing hardware clock init scripts'
|
|
|
|
phase = phases.system_modification
|
|
|
|
successors = [InstallInitScripts]
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-01 14:34:38 +01:00
|
|
|
info.initd['disable'].append('hwclock.sh')
|
|
|
|
if info.manifest.system['release'] == 'squeeze':
|
|
|
|
info.initd['disable'].append('hwclockfirst.sh')
|
|
|
|
|
|
|
|
|
2013-11-21 16:58:21 +01:00
|
|
|
class AdjustExpandRootScript(Task):
|
|
|
|
description = 'Adjusting the expand-root script'
|
|
|
|
phase = phases.system_modification
|
|
|
|
predecessors = [InstallInitScripts]
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-11-21 16:58:21 +01:00
|
|
|
if 'expand-root' not in info.initd['install']:
|
|
|
|
raise TaskError('The expand-root script was not installed')
|
|
|
|
|
|
|
|
from base.fs.partitionmaps.none import NoPartitions
|
|
|
|
if not isinstance(info.volume.partition_map, NoPartitions):
|
|
|
|
import os.path
|
|
|
|
from common.tools import sed_i
|
|
|
|
script = os.path.join(info.root, 'etc/init.d.expand-root')
|
|
|
|
root_idx = info.volume.partition_map.root.get_index()
|
|
|
|
device_path = 'device_path="/dev/xvda{idx}"'.format(idx=root_idx)
|
|
|
|
sed_i(script, '^device_path="/dev/xvda$', device_path)
|