ENT-12600: functions: documented & refactored script - #1960
Conversation
larsewi
commented
Oct 1, 2025
- 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>
|
@cf-bottom Jenkins please :) |
|
Alright, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/12788/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-12788/ |
| # | ||
|
|
||
| # | ||
| # NOTE: In this file, do not use $(), as Solaris /bin/sh will choke on |
There was a problem hiding this comment.
So... you have changed `` to $() above for sourcing functions. Is this warning about Solaris not an issue now?
There was a problem hiding this comment.
It appears not to be an issue anymore
| # Args: | ||
| # $1 - Package name pattern (regex) | ||
| uninstall_debs() { | ||
| PKGS=$(dpkg -l | tail -n+6 | awk '{print $2}' | grep "^$1" || true) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
We do use it. Let's create a followup ticket
| uninstall_freebsd_pkgs() { | ||
| PKGS=$(pkg_info | awk '{print $1}' | grep "^$1" || true) | ||
| if [ -n "$PKGS" ]; then | ||
| retry_wrapper sudo pkg_delete "$PKGS" |
There was a problem hiding this comment.
I wonder why the retry_wrapper here and not elsewhere? I wouldn't think we should "retry" at all if it fails honestly.
| # Args: | ||
| # $@ - Command names to search for (tries each in order) | ||
| # Returns: | ||
| # 0 and prints path if found, 1 if not found |
There was a problem hiding this comment.
Maybe add that it prints the first path found and stops searching the other options provided as arguments.
| # Path to created directory | ||
| # Note: | ||
| # Fallback implementation for systems without mktemp command | ||
| func_mktemp() { |
There was a problem hiding this comment.
seems like with mktempdir below we would not need this func_mktemp()
There was a problem hiding this comment.
mktempdir uses func_mktemp
| # Args: | ||
| # $1 - File to hash (optional, uses stdin if omitted) | ||
| # Returns: | ||
| # SHA-256 hash as hexadecimal string |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>