From 8ecb0239390891eed4ebda10523037328bc9ba97 Mon Sep 17 00:00:00 2001 From: Matthew Pherigo Date: Mon, 2 Feb 2015 23:10:23 -0600 Subject: [PATCH 1/2] pkgng: add 'batch' parameter Some packages attempt to prompt the user for certain settings during installation. Thus, this parameter sets the environment variable $BATCH to 'yes', which forces package installation scripts to accept default values for these interactive prompts. This should work for all prompts that have a default value and aren't implemented through a custom script (as this variable is built into the ports/package system). FIXME: Package install should fail if it prompts and batch isn't set; currently, the install hangs indefinitely. TODO: Allow user to specify the answers to certain prompts. I (github.com/mwpher) have NOT tested this with any packages besides bsdstats. It's a small improvement, but not a complete answer to all the complexities of package installation. --- packaging/os/pkgng.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packaging/os/pkgng.py b/packaging/os/pkgng.py index a1f443fd4e1..b0ebe9d547a 100644 --- a/packaging/os/pkgng.py +++ b/packaging/os/pkgng.py @@ -63,6 +63,13 @@ options: for newer pkgng versions, specify a the name of a repository configured in /usr/local/etc/pkg/repos required: false + batch: + description: + - for packages with interactive prompts during installation, + this makes pkgng automatically accept all default options for + the installation of the package. + default: yes + required: false author: bleader notes: - When using pkgsite, be careful that already in cache packages won't be downloaded again. @@ -136,7 +143,7 @@ def remove_packages(module, pkgng_path, packages): return (False, "package(s) already absent") -def install_packages(module, pkgng_path, packages, cached, pkgsite): +def install_packages(module, pkgng_path, packages, cached, pkgsite, batch): install_c = 0 @@ -149,6 +156,11 @@ def install_packages(module, pkgng_path, packages, cached, pkgsite): else: pkgsite = "-r %s" % (pkgsite) + if batch == True: + batch_var = 'env BATCH=yes' + else: + batch_var = '' + if not module.check_mode and not cached: if old_pkgng: rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgng_path)) @@ -163,9 +175,9 @@ def install_packages(module, pkgng_path, packages, cached, pkgsite): if not module.check_mode: if old_pkgng: - rc, out, err = module.run_command("%s %s install -g -U -y %s" % (pkgsite, pkgng_path, package)) + rc, out, err = module.run_command("%s %s %s install -g -U -y %s" % (batch_var, pkgsite, pkgng_path, package)) else: - rc, out, err = module.run_command("%s install %s -g -U -y %s" % (pkgng_path, pkgsite, package)) + rc, out, err = module.run_command("%s %s install %s -g -U -y %s" % (batch_var, pkgng_path, pkgsite, package)) if not module.check_mode and not query_package(module, pkgng_path, package): module.fail_json(msg="failed to install %s: %s" % (package, out), stderr=err) @@ -264,7 +276,8 @@ def main(): name = dict(aliases=["pkg"], required=True), cached = dict(default=False, type='bool'), annotation = dict(default="", required=False), - pkgsite = dict(default="", required=False)), + pkgsite = dict(default="", required=False), + batch = dict(default=False, required=False, type='bool')), supports_check_mode = True) pkgng_path = module.get_bin_path('pkg', True) @@ -277,7 +290,7 @@ def main(): msgs = [] if p["state"] == "present": - _changed, _msg = install_packages(module, pkgng_path, pkgs, p["cached"], p["pkgsite"]) + _changed, _msg = install_packages(module, pkgng_path, pkgs, p["cached"], p["pkgsite"], p["batch"]) changed = changed or _changed msgs.append(_msg) From e909beb6537c318f7227901bd5cdc3a4a17b1a08 Mon Sep 17 00:00:00 2001 From: Matthew Pherigo Date: Tue, 3 Feb 2015 15:43:24 -0600 Subject: [PATCH 2/2] Make $BATCH=yes the default, remove module option --- packaging/os/pkgng.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/packaging/os/pkgng.py b/packaging/os/pkgng.py index b0ebe9d547a..1aa8e0c737f 100644 --- a/packaging/os/pkgng.py +++ b/packaging/os/pkgng.py @@ -63,13 +63,6 @@ options: for newer pkgng versions, specify a the name of a repository configured in /usr/local/etc/pkg/repos required: false - batch: - description: - - for packages with interactive prompts during installation, - this makes pkgng automatically accept all default options for - the installation of the package. - default: yes - required: false author: bleader notes: - When using pkgsite, be careful that already in cache packages won't be downloaded again. @@ -143,7 +136,7 @@ def remove_packages(module, pkgng_path, packages): return (False, "package(s) already absent") -def install_packages(module, pkgng_path, packages, cached, pkgsite, batch): +def install_packages(module, pkgng_path, packages, cached, pkgsite): install_c = 0 @@ -156,10 +149,8 @@ def install_packages(module, pkgng_path, packages, cached, pkgsite, batch): else: pkgsite = "-r %s" % (pkgsite) - if batch == True: - batch_var = 'env BATCH=yes' - else: - batch_var = '' + batch_var = 'env BATCH=yes' # This environment variable skips mid-install prompts, + # setting them to their default values. if not module.check_mode and not cached: if old_pkgng: @@ -276,8 +267,7 @@ def main(): name = dict(aliases=["pkg"], required=True), cached = dict(default=False, type='bool'), annotation = dict(default="", required=False), - pkgsite = dict(default="", required=False), - batch = dict(default=False, required=False, type='bool')), + pkgsite = dict(default="", required=False)), supports_check_mode = True) pkgng_path = module.get_bin_path('pkg', True) @@ -290,7 +280,7 @@ def main(): msgs = [] if p["state"] == "present": - _changed, _msg = install_packages(module, pkgng_path, pkgs, p["cached"], p["pkgsite"], p["batch"]) + _changed, _msg = install_packages(module, pkgng_path, pkgs, p["cached"], p["pkgsite"]) changed = changed or _changed msgs.append(_msg)