From 269d61fb57552e02e1e84a03a349083b36dbf44b Mon Sep 17 00:00:00 2001 From: Robert Hecht Date: Tue, 21 Sep 2021 11:26:53 +0200 Subject: [PATCH 1/3] 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 } } From 5226b6f572ef1f287b61f0a2a531a595a456a39c Mon Sep 17 00:00:00 2001 From: Jard Leex Date: Tue, 6 Jun 2023 16:31:15 +0200 Subject: [PATCH 2/3] moved default value of bash_completion_compat_dir from params.pp to init.pp --- REFERENCE.md | 2 +- manifests/init.pp | 2 +- manifests/params.pp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index ffaf8db6..e93022a8 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -222,7 +222,7 @@ Data type: `String[1]` Directory to place bash-completion file for Consul into. -Default value: `$consul::params::bash_completion_compat_dir` +Default value: `'/etc/bash_completion.d/'` ##### `bin_dir` diff --git a/manifests/init.pp b/manifests/init.pp index 20586b2c..95fb6ec5 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -98,7 +98,7 @@ 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, + String[1] $bash_completion_compat_dir = '/etc/bash_completion.d/', 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/params.pp b/manifests/params.pp index 3d3f6ed7..bcabcb28 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -47,7 +47,6 @@ 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' From feb4dc116dd474bbd0ebc025d87d2ae60128c972 Mon Sep 17 00:00:00 2001 From: Jard Leex Date: Tue, 6 Jun 2023 16:34:06 +0200 Subject: [PATCH 3/3] disabled bash_completion for RedHat, Archlinux, OpenSuse and SLE[SD] as it's untested --- manifests/params.pp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/manifests/params.pp b/manifests/params.pp index bcabcb28..40f5f05c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -67,6 +67,7 @@ $shell = '/usr/sbin/nologin' } 'RedHat': { + $bash_completion = false $shell = '/sbin/nologin' } 'Debian': { @@ -74,12 +75,15 @@ $shell = '/usr/sbin/nologin' } 'Archlinux': { + $bash_completion = false $shell = '/sbin/nologin' } 'OpenSuSE': { + $bash_completion = false $shell = '/usr/sbin/nologin' } /SLE[SD]/: { + $bash_completion = false $shell = '/usr/sbin/nologin' } default: {