Skip to content

Commit 52841d5

Browse files
committed
(maint) Clarify difference between package version and os versions
...by prefixing the os related globals with 'os_'. Also changes set_platform() to set_platform_globals() and has it set os_family as well. Makes setting of the platform global variables little more linear, and simplifies a bit of the defensive set global calls in the common.sh.
1 parent 73d28a8 commit 52841d5

File tree

3 files changed

+72
-76
lines changed

3 files changed

+72
-76
lines changed

files/common.sh

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -171,80 +171,81 @@ translate_codename_to_version() {
171171
esac
172172
}
173173

174-
# Set platform, full_version and major_version variables by reaching
175-
# out to the puppetlabs-facts bash task as an executable.
176-
set_platform() {
177-
local facts="${installdir}/facts/tasks/bash.sh"
178-
if [ -e "${facts}" ]; then
179-
platform=$(bash "${facts}" platform)
180-
full_version=$(bash "${facts}" release)
181-
if [[ "${full_version}" == "n/a" ]]; then
182-
# Hit the facts json with blunt objects until the codename value
183-
# pops out...
184-
codename=$(bash "${facts}" | grep '"codename"' | cut -d':' -f2 | grep -oE '[^ "]+')
185-
full_version=$(translate_codename_to_version "${codename}")
186-
fi
187-
major_version=${full_version%%.*}
188-
else
189-
fail "Unable to find the puppetlabs-facts bash task to determine platform at '${facts}'."
190-
fi
191-
export platform # quiets shellcheck SC2034
192-
assigned 'platform'
193-
export full_version # quiets shellcheck SC2034
194-
assigned 'full_version'
195-
export major_version # quiets shellcheck SC2034
196-
assigned 'major_version'
197-
}
198-
199-
# Set the OS family variable based on the platform.
200-
set_family() {
174+
# Set the $os_family variable based on the platform.
175+
set_os_family() {
201176
local _platform="${1:-${platform}}"
202177

203-
if [[ -z "${_platform}" ]]; then
204-
set_platform
205-
_platform="${platform}"
206-
fi
207-
208178
# Downcase the platform so as to avoid case issues.
209179
case ${_platform,,} in
210180
amazon)
211-
family='amazon'
181+
os_family='amazon'
212182
;;
213183
rhel|redhat|centos|scientific|oraclelinux|rocky|almalinux)
214-
family='el'
184+
os_family='el'
215185
;;
216186
fedora)
217-
family='fedora'
187+
os_family='fedora'
218188
;;
219189
sles|suse)
220-
family='sles'
190+
os_family='sles'
221191
;;
222192
debian)
223-
family='debian'
193+
os_family='debian'
224194
;;
225195
ubuntu)
226-
family='ubuntu'
196+
os_family='ubuntu'
227197
;;
228198
*)
229199
fail "Unhandled platform: '${_platform}'"
230200
;;
231201
esac
232-
export family # quiets shellcheck SC2034
233-
assigned 'family'
202+
export os_family # quiets shellcheck SC2034
203+
assigned 'os_family'
204+
}
205+
206+
# Read local OS facts by reaching out to the puppetlabs-facts bash
207+
# task as an executable, then set these globals:
208+
# $platform
209+
# $os_full_version
210+
# $os_major_version
211+
# $os_family
212+
set_platform_globals() {
213+
local facts="${installdir}/facts/tasks/bash.sh"
214+
if [ -e "${facts}" ]; then
215+
platform=$(bash "${facts}" platform)
216+
os_full_version=$(bash "${facts}" release)
217+
if [[ "${os_full_version}" == "n/a" ]]; then
218+
# Hit the facts json with blunt objects until the codename value
219+
# pops out...
220+
codename=$(bash "${facts}" | grep '"codename"' | cut -d':' -f2 | grep -oE '[^ "]+')
221+
os_full_version=$(translate_codename_to_version "${codename}")
222+
fi
223+
os_major_version=${os_full_version%%.*}
224+
else
225+
fail "Unable to find the puppetlabs-facts bash task to determine platform at '${facts}'."
226+
fi
227+
export platform # quiets shellcheck SC2034
228+
assigned 'platform'
229+
export os_full_version # quiets shellcheck SC2034
230+
assigned 'os_full_version'
231+
export os_major_version # quiets shellcheck SC2034
232+
assigned 'os_major_version'
233+
234+
set_os_family "${platform}"
234235
}
235236

236-
# Based on platform family set:
237+
# Based on platform os_family set:
237238
# package_type - rpm or deb or...
238239
# package_file_suffix - the file extension for the release package name
239240
set_package_type() {
240-
local _family="${1:-${family}}"
241+
local _os_family="${1:-${os_family}}"
241242

242-
if [[ -z "${_family}" ]]; then
243-
set_family "${platform}"
244-
_family="${family}"
243+
if [[ -z "${_os_family}" ]]; then
244+
set_platform_globals
245+
_os_family="${os_family}"
245246
fi
246247

247-
case $_family in
248+
case $_os_family in
248249
amazon|fedora|el|sles)
249250
package_type='rpm'
250251
package_file_suffix='noarch.rpm'
@@ -265,8 +266,8 @@ set_package_type() {
265266
# since this could be called multiple times for different packages.
266267
get_deb_package_version() {
267268
local _version="$1"
268-
local _family="${2:-${family}}"
269-
local _full_version="${3-${full_version}}"
269+
local _os_family="${2:-${os_family}}"
270+
local _os_full_version="${3-${os_full_version}}"
270271

271272
# Need the full packaging version for deb.
272273
# As an example, for openvox-agent 8.14.0 on ubuntu 24.04:
@@ -277,7 +278,7 @@ get_deb_package_version() {
277278
# full package version string.
278279
_package_version="${_version}"
279280
else
280-
_package_version="${_version}-1+${_family}${_full_version}"
281+
_package_version="${_version}-1+${_os_family}${_os_full_version}"
281282
fi
282283

283284
echo -n "${_package_version}"
@@ -309,25 +310,22 @@ install_package_file() {
309310
install_package() {
310311
local _package="$1"
311312
local _version="$2"
312-
local _family="${3:-${family}}"
313-
local _full_version="${4:-${full_version}}"
313+
local _os_family="${3:-${os_family}}"
314+
local _os_full_version="${4:-${os_full_version}}"
314315

315316
info "Installing ${_package} ${_version}"
316317

317318
local _package_and_version
318319
if [[ -n "${_version}" ]] && [[ "${_version}" != 'latest' ]]; then
319-
if [[ -z "${_family}" ]]; then
320-
set_family "${platform}"
321-
_family="${family}"
320+
if [[ -z "${_os_family}" ]] || [[ -z "${_os_full_version}" ]]; then
321+
set_platform_globals
322+
_os_family="${os_family}"
323+
_os_full_version="${os_full_version}"
322324
fi
323-
case $_family in
325+
case $_os_family in
324326
debian|ubuntu)
325-
if [[ -z "${_full_version}" ]]; then
326-
set_platform
327-
_full_version="${full_version}"
328-
fi
329327
local _deb_package_version
330-
_deb_package_version=$(get_deb_package_version "${_version}" "${_family}" "${_full_version}")
328+
_deb_package_version=$(get_deb_package_version "${_version}" "${_os_family}" "${_os_full_version}")
331329
_package_and_version="${_package}=${deb_package_version}"
332330
;;
333331
*)

tasks/install_build_artifact_linux.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,21 @@ set_package_url() {
6262
local _package="$2"
6363
local _version="$3"
6464

65-
set_family "${_platform}"
66-
set_package_type "${family}"
67-
set_architecture "${family}"
65+
set_package_type "${os_family}"
66+
set_architecture "${os_family}"
6867

6968
case "${package_type}" in
7069
rpm)
7170
# Account for a fedora naming quirk in the build artifacts.
72-
if [[ "${family}" == "fedora" ]]; then
73-
_family="fc"
71+
if [[ "${os_family}" == "fedora" ]]; then
72+
_os_family="fc"
7473
else
75-
_family="${family}"
74+
_os_family="${os_family}"
7675
fi
77-
package_name="${_package}-${_version}-1.${_family}${major_version}.${cpu_arch}.${package_type}"
76+
package_name="${_package}-${_version}-1.${_os_family}${os_major_version}.${cpu_arch}.${package_type}"
7877
;;
7978
deb)
80-
package_name="${_package}_${_version}-1%2B${family}${full_version}_${cpu_arch}.${package_type}"
79+
package_name="${_package}_${_version}-1%2B${os_family}${os_full_version}_${cpu_arch}.${package_type}"
8180
;;
8281
*)
8382
fail "Unhandled package type: '${package_type}'"
@@ -90,7 +89,7 @@ set_package_url() {
9089
}
9190

9291
# Get platform information
93-
set_platform
92+
set_platform_globals
9493
# Set url to build artifacts package based on platform
9594
set_package_url "${platform}" "${package}" "${version}"
9695
# Download the build artifacts package to the tempdir.

tasks/install_linux.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@ set_repository() {
4141
set_collection_url() {
4242
local _platform="$1"
4343

44-
set_family "${_platform}"
45-
set_repository "${family}"
46-
set_package_type "${family}"
44+
set_repository "${os_family}"
45+
set_package_type "${os_family}"
4746

4847
case "${package_type}" in
4948
rpm)
50-
package_name="${collection}-release-${family}-${major_version}.${package_file_suffix}"
49+
package_name="${collection}-release-${os_family}-${os_major_version}.${package_file_suffix}"
5150
;;
5251
deb)
53-
package_name="${collection}-release-${family}${full_version}.${package_file_suffix}"
52+
package_name="${collection}-release-${os_family}${os_full_version}.${package_file_suffix}"
5453
;;
5554
*)
5655
fail "Unhandled package type: '${package_type}'"
@@ -75,7 +74,7 @@ install_release_package() {
7574
}
7675

7776
# Get platform information
78-
set_platform
77+
set_platform_globals
7978
# Set collection release package url based on platform
8079
set_collection_url "${platform}"
8180
# Download the release package to tempdir
@@ -86,4 +85,4 @@ download "${package_url}" "${local_release_package}"
8685
# packages from the collection using the platform package manager.
8786
install_release_package "${local_release_package}" "${package_type}"
8887
# Use the platform package manager to install openvox-agent
89-
install_package "${package}" "${version}" "${family}" "${full_version}"
88+
install_package "${package}" "${version}" "${os_family}" "${os_full_version}"

0 commit comments

Comments
 (0)