Skip to content

Commit 37bfc92

Browse files
authored
Merge pull request #5 from jpartlow/install-specific-version
(tasks,gha) Implement version parameter for install task
2 parents f4d9177 + 867e7ac commit 37bfc92

File tree

4 files changed

+109
-12
lines changed

4 files changed

+109
-12
lines changed

.github/workflows/pr_testing.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,33 @@ jobs:
7272
PT_yum_source: "https://yum.overlookinfratech.com"
7373
run: ./openvox_bootstrap/tasks/install_linux.sh
7474
- name: Verify openvox-agent is installed
75-
run: /opt/puppetlabs/bin/puppet --version | grep -E '[0-9]+\.[0-9]+'
75+
run: /opt/puppetlabs/bin/puppet --version | grep -E '8\.[0-9]+'
76+
77+
test-install-version:
78+
strategy:
79+
matrix:
80+
image:
81+
- rockylinux:9
82+
- fedora:41
83+
- debian:12
84+
- ubuntu:24.04
85+
# Need to pull in the repo GPG keys for sles
86+
# - registry.suse.com/suse/sle15:15.6
87+
needs: shellcheck
88+
runs-on: ubuntu-latest
89+
container: ${{ matrix.image }}
90+
steps:
91+
- uses: actions/checkout@v4
92+
with:
93+
path: openvox_bootstrap
94+
- id: prep
95+
uses: ./openvox_bootstrap/.github/actions/container_task_prep
96+
- name: Run openvox-agent install task manually
97+
env:
98+
PT__installdir: ${{ github.workspace }}
99+
PT_version: "8.14.0"
100+
PT_apt_source: "https://apt.overlookinfratech.com"
101+
PT_yum_source: "https://yum.overlookinfratech.com"
102+
run: ./openvox_bootstrap/tasks/install_linux.sh
103+
- name: Verify openvox-agent is installed
104+
run: /opt/puppetlabs/bin/puppet --version | grep '8.14.0'

files/common.sh

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ set_platform() {
9595

9696
# Set the OS family variable based on the platform.
9797
set_family() {
98-
local _platform="$1"
98+
local _platform="${1:-${platform}}"
99+
100+
if [[ -z "${_platform}" ]]; then
101+
set_platform
102+
_platform="${platform}"
103+
fi
99104

100105
case $_platform in
101106
Amazon)
@@ -128,7 +133,12 @@ set_family() {
128133
# package_type - rpm or deb or...
129134
# package_file_suffix - the file extension for the release package name
130135
set_package_type() {
131-
local _family="$1"
136+
local _family="${1:-${family}}"
137+
138+
if [[ -z "${_family}" ]]; then
139+
set_family "${platform}"
140+
_family="${family}"
141+
fi
132142

133143
case $_family in
134144
amazon|fedora|el|sles)
@@ -166,21 +176,42 @@ install_package_file() {
166176
esac
167177
}
168178

169-
# TODO add support for the version parameter.
179+
# Install a package using the system package manager.
170180
install_package() {
171181
local _package="$1"
182+
local _version="$2"
183+
local _family="${3:-${family}}"
184+
185+
info "Installing ${_package} ${_version}"
186+
187+
local _package_and_version
188+
if [[ -n "${_version}" ]] && [[ "${_version}" != 'latest' ]]; then
189+
if [[ -z "${_family}" ]]; then
190+
set_family "${platform}"
191+
_family="${family}"
192+
fi
193+
case $_family in
194+
debian|ubuntu)
195+
_package_and_version="${_package}=${_version}"
196+
;;
197+
*)
198+
_package_and_version="${_package}-${_version}"
199+
;;
200+
esac
201+
else
202+
_package_and_version="${_package}"
203+
fi
172204

173-
info "Installing ${_package}"
174205
if exists 'dnf'; then
175-
exec_and_capture dnf install -y "$_package"
206+
exec_and_capture dnf install -y "${_package_and_version}"
176207
elif exists 'yum'; then
177-
exec_and_capture yum install -y "$_package"
208+
exec_and_capture yum install -y "${_package_and_version}"
178209
elif exists 'zypper'; then
179-
exec_and_capture zypper install -y "$_package"
210+
exec_and_capture zypper install -y "${_package_and_version}"
180211
elif exists 'apt'; then
181-
exec_and_capture apt install -y "$_package"
212+
exec_and_capture apt install -y "${_package_and_version}"
182213
elif exists 'apt-get'; then
183-
exec_and_capture apt-get install -y "$_package"
214+
exec_and_capture apt-get install -y "${_package_and_version}"
184215
else
185216
fail "Unable to install ${_package}. Neither dnf, yum, zypper, apt nor apt-get are installed."
186217
fi

tasks/install.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"description": "Installs the openvox-agent package.",
33
"parameters": {
44
"version": {
5-
"description": "TODO The version of the openvox-agent package to install. Defaults to latest.",
5+
"description": "The version of the openvox-agent package to install. Defaults to latest.",
66
"type": "Optional[String]"
77
},
88
"collection": {

tasks/install_linux.sh

Lines changed: 38 additions & 1 deletion
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+
version=${PT_version:-'latest'}
10+
# shellcheck disable=SC2154
911
collection=${PT_collection:-'openvox8'}
1012
# shellcheck disable=SC2154
1113
yum_source=${PT_yum_source:-'https://yum.overlookinfratech.com'}
@@ -70,6 +72,41 @@ install_release_package() {
7072
fi
7173
}
7274

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+
73110
# Get platform information
74111
set_platform
75112
# Set collection release package url based on platform
@@ -82,4 +119,4 @@ download "${package_url}" "${local_release_package}"
82119
# packages from the collection using the platform package manager.
83120
install_release_package "${local_release_package}" "${package_type}"
84121
# Use the platform package manager to install openvox-agent
85-
install_package 'openvox-agent'
122+
install_openvox_agent "${version}" "${family}" "${full_version}"

0 commit comments

Comments
 (0)