Skip to content

ENT-12600: functions: documented & refactored script - #1960

Merged
larsewi merged 3 commits into
cfengine:masterfrom
larsewi:functions
Oct 3, 2025
Merged

ENT-12600: functions: documented & refactored script#1960
larsewi merged 3 commits into
cfengine:masterfrom
larsewi:functions

Conversation

@larsewi

@larsewi larsewi commented Oct 1, 2025

Copy link
Copy Markdown
Contributor
  • functions: replaced echo's with logging functions
  • functions: prepend basename to log_info
  • functions: documented script

Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Also use lowercase `"info"` prefix, similar to `log_debug` and
`log_error`.

Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
@larsewi

larsewi commented Oct 1, 2025

Copy link
Copy Markdown
Contributor Author

@cf-bottom Jenkins please :)

@cfengine cfengine deleted a comment from cf-bottom Oct 1, 2025
@larsewi
larsewi marked this pull request as ready for review October 1, 2025 18:08
@larsewi
larsewi requested a review from craigcomstock October 1, 2025 18:08
@cfengine cfengine deleted a comment from cf-bottom Oct 2, 2025
@cf-bottom

Copy link
Copy Markdown

Comment thread build-scripts/functions
#

#
# NOTE: In this file, do not use $(), as Solaris /bin/sh will choke on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... you have changed `` to $() above for sourcing functions. Is this warning about Solaris not an issue now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears not to be an issue anymore

Comment thread build-scripts/functions
# Args:
# $1 - Package name pattern (regex)
uninstall_debs() {
PKGS=$(dpkg -l | tail -n+6 | awk '{print $2}' | grep "^$1" || true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh damn. this looks fragile ;) tail -n+6 PLUS SIX? ;) I think there is probably a warning on dpkg output to stderr saying the output is not stable and not an interface. Maybe we should refactor this if we actually use it somewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do use it. Let's create a followup ticket

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See ENT-13251

Comment thread build-scripts/functions
uninstall_freebsd_pkgs() {
PKGS=$(pkg_info | awk '{print $1}' | grep "^$1" || true)
if [ -n "$PKGS" ]; then
retry_wrapper sudo pkg_delete "$PKGS"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why the retry_wrapper here and not elsewhere? I wouldn't think we should "retry" at all if it fails honestly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No clue ¯\_(ツ)_/¯

Comment thread build-scripts/functions Outdated
# Args:
# $@ - Command names to search for (tries each in order)
# Returns:
# 0 and prints path if found, 1 if not found

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add that it prints the first path found and stops searching the other options provided as arguments.

Comment thread build-scripts/functions
# Path to created directory
# Note:
# Fallback implementation for systems without mktemp command
func_mktemp() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like with mktempdir below we would not need this func_mktemp()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mktempdir uses func_mktemp

Comment thread build-scripts/functions
# Args:
# $1 - File to hash (optional, uses stdin if omitted)
# Returns:
# SHA-256 hash as hexadecimal string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to mention this is present to workaround different platforms.

Maybe we should move all of these sorts of things into a separate include named "platform_compat" or similar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says ... in a portable way in the start of the doc string. Can change it to "platform independent way" maybe

Ticket: ENT-12600
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
@larsewi
larsewi merged commit 7a66d1b into cfengine:master Oct 3, 2025
2 of 3 checks passed
@larsewi
larsewi deleted the functions branch April 27, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants