action_utils: Introduce utility for setting debconf answers

Tests:

mldonkey
 - Installs
 - /etc/default/mldonkey-server has LAUNCH_AT_STARTUP=true
 - systemctl status mldonkey-server shows daemon running

ejabberd
 - Installs
 - /etc/ejabberd/ejabberd.yml has domainname properly configured

privoxy
 - Installs
 - /etc/privoxy/config has listen-address set to '[::]:8118'

roundcube
 - Installs and works
 - /etc/roundcube/debian-db.php contains dbtype sqlite3

ttrss
 - Installs and works
 - /etc/ttrss/database.php has dbtype 'pgsql'.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-08-21 15:45:38 -07:00 committed by James Valleroy
parent 12cf790dcd
commit ca8ea9427c
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
7 changed files with 34 additions and 35 deletions

View File

@ -129,21 +129,20 @@ def subcommand_disable_user_registrations(_):
def subcommand_pre_install(_):
"""Pre installation configuration for diaspora"""
presets = [
b'diaspora-common diaspora-common/url string dummy_domain_name',
b'diaspora-common diaspora-common/dbpass note ',
b'diaspora-common diaspora-common/enablessl boolean false',
b'diaspora-common diaspora-common/useletsencrypt string false',
b'diaspora-common diaspora-common/services multiselect ',
b'diaspora-common diaspora-common/ssl boolean false',
b'diaspora-common diaspora-common/pgsql/authmethod-admin string ident',
b'diaspora-common diaspora-common/letsencrypt boolean false',
b'diaspora-common diaspora-common/remote/host string localhost',
b'diaspora-common diaspora-common/database-type string pgsql',
b'diaspora-common diaspora-common/dbconfig-install boolean true'
'diaspora-common diaspora-common/url string dummy_domain_name',
'diaspora-common diaspora-common/dbpass note ',
'diaspora-common diaspora-common/enablessl boolean false',
'diaspora-common diaspora-common/useletsencrypt string false',
'diaspora-common diaspora-common/services multiselect ',
'diaspora-common diaspora-common/ssl boolean false',
'diaspora-common diaspora-common/pgsql/authmethod-admin string ident',
'diaspora-common diaspora-common/letsencrypt boolean false',
'diaspora-common diaspora-common/remote/host string localhost',
'diaspora-common diaspora-common/database-type string pgsql',
'diaspora-common diaspora-common/dbconfig-install boolean true'
]
for preset in presets:
subprocess.check_output(['debconf-set-selections'], input=preset)
action_utils.debconf_set_selections(presets)
def main():

View File

@ -100,9 +100,8 @@ def subcommand_pre_install(arguments):
# If new domainname is blank, use hostname instead.
domainname = socket.gethostname()
subprocess.check_output(
['debconf-set-selections'],
input=b'ejabberd ejabberd/hostname string ' + domainname.encode())
action_utils.debconf_set_selections(
['ejabberd ejabberd/hostname string ' + domainname])
def subcommand_setup(arguments):

View File

@ -21,7 +21,8 @@ Configuration helper for mldonkey.
"""
import argparse
import subprocess
from plinth import action_utils
def parse_arguments():
@ -37,9 +38,8 @@ def parse_arguments():
def subcommand_pre_install(_):
"""Preseed debconf values before packages are installed."""
subprocess.check_output([
'debconf-set-selections'
], input=b'mldonkey-server mldonkey-server/launch_at_startup boolean true')
action_utils.debconf_set_selections(
['mldonkey-server mldonkey-server/launch_at_startup boolean true'])
def main():

View File

@ -15,13 +15,13 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Configuration helper for Privoxy server.
"""
import argparse
import subprocess
from plinth import action_utils
def parse_arguments():
@ -39,10 +39,8 @@ def parse_arguments():
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)
action_utils.debconf_set_selections(
['privoxy privoxy/listen-address string [::]:8118'])
def main():

View File

@ -21,7 +21,6 @@ Configuration helper for Roundcube server.
import argparse
import re
import subprocess
from plinth import action_utils
@ -44,12 +43,10 @@ def parse_arguments():
def subcommand_pre_install(_):
"""Preseed debconf values before packages are installed."""
subprocess.check_output(
['debconf-set-selections'],
input=b'roundcube-core roundcube/dbconfig-install boolean true')
subprocess.check_output(
['debconf-set-selections'],
input=b'roundcube-core roundcube/database-type string sqlite3')
action_utils.debconf_set_selections([
'roundcube-core roundcube/dbconfig-install boolean true',
'roundcube-core roundcube/database-type string sqlite3'
])
def subcommand_setup(_):

View File

@ -51,8 +51,8 @@ def parse_arguments():
def subcommand_pre_setup(_):
"""Preseed debconf values before packages are installed."""
subprocess.check_output(['debconf-set-selections'],
input=b'tt-rss tt-rss/database-type string pgsql')
action_utils.debconf_set_selections(
['tt-rss tt-rss/database-type string pgsql'])
def subcommand_setup(_):

View File

@ -529,6 +529,12 @@ Owners: {package}
pass
def debconf_set_selections(presets):
"""Answer debconf questions before installing a package."""
presets = '\n'.join(presets)
subprocess.check_output(['debconf-set-selections'], input=presets.encode())
def is_disk_image():
"""Return whether the current machine is from a disk image.