Skip to content

Commit 73d28a8

Browse files
committed
(tasks) Add package param to install task
By default, openvox_bootstrap::install will still install openvox-agent, but you can override `package` to install another package, such as openvox-server or openvoxdb from the collection.
1 parent bb48d12 commit 73d28a8

File tree

6 files changed

+92
-65
lines changed

6 files changed

+92
-65
lines changed

README.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# openvox_bootstrap
22

3-
[Bolt](https://www.puppet.com/docs/bolt/latest/bolt.html) module for
4-
bootstrapping installation of the openvox-agent package.
3+
[Bolt] module for bootstrapping installation of the [openvox]
4+
(Puppet<sup>:tm:</sup>) packages.
55

66
Provides some of the functionality of the [puppet_agent::install
7-
tasks](https://github.com/puppetlabs/puppetlabs-puppet_agent/tree/main?tab=readme-ov-file#puppet_agentinstall)
8-
for [openvox](https://voxpupuli.org/openvox/) packages from
9-
https://apt.voxpupuli.org, https://yum.voxpupuli.org.
7+
tasks] for [openvox] packages from https://apt.voxpupuli.org,
8+
https://yum.voxpupuli.org.
109

1110
The puppet_agent module makes use of the Perforce repositories and
1211
collections instead.
@@ -17,28 +16,34 @@ Assumes you have Bolt installed.
1716

1817
### openvox_boostrap::install
1918

20-
Installs the openvox8 collection by default (Puppet<sup>:tm:</sup> 8).
19+
Installs the platform appropriate openvox8 collection release package
20+
and the openvox-agent package by default (Puppet<sup>:tm:</sup> 8).
2121

2222
```sh
2323
bolt task run openvox_bootstrap::install \
2424
--targets <target> \
2525
--run-as root
2626
```
27+
#### parameters
28+
29+
By default the task will install the openvox-agent package, but this
30+
can be overridden by setting the `package` parameter to install
31+
openvox-server, openvoxdb or another package from the openvox
32+
collection.
33+
34+
See the [install task](./REFERENCE.md#install) for details.
2735

2836
#### Usage with Bolt apply_prep() function
2937

30-
Bolt's
31-
[apply_prep](https://www.puppet.com/docs/bolt/latest/plan_functions#apply-prep)
32-
function ensures that the latest version of Puppet<sup>:tm:</sup> is installed on
33-
a node by calling the puppet_agent::install task if the agent is not
34-
detected on the node.
38+
Bolt's [apply_prep] function ensures that the latest version of
39+
Puppet<sup>:tm:</sup> is installed on a node by calling the
40+
`puppet_agent::install` task if the agent is not detected on the node.
3541

36-
The openvox_bootstrap::install task can be used in its place to
42+
The `openvox_bootstrap::install` task can be used in its place to
3743
instead ensure that openvox-agent is installed.
3844

39-
The apply_prep() function relies on Bolt's
40-
[puppet_library](https://www.puppet.com/docs/bolt/latest/using_plugins#puppet-library-plugins)
41-
plugin configuration.
45+
The apply_prep() function relies on Bolt's [puppet_library] plugin
46+
configuration.
4247

4348
To use openvox_bootstrap instead, configure your bolt_project.yaml
4449
with:
@@ -57,9 +62,15 @@ task that can be used to install a build artifact package directly
5762
from the https://artifact.voxpupuli.org repository for testing
5863
prior to release.
5964
65+
Minimally, you must supply the `version` parameter, but generally you
66+
would also supply `package` unless you are installing the
67+
openvox-agent package.
68+
69+
See [task ref](./REFERENCE.md#install_build_artifact) for details.
70+
6071
```sh
61-
bolt task run openvox_bootstrap::install \
62-
--targets <target> \
72+
bolt task run openvox_bootstrap::install_build_artifact \
73+
--targets <target> --version=8.17.0 \
6374
--run-as root
6475
```
6576

@@ -85,3 +96,9 @@ GNU Affero General Public License for more details.
8596

8697
You should have received a copy of the GNU Affero General Public License
8798
along with this program. If not, see <https://www.gnu.org/licenses/>.
99+
100+
[bolt]: https://puppet.com/docs/bolt/latest/bolt.html
101+
[openvox]: https://voxpupuli.org/openvox/
102+
[puppet_agent::install tasks]: https://github.com/puppetlabs/puppetlabs-puppet_agent/tree/main?tab=readme-ov-file#puppet_agentinstall
103+
[apply_prep]: https://www.puppet.com/docs/bolt/latest/plan_functions#apply-prep
104+
[puppet_library]: https://www.puppet.com/docs/bolt/latest/using_plugins#puppet-library-plugins

REFERENCE.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66

77
### Tasks
88

9-
* [`install`](#install): Installs the openvox-agent package.
9+
* [`install`](#install): Installs an openvox package. By default, this will be the latest openvox-agent from the latest collection.
1010
* [`install_build_artifact`](#install_build_artifact): Downloads and installs a package directly from openvox build artifact server. This can be used to help with testing builds prior to release.
1111

1212
## Tasks
1313

1414
### <a name="install"></a>`install`
1515

16-
Installs the openvox-agent package.
16+
Installs an openvox package. By default, this will be the latest openvox-agent from the latest collection.
1717

1818
**Supports noop?** false
1919

2020
#### Parameters
2121

22+
##### `package`
23+
24+
Data type: `String[1]`
25+
26+
The name of the package to install.
27+
2228
##### `version`
2329

2430
Data type: `Optional[String]`
@@ -51,17 +57,17 @@ Downloads and installs a package directly from openvox build artifact server. Th
5157

5258
#### Parameters
5359

54-
##### `version`
60+
##### `package`
5561

5662
Data type: `String[1]`
5763

58-
The version of the package to install.
64+
The name of the package to install.
5965

60-
##### `package`
66+
##### `version`
6167

6268
Data type: `String[1]`
6369

64-
The name of the package to install.
70+
The version of the package to install.
6571

6672
##### `artifacts_source`
6773

files/common.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,29 @@ set_package_type() {
260260
assigned 'package_file_suffix'
261261
}
262262

263+
# Construct and echo the full debian package version string.
264+
# Echoing for $() capture rather than setting a 'global' $var
265+
# since this could be called multiple times for different packages.
266+
get_deb_package_version() {
267+
local _version="$1"
268+
local _family="${2:-${family}}"
269+
local _full_version="${3-${full_version}}"
270+
271+
# Need the full packaging version for deb.
272+
# As an example, for openvox-agent 8.14.0 on ubuntu 24.04:
273+
# 8.14.0-1+ubuntu24.04
274+
if [[ "${_version}" =~ - ]]; then
275+
# Caller's version already has a '-' seprator, so we
276+
# should respect that they have probably supplied some
277+
# full package version string.
278+
_package_version="${_version}"
279+
else
280+
_package_version="${_version}-1+${_family}${_full_version}"
281+
fi
282+
283+
echo -n "${_package_version}"
284+
}
285+
263286
# Install a local rpm or deb package file.
264287
install_package_file() {
265288
local _package_file="$1"
@@ -281,10 +304,13 @@ install_package_file() {
281304
}
282305

283306
# Install a package using the system package manager.
307+
# The version is optional, and if not provided, the latest version
308+
# available in the repository will be installed.
284309
install_package() {
285310
local _package="$1"
286311
local _version="$2"
287312
local _family="${3:-${family}}"
313+
local _full_version="${4:-${full_version}}"
288314

289315
info "Installing ${_package} ${_version}"
290316

@@ -296,7 +322,13 @@ install_package() {
296322
fi
297323
case $_family in
298324
debian|ubuntu)
299-
_package_and_version="${_package}=${_version}"
325+
if [[ -z "${_full_version}" ]]; then
326+
set_platform
327+
_full_version="${full_version}"
328+
fi
329+
local _deb_package_version
330+
_deb_package_version=$(get_deb_package_version "${_version}" "${_family}" "${_full_version}")
331+
_package_and_version="${_package}=${deb_package_version}"
300332
;;
301333
*)
302334
_package_and_version="${_package}-${_version}"

tasks/install.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
2-
"description": "Installs the openvox-agent package.",
2+
"description": "Installs an openvox package. By default, this will be the latest openvox-agent from the latest collection.",
33
"parameters": {
4+
"package": {
5+
"description": "The name of the package to install.",
6+
"type": "String[1]",
7+
"default": "openvox-agent"
8+
},
49
"version": {
510
"description": "The version of the openvox-agent package to install. Defaults to latest.",
611
"type": "Optional[String]"

tasks/install_build_artifact.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"description": "Downloads and installs a package directly from openvox build artifact server. This can be used to help with testing builds prior to release. (To install a released version, use the openvox_bootstrap::install task.)",
33
"parameters": {
4-
"version": {
5-
"description": "The version of the package to install.",
6-
"type": "String[1]"
7-
},
84
"package": {
95
"description": "The name of the package to install.",
106
"type": "String[1]",
117
"default": "openvox-agent"
128
},
9+
"version": {
10+
"description": "The version of the package to install.",
11+
"type": "String[1]"
12+
},
1313
"artifacts_source": {
1414
"description": "URL to the build artifacts server.",
1515
"type": "String[1]",

tasks/install_linux.sh

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set -e
66
# shellcheck disable=SC2154
77
installdir=$PT__installdir
88
# shellcheck disable=SC2154
9+
package=${PT_package:-'openvox-agent'}
10+
# shellcheck disable=SC2154
911
version=${PT_version:-'latest'}
1012
# shellcheck disable=SC2154
1113
collection=${PT_collection:-'openvox8'}
@@ -72,41 +74,6 @@ install_release_package() {
7274
fi
7375
}
7476

75-
# Installs the openvox-agent package using the system package manager.
76-
# The version is optional, and if not provided, the latest version
77-
# available in the repository will be installed.
78-
install_openvox_agent() {
79-
local _version="$1"
80-
local _family="$2"
81-
local _full_version="$3"
82-
83-
local _package_version
84-
if [[ -n "${_version}" ]] && [[ "${_version}" != 'latest' ]]; then
85-
case $_family in
86-
debian|ubuntu)
87-
# Need the full packaging version for deb.
88-
# As an example, for openvox-agent 8.14.0 on ubuntu 24.04:
89-
# 8.14.0-1+ubuntu24.04
90-
if [[ "${_version}" =~ - ]]; then
91-
# Caller's version already has a '-' seprator, so we
92-
# should respect that they have probably supplied some
93-
# full package version string.
94-
_package_version="${_version}"
95-
else
96-
_package_version="${_version}-1+${_family}${_full_version}"
97-
fi
98-
;;
99-
*)
100-
# rpm packages should be fine so long as the shorter form
101-
# matches uniquely.
102-
_package_version="${_version}"
103-
;;
104-
esac
105-
fi
106-
107-
install_package openvox-agent "${_package_version}" "${_family}"
108-
}
109-
11077
# Get platform information
11178
set_platform
11279
# Set collection release package url based on platform
@@ -119,4 +86,4 @@ download "${package_url}" "${local_release_package}"
11986
# packages from the collection using the platform package manager.
12087
install_release_package "${local_release_package}" "${package_type}"
12188
# Use the platform package manager to install openvox-agent
122-
install_openvox_agent "${version}" "${family}" "${full_version}"
89+
install_package "${package}" "${version}" "${family}" "${full_version}"

0 commit comments

Comments
 (0)