mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Pep8 and define SSHD_CONF
This commit is contained in:
parent
4e92a36322
commit
4602439c01
2 changed files with 14 additions and 19 deletions
|
@ -1,4 +1,3 @@
|
|||
import subprocess
|
||||
import os
|
||||
import re
|
||||
|
||||
|
@ -15,6 +14,8 @@ from yunohost.service import service_regen_conf, _get_conf_hashes, \
|
|||
|
||||
logger = getActionLogger('yunohost.migration')
|
||||
|
||||
SSHD_CONF = '/etc/ssh/sshd_config'
|
||||
|
||||
|
||||
class MyMigration(Migration):
|
||||
"""
|
||||
|
@ -25,30 +26,30 @@ class MyMigration(Migration):
|
|||
def migrate(self):
|
||||
|
||||
# Create sshd_config.d dir
|
||||
if not os.path.exists('/etc/ssh/sshd_config.d'):
|
||||
mkdir('/etc/ssh/sshd_config.d', 0755, uid='root', gid='root')
|
||||
if not os.path.exists(SSHD_CONF + '.d'):
|
||||
mkdir(SSHD_CONF + '.d', 0755, uid='root', gid='root')
|
||||
|
||||
# Manage SSHd in all case
|
||||
if os.path.exists('/etc/yunohost/from_script'):
|
||||
rm('/etc/yunohost/from_script')
|
||||
copyfile('/etc/ssh/sshd_config', '/etc/ssh/sshd_config.bkp')
|
||||
copyfile(SSHD_CONF, '/etc/ssh/sshd_config.bkp')
|
||||
service_regen_conf(names=['ssh'], force=True)
|
||||
copyfile('/etc/ssh/sshd_config.bkp', '/etc/ssh/sshd_config')
|
||||
copyfile('/etc/ssh/sshd_config.bkp', SSHD_CONF)
|
||||
|
||||
# If custom conf, add 'Include' instruction
|
||||
ynh_hash = _get_conf_hashes('ssh')['/etc/ssh/sshd_config']
|
||||
current_hash = _calculate_hash('/etc/ssh/sshd_config')
|
||||
ynh_hash = _get_conf_hashes('ssh')[SSHD_CONF]
|
||||
current_hash = _calculate_hash(SSHD_CONF)
|
||||
include_rgx = r'^[ \t]*Include[ \t]+sshd_config\.d/\*[ \t]*(?:#.*)?$'
|
||||
if ynh_hash != current_hash:
|
||||
|
||||
add_include = False
|
||||
include_rgx = r'^[ \t]*Include[ \t]+sshd_config\.d/\*[ \t]*(?:#.*)?$'
|
||||
for line in open('/etc/ssh/sshd_config'):
|
||||
for line in open(SSHD_CONF):
|
||||
if re.match(include_rgx, line) is not None:
|
||||
add_include = True
|
||||
break
|
||||
|
||||
if add_include:
|
||||
with open("/etc/ssh/sshd_config", "a") as conf:
|
||||
with open(SSHD_CONF, "a") as conf:
|
||||
conf.write('Include sshd_config.d/*')
|
||||
|
||||
# Restart ssh and backward if it fail
|
||||
|
@ -56,11 +57,9 @@ class MyMigration(Migration):
|
|||
self.backward()
|
||||
raise MoulinetteError(m18n.n("migration_0006_cancel"))
|
||||
|
||||
|
||||
def backward(self):
|
||||
# We don't backward completely but it should be enough
|
||||
|
||||
copyfile('/etc/ssh/sshd_config.bkp', '/etc/ssh/sshd_config')
|
||||
copyfile('/etc/ssh/sshd_config.bkp', SSHD_CONF)
|
||||
if not _run_service_command('restart', 'ssh'):
|
||||
raise MoulinetteError(m18n.n("migration_0006_cannot_restart"))
|
||||
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
import subprocess
|
||||
import os
|
||||
import re
|
||||
|
||||
from shutil import copyfile
|
||||
|
||||
from moulinette import m18n
|
||||
from moulinette.core import MoulinetteError
|
||||
from moulinette.utils.log import getActionLogger
|
||||
|
||||
from yunohost.tools import Migration
|
||||
from yunohost.service import service_regen_conf, _get_conf_hashes, _calculate_hash
|
||||
from yunohost.service import service_regen_conf, _get_conf_hashes, \
|
||||
_calculate_hash
|
||||
|
||||
logger = getActionLogger('yunohost.migration')
|
||||
|
||||
|
@ -37,7 +34,6 @@ class MyMigration(Migration):
|
|||
|
||||
return "manual"
|
||||
|
||||
|
||||
@property
|
||||
def disclaimer(self):
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue