mirror of
https://github.com/mag37/dockcheck.git
synced 2026-03-08 01:42:44 +01:00
style changes for output
This commit is contained in:
parent
88e1f6646c
commit
9daee4a523
1 changed files with 35 additions and 70 deletions
101
podcheck.sh
101
podcheck.sh
|
|
@ -14,7 +14,6 @@ ScriptWorkDir="$(dirname "$ScriptPath")"
|
||||||
Github="https://github.com/sudo-kraken/podcheck"
|
Github="https://github.com/sudo-kraken/podcheck"
|
||||||
RawUrl="https://raw.githubusercontent.com/sudo-kraken/podcheck/main/podcheck.sh"
|
RawUrl="https://raw.githubusercontent.com/sudo-kraken/podcheck/main/podcheck.sh"
|
||||||
|
|
||||||
# Add near the beginning
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
# Temporarily disable failglob for cleanup
|
# Temporarily disable failglob for cleanup
|
||||||
shopt -u failglob
|
shopt -u failglob
|
||||||
|
|
@ -78,7 +77,7 @@ c_blue="\033[0;34m"
|
||||||
c_teal="\033[0;36m"
|
c_teal="\033[0;36m"
|
||||||
c_reset="\033[0m"
|
c_reset="\033[0m"
|
||||||
|
|
||||||
# Initialize variables first
|
# Initialise variables first
|
||||||
AutoUp="no"
|
AutoUp="no"
|
||||||
AutoPrune=""
|
AutoPrune=""
|
||||||
Stopped=""
|
Stopped=""
|
||||||
|
|
@ -219,11 +218,10 @@ progress_bar() {
|
||||||
((Left=50-Complete))
|
((Left=50-Complete))
|
||||||
BarComplete=$(printf "%${Complete}s" | tr " " "#")
|
BarComplete=$(printf "%${Complete}s" | tr " " "#")
|
||||||
BarLeft=$(printf "%${Left}s" | tr " " "-")
|
BarLeft=$(printf "%${Left}s" | tr " " "-")
|
||||||
if [[ "$QueTotal" != "$QueCurrent" ]]; then
|
# Remove the duplicate "Processing container" output
|
||||||
printf "\r[%s%s] %s/%s " "$BarComplete" "$BarLeft" "$QueCurrent" "$QueTotal"
|
printf "\r[%s%s] %s/%s %bProcessing container: %s%b\n" \
|
||||||
else
|
"$BarComplete" "$BarLeft" "$QueCurrent" "$QueTotal" \
|
||||||
printf "\r[%b%s%b] %s/%s \n" "$c_teal" "$BarComplete" "$c_reset" "$QueCurrent" "$QueTotal"
|
"$c_blue" "$container" "$c_reset"
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_out=$(command -v timeout 2>/dev/null || echo "")
|
t_out=$(command -v timeout 2>/dev/null || echo "")
|
||||||
|
|
@ -354,13 +352,12 @@ ContCount=$(podman ps $Stopped --filter "name=$SearchName" --format '{{.Names}}'
|
||||||
RegCheckQue=0
|
RegCheckQue=0
|
||||||
start_time=$(date +%s)
|
start_time=$(date +%s)
|
||||||
|
|
||||||
echo "Starting container update check"
|
printf "\n%bStarting container update check%b\n" "$c_blue" "$c_reset"
|
||||||
|
|
||||||
process_container() {
|
process_container() {
|
||||||
local container="$1"
|
local container="$1"
|
||||||
((RegCheckQue++))
|
((RegCheckQue++))
|
||||||
progress_bar "$RegCheckQue" "$ContCount"
|
progress_bar "$RegCheckQue" "$ContCount"
|
||||||
>&2 echo "Processing container: $container"
|
|
||||||
|
|
||||||
for e in "${Excludes[@]}"; do
|
for e in "${Excludes[@]}"; do
|
||||||
if [[ "$container" == "$e" ]]; then
|
if [[ "$container" == "$e" ]]; then
|
||||||
|
|
@ -478,70 +475,36 @@ if [[ -n "${GotUpdates[*]}" ]]; then
|
||||||
ContRestartStack=$($jqbin -r '."sudo-kraken.podcheck.restart-stack"' <<< "$ContLabels")
|
ContRestartStack=$($jqbin -r '."sudo-kraken.podcheck.restart-stack"' <<< "$ContLabels")
|
||||||
[ "$ContRestartStack" == "null" ] && ContRestartStack=""
|
[ "$ContRestartStack" == "null" ] && ContRestartStack=""
|
||||||
|
|
||||||
|
# Add spacing and colors to systemd unit detection
|
||||||
if [ -z "$ContPath" ]; then
|
if [ -z "$ContPath" ]; then
|
||||||
echo "Checking systemd units for container: $i"
|
printf "\n%bChecking systemd units for container: %s%b\n\n" \
|
||||||
|
"$c_teal" "$i" "$c_reset"
|
||||||
|
|
||||||
# Get the PODMAN_SYSTEMD_UNIT label first
|
unit=$(podman inspect "$i" --format '{{.Config.Labels.PODMAN_SYSTEMD_UNIT}}')
|
||||||
unit=$(podman inspect "$i" --format '{{.Config.Labels.PODMAN_SYSTEMD_UNIT}}')
|
if [ -n "$unit" ]; then
|
||||||
if [ -n "$unit" ]; then
|
printf "%bDetected Quadlet-managed container: %s (unit: %s)%b\n\n" \
|
||||||
echo "Found systemd unit from container label: $unit"
|
"$c_green" "$i" "$unit" "$c_reset"
|
||||||
else
|
|
||||||
# First check if we can find the quadlet service directly
|
|
||||||
all_services=$(systemctl --user list-units --type=service --all --no-legend | awk '{print $1}')
|
|
||||||
|
|
||||||
# Look for both the container's quadlet file and service
|
printf "%bPulling new image...%b\n\n" "$c_teal" "$c_reset"
|
||||||
while read -r service; do
|
|
||||||
# Get the actual container name from the service unit
|
if podman pull "$ContImage"; then
|
||||||
if container_info=$(systemctl --user show "$service" -p ExecStart 2>/dev/null); then
|
printf "\n%bSuccessfully pulled new image%b\n\n" "$c_green" "$c_reset"
|
||||||
# Check both container file name and container name in ExecStart
|
else
|
||||||
if [[ "$container_info" =~ $i ]] || \
|
printf "\n%bFailed to pull image for %s%b\n\n" "$c_red" "$i" "$c_reset"
|
||||||
[[ "$container_info" =~ /containers/[^[:space:]]*/\.container ]]; then
|
continue
|
||||||
if container_path=$(echo "$container_info" | grep -o '/containers/[^"]*\.container' | head -n1); then
|
|
||||||
container_name=$(basename "$container_path" .container)
|
|
||||||
# Match either the container name or the service name
|
|
||||||
if [[ "$container_name" == "$i" ]] || [[ "$service" =~ ^${i%.*}\.service$ ]]; then
|
|
||||||
unit="$service"
|
|
||||||
echo "Found matching quadlet service: $unit (container: $container_name)"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done <<< "$all_services"
|
printf "%bAttempting to restart unit...%b\n\n" "$c_teal" "$c_reset"
|
||||||
|
|
||||||
# If still no match found, try the direct service name
|
if timeout 60 systemctl --user restart "$unit"; then
|
||||||
if [ -z "${unit:-}" ]; then
|
printf "\n%bQuadlet container %s updated and restarted (user scope)%b\n\n" \
|
||||||
if systemctl --user status "$i.service" &>/dev/null; then
|
"$c_green" "$i" "$c_reset"
|
||||||
unit="$i.service"
|
else
|
||||||
echo "Found direct unit match: $unit"
|
printf "\n%bFailed to restart unit %s%b\n" "$c_red" "$unit" "$c_reset"
|
||||||
|
systemctl --user status "$unit"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
continue
|
||||||
|
fi
|
||||||
if [ -n "${unit:-}" ]; then
|
|
||||||
echo "Detected Quadlet-managed container: $i (matched unit: $unit)"
|
|
||||||
echo "Pulling new image..."
|
|
||||||
|
|
||||||
if podman pull "$ContImage"; then
|
|
||||||
echo "Successfully pulled new image"
|
|
||||||
else
|
|
||||||
echo "Failed to pull image for $i"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
echo "Attempting to restart unit..."
|
|
||||||
|
|
||||||
if timeout 60 systemctl --user restart "$unit"; then
|
|
||||||
echo "Quadlet container $i updated and restarted (user scope)"
|
|
||||||
else
|
|
||||||
echo "Failed to restart unit $unit"
|
|
||||||
systemctl --user status "$unit"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
printf "\n%b%s%b has no systemd unit found; %bskipping%b\n\n" "$c_yellow" "$i" "$c_reset" "$c_yellow" "$c_reset"
|
|
||||||
fi
|
|
||||||
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
cd "$ContPath" || { echo "Path error - skipping $i"; continue; }
|
cd "$ContPath" || { echo "Path error - skipping $i"; continue; }
|
||||||
if [[ $ContConfigFile = /* ]]; then
|
if [[ $ContConfigFile = /* ]]; then
|
||||||
CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s " "$conf"; done)
|
CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s " "$conf"; done)
|
||||||
|
|
@ -567,9 +530,11 @@ fi
|
||||||
if [[ -z "$AutoPrune" ]] && [[ "$AutoUp" == "no" ]]; then
|
if [[ -z "$AutoPrune" ]] && [[ "$AutoUp" == "no" ]]; then
|
||||||
read -r -p "Would you like to prune dangling images? y/[n]: " AutoPrune
|
read -r -p "Would you like to prune dangling images? y/[n]: " AutoPrune
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$AutoPrune" =~ [yY] ]] || [[ "$AutoUp" == "yes" ]]; then
|
if [[ "$AutoPrune" =~ [yY] ]] || [[ "$AutoUp" == "yes" ]]; then
|
||||||
echo "Cleaning up failed update images..."
|
printf "\n%bCleaning up failed update images...%b\n\n" "$c_teal" "$c_reset"
|
||||||
podman image prune -f
|
podman image prune -f
|
||||||
|
printf "\n"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
printf "\nNo updates installed, exiting.\n"
|
printf "\nNo updates installed, exiting.\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue