2013-08-10 16:51:42 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
2013-10-06 13:20:39 +02:00
|
|
|
from common.tools import log_check_call
|
2013-08-10 16:51:42 +02:00
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
|
|
class ResolveInitScripts(Task):
|
|
|
|
description = 'Determining which startup scripts to install or disable'
|
|
|
|
phase = phases.system_modification
|
|
|
|
|
|
|
|
def run(self, info):
|
2013-10-27 17:49:39 +01:00
|
|
|
init_scripts = {}
|
|
|
|
init_scripts['expand-volume'] = 'expand-volume'
|
2013-08-10 16:51:42 +02:00
|
|
|
|
2013-10-06 13:20:39 +02:00
|
|
|
from subprocess import CalledProcessError
|
|
|
|
try:
|
|
|
|
log_check_call(['/usr/sbin/chroot', info.root,
|
|
|
|
'/usr/bin/dpkg-query', '-W', 'openssh-server'])
|
|
|
|
init_scripts['generate-ssh-hostkeys'] = 'generate-ssh-hostkeys'
|
|
|
|
if info.manifest.system['release'] == 'squeeze':
|
|
|
|
init_scripts['generate-ssh-hostkeys'] = 'squeeze/generate-ssh-hostkeys'
|
|
|
|
except CalledProcessError:
|
|
|
|
pass
|
2013-08-10 16:51:42 +02:00
|
|
|
|
|
|
|
disable_scripts = ['hwclock.sh']
|
|
|
|
if info.manifest.system['release'] == 'squeeze':
|
|
|
|
disable_scripts.append('hwclockfirst.sh')
|
|
|
|
|
|
|
|
init_scripts_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/init.d'))
|
|
|
|
for name, path in init_scripts.iteritems():
|
|
|
|
init_scripts[name] = os.path.join(init_scripts_dir, path)
|
|
|
|
|
|
|
|
info.initd = {'install': init_scripts,
|
|
|
|
'disable': disable_scripts}
|
|
|
|
|
|
|
|
|
|
|
|
class InstallInitScripts(Task):
|
|
|
|
description = 'Installing startup scripts'
|
|
|
|
phase = phases.system_modification
|
2013-11-21 15:54:42 +01:00
|
|
|
predecessors = [ResolveInitScripts]
|
2013-08-10 16:51:42 +02:00
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
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)
|
2013-08-17 15:00:53 +00:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root, '/sbin/insserv', '--default', name])
|
2013-08-10 16:51:42 +02:00
|
|
|
|
|
|
|
for name in info.initd['disable']:
|
2013-08-17 15:00:53 +00:00
|
|
|
log_check_call(['/usr/sbin/chroot', info.root, '/sbin/insserv', '--remove', name])
|