2024-02-12 09:55:34 +01:00
|
|
|
#!/bin/bash
|
2024-02-12 09:36:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Initiate variables
|
|
|
|
retry_count=0
|
2024-02-12 12:56:44 +01:00
|
|
|
max_retries=5
|
|
|
|
retry_delay=30
|
2024-02-12 09:36:45 +01:00
|
|
|
success=0
|
|
|
|
|
|
|
|
|
|
|
|
# Retry until success or retry count reaches max_retries
|
|
|
|
while [[ $retry_count -le $max_retries && $success -ne 1 ]]; do
|
2024-02-13 10:25:10 +01:00
|
|
|
cmd_res="$(checkupdates 2>&1)"
|
2024-02-12 09:36:45 +01:00
|
|
|
case $? in
|
|
|
|
# Update(s) available
|
|
|
|
0)
|
|
|
|
success=1
|
2024-02-13 10:25:10 +01:00
|
|
|
output=$(echo "$cmd_res" | wc -l)
|
|
|
|
tooltip="$(echo "$cmd_res" | sed -z 's/\n/\\n/g' | sed 's/\\n$//')"
|
2024-02-12 09:36:45 +01:00
|
|
|
class="update-available"
|
|
|
|
;;
|
|
|
|
|
|
|
|
# No update available
|
|
|
|
2)
|
|
|
|
success=1
|
|
|
|
output=0
|
2024-02-13 10:25:10 +01:00
|
|
|
tooltip="No update available."
|
2024-02-12 09:36:45 +01:00
|
|
|
class="no-update"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
sleep $retry_delay
|
|
|
|
retry_count+=1
|
|
|
|
output=""
|
2024-02-13 10:25:10 +01:00
|
|
|
tooltip="$(echo "$cmd_res" | sed -z 's/\n/\\n/g' | sed 's/\\n$//')"
|
2024-02-12 09:36:45 +01:00
|
|
|
class="error"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2024-02-15 15:50:58 +01:00
|
|
|
# Show time of check
|
|
|
|
time="$(date '+%H:%M:%S')"
|
2024-02-21 07:56:59 +01:00
|
|
|
tooltip="$tooltip\n\nLatest check: $time"
|
2024-02-15 15:50:58 +01:00
|
|
|
|
|
|
|
|
2024-02-12 09:36:45 +01:00
|
|
|
cat << EOF
|
2024-02-13 10:25:10 +01:00
|
|
|
{"text": "$output", "alt": "$class", "tooltip": "$tooltip", "class": "$class"}
|
2024-02-12 09:36:45 +01:00
|
|
|
EOF
|