From 269d61fb57552e02e1e84a03a349083b36dbf44b Mon Sep 17 00:00:00 2001 From: Robert Hecht Date: Tue, 21 Sep 2021 11:26:53 +0200 Subject: [PATCH] added bash completion for Ubuntu and Debian --- REFERENCE.md | 18 ++++++++++++++++++ manifests/init.pp | 4 ++++ manifests/install.pp | 14 ++++++++++++++ manifests/params.pp | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/REFERENCE.md b/REFERENCE.md index ca228bbc..ffaf8db6 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -78,6 +78,8 @@ The following parameters are available in the `consul` class: * [`acl_api_token`](#-consul--acl_api_token) * [`arch`](#-consul--arch) * [`archive_path`](#-consul--archive_path) +* [`bash_completion`](#-consul--bash_completion) +* [`bash_completion_compat_dir`](#-consul--bash_completion_compat_dir) * [`bin_dir`](#-consul--bin_dir) * [`binary_group`](#-consul--binary_group) * [`binary_mode`](#-consul--binary_mode) @@ -206,6 +208,22 @@ Path used when installing consul via the url Default value: `undef` +##### `bash_completion` + +Data type: `Boolean` + +Whether to setup bash completion. Adjust bin_dir when install_method == package. + +Default value: `$consul::params::bash_completion` + +##### `bash_completion_compat_dir` + +Data type: `String[1]` + +Directory to place bash-completion file for Consul into. + +Default value: `$consul::params::bash_completion_compat_dir` + ##### `bin_dir` Data type: `Stdlib::Absolutepath` diff --git a/manifests/init.pp b/manifests/init.pp index f47f48d9..20586b2c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -11,6 +11,8 @@ # @param acl_api_token Global token of ACL API, will be merged with consul_token resources # @param arch Architecture of consul binary to download # @param archive_path Path used when installing consul via the url +# @param bash_completion Whether to setup bash completion. Adjust bin_dir when install_method == package. +# @param bash_completion_compat_dir Directory to place bash-completion file for Consul into. # @param bin_dir Directory to create the symlink to the consul binary in. # @param binary_group The group that the file belongs to. # @param binary_mode Permissions mode for the file. @@ -95,6 +97,8 @@ String[0] $acl_api_token = '', # lint:ignore:params_empty_string_assignment String[1] $arch = $consul::params::arch, Optional[Stdlib::Absolutepath] $archive_path = undef, + Boolean $bash_completion = $consul::params::bash_completion, + String[1] $bash_completion_compat_dir = $consul::params::bash_completion_compat_dir, Stdlib::Absolutepath $bin_dir = $consul::params::bin_dir, Optional[String[1]] $binary_group = $consul::params::binary_group, String[1] $binary_mode = $consul::params::binary_mode, diff --git a/manifests/install.pp b/manifests/install.pp index a5dea517..6d3353ae 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -119,4 +119,18 @@ system => true, } } + + if ($consul::bash_completion) and ($consul::install_method != 'docker' ) { + file { $consul::bash_completion_compat_dir: + ensure => 'directory', + } + + file { "${consul::bash_completion_compat_dir}/consul": + ensure => file, + owner => 'root', + group => 'root', + mode => '0644', + content => "complete -C ${consul::bin_dir}/${consul::binary_name} consul\n", + } + } } diff --git a/manifests/params.pp b/manifests/params.pp index a52ff4d2..3d3f6ed7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -47,6 +47,7 @@ default: { # 0 instead of root because OS X uses "wheel". $data_dir_mode = '0755' + $bash_completion_compat_dir = '/etc/bash_completion.d/' $binary_group = '0' $binary_mode = '0555' $binary_name = 'consul' @@ -63,12 +64,14 @@ case $facts['os']['name'] { 'Ubuntu': { + $bash_completion = true $shell = '/usr/sbin/nologin' } 'RedHat': { $shell = '/sbin/nologin' } 'Debian': { + $bash_completion = true $shell = '/usr/sbin/nologin' } 'Archlinux': { @@ -81,6 +84,7 @@ $shell = '/usr/sbin/nologin' } default: { + $bash_completion = false $shell = undef } }