29 lines
847 B
Bash
Executable File
29 lines
847 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Retrieve JSON output from alhp.utils.
|
|
readonly ALHP_OUTPUT=$(alhp.utils -j)
|
|
|
|
# Extract "total" as a string and read "packages" into a Bash array.
|
|
readonly total=$(echo "$ALHP_OUTPUT" | jq -r '.total | tostring')
|
|
readarray -t packages < <(echo "$ALHP_OUTPUT" | jq -r '.packages[]?')
|
|
|
|
# Initialize default tooltip and class.
|
|
tooltip=''
|
|
class='good'
|
|
|
|
# Use arithmetic evaluation to check if total is greater than 0.
|
|
if (( total > 0 )); then
|
|
class='bad'
|
|
fi
|
|
|
|
# If there are any packages, join them with newline as separator.
|
|
if (( ${#packages[@]} > 0 )); then
|
|
tooltip=$(IFS=$'\n'; echo "${packages[*]}")
|
|
else
|
|
tooltip="All good"
|
|
fi
|
|
|
|
# Generate compact JSON output (all in one line) with jq.
|
|
jq -nc --arg text "$total" --arg class "$class" --arg tooltip "$tooltip" \
|
|
'{text: $text, class: $class, tooltip: $tooltip}'
|