apache: Only regenerate snake oil cert when needed

Closes #1230.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2018-03-22 12:01:18 +05:30 committed by James Valleroy
parent b057a57dec
commit 7b326870da
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 25 additions and 6 deletions

View File

@ -31,18 +31,26 @@ def parse_arguments():
"""Return parsed command line arguments as dictionary"""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
subparsers.add_parser('setup', help='Setup for Apache')
subparser = subparsers.add_parser('setup', help='Setup for Apache')
subparser.add_argument(
'--old-version', type=int, required=True,
help='Earlier version of the app that is already setup.')
subparsers.required = True
return parser.parse_args()
def subcommand_setup(_):
def subcommand_setup(arguments):
"""Setup Apache configuration."""
# Regenerate the snakeoil self-signed SSL certificate. This is so that
# FreedomBox images don't all have the same certificate.
subprocess.run(['make-ssl-cert', 'generate-default-snakeoil',
'--force-overwrite'], check=True)
# FreedomBox images don't all have the same certificate. When FreedomBox
# package is installed via apt, don't regenerate. When upgrading to newer
# version of Apache FreedomBox app and setting up for the first time don't
# regenerate.
if action_utils.is_disk_image() and arguments.old_version == 0:
subprocess.run([
'make-ssl-cert', 'generate-default-snakeoil', '--force-overwrite'
], check=True)
with action_utils.WebserverChange() as webserver:
# set the prefork worker model

View File

@ -478,3 +478,13 @@ Owners: {package}
os.remove(override_file.name)
except OSError:
pass
def is_disk_image():
"""Return whether the current machine is from a disk image.
Two primary ways to install FreedomBox are:
- Using FreedomBox image for various hardware platforms.
- Installing packages on a Debian machine using apt.
"""
return os.path.exists('/var/lib/freedombox/is-freedombox-disk-image')

View File

@ -30,4 +30,5 @@ managed_packages = ['apache2', 'libapache2-mod-gnutls', 'libapache2-mod-php']
def setup(helper, old_version=None):
"""Configure the module."""
helper.install(managed_packages)
actions.superuser_run('apache', ['setup'])
actions.superuser_run('apache',
['setup', '--old-version', str(old_version)])