diff --git a/actions/apache b/actions/apache index d66933ea5..1fbcae470 100755 --- a/actions/apache +++ b/actions/apache @@ -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 diff --git a/plinth/action_utils.py b/plinth/action_utils.py index a0b6a588f..370e52889 100644 --- a/plinth/action_utils.py +++ b/plinth/action_utils.py @@ -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') diff --git a/plinth/modules/apache/__init__.py b/plinth/modules/apache/__init__.py index 2f943fc4a..246d411fe 100644 --- a/plinth/modules/apache/__init__.py +++ b/plinth/modules/apache/__init__.py @@ -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)])