Set privoxy listen-address by debconf preseed before install.

This commit is contained in:
James Valleroy 2016-05-25 19:23:54 -04:00
parent 7b8b12dc20
commit f6884a18fa
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 11 additions and 27 deletions

View File

@ -22,12 +22,7 @@ Configuration helper for Privoxy server.
"""
import argparse
import re
from plinth import action_utils
CONFIG_FILE = '/etc/privoxy/config'
import subprocess
def parse_arguments():
@ -35,30 +30,19 @@ def parse_arguments():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
subparsers.add_parser('setup',
help='Perform Privoxy configuration setup')
subparsers.add_parser(
'pre-install',
help='Preseed debconf values before packages are installed')
return parser.parse_args()
def subcommand_setup(_):
"""Setup configuration for the first time."""
with open(CONFIG_FILE, 'r') as conffile:
lines = conffile.readlines()
with open(CONFIG_FILE, 'w') as conffile:
written = False
for line in lines:
if re.match(r'#?listen-address', line) and not written:
conffile.write('listen-address [::]:8118\n')
written = True
else:
conffile.write(line)
if not written:
conffile.write('listen-address [::]:8118')
action_utils.service_restart('privoxy')
def subcommand_pre_install(_):
"""Preseed debconf values before packages are installed."""
subprocess.run(
['debconf-set-selections'],
input=b'privoxy privoxy/listen-address string [::]:8118',
check=True)
def main():

View File

@ -69,8 +69,8 @@ def init():
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.call('pre', actions.superuser_run, 'privoxy', ['pre-install'])
helper.install(['privoxy'])
helper.call('post', actions.superuser_run, 'privoxy', ['setup'])
helper.call('post', service.notify_enabled, None, True)