@@ -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
239240set_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.
266267get_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() {
309310install_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 * )
0 commit comments