2023-02-15 13:16:31 +01:00
|
|
|
#!/usr/bin/env bash
|
2024-11-25 15:20:34 +01:00
|
|
|
VERSION="v0.5.7"
|
2024-11-25 14:05:30 +01:00
|
|
|
# ChangeNotes: Rewrite of dependency installer. jq can now be installed via package manager or static binary.
|
2024-11-16 18:24:58 +00:00
|
|
|
Github="https://github.com/sudo-kraken/podcheck"
|
|
|
|
|
RawUrl="https://raw.githubusercontent.com/sudo-kraken/podcheck/main/podcheck.sh"
|
2023-02-02 22:02:41 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Variables for self-updating
|
2023-03-04 19:56:26 +01:00
|
|
|
ScriptArgs=( "$@" )
|
|
|
|
|
ScriptPath="$(readlink -f "$0")"
|
|
|
|
|
ScriptWorkDir="$(dirname "$ScriptPath")"
|
2023-01-18 11:50:00 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Check if there's a new release of the script
|
|
|
|
|
LatestRelease="$(curl -s -r 0-100 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
|
|
|
|
|
LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
|
2023-03-05 20:44:05 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Help Function
|
2023-01-19 12:09:29 +01:00
|
|
|
Help() {
|
2024-11-16 18:24:58 +00:00
|
|
|
echo "Syntax: podcheck.sh [OPTION] [part of name to filter]"
|
|
|
|
|
echo "Example: podcheck.sh -y -d 10 -e nextcloud,heimdall"
|
2023-02-09 12:03:27 +00:00
|
|
|
echo
|
|
|
|
|
echo "Options:"
|
|
|
|
|
echo "-a|y Automatic updates, without interaction."
|
2024-11-16 18:24:58 +00:00
|
|
|
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age."
|
2023-12-23 20:47:23 +01:00
|
|
|
echo "-e X Exclude containers, separated by comma."
|
2024-11-16 18:24:58 +00:00
|
|
|
echo "-f Force pod restart after update."
|
2023-12-23 20:47:23 +01:00
|
|
|
echo "-h Print this Help."
|
2024-01-06 00:11:33 +01:00
|
|
|
echo "-i Inform - send a preconfigured notification."
|
2024-01-18 20:59:55 +01:00
|
|
|
echo "-l Only update if label is set. See readme."
|
2023-12-23 20:47:23 +01:00
|
|
|
echo "-m Monochrome mode, no printf color codes."
|
2024-11-16 18:24:58 +00:00
|
|
|
echo "-n No updates; only checking availability."
|
|
|
|
|
echo "-p Auto-prune dangling images after update."
|
|
|
|
|
echo "-r Allow updating images for podman run; won't update the container."
|
|
|
|
|
echo "-s Include stopped containers in the check."
|
2024-06-03 22:15:08 +02:00
|
|
|
echo "-t Set a timeout (in seconds) per container for registry checkups, 10 is default."
|
2024-02-02 20:52:01 +01:00
|
|
|
echo "-v Prints current version."
|
2024-09-28 14:22:09 +02:00
|
|
|
echo
|
|
|
|
|
echo "Project source: $Github"
|
2023-02-09 12:03:27 +00:00
|
|
|
}
|
2023-01-19 12:09:29 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Colors
|
2023-12-19 20:24:34 +01:00
|
|
|
c_red="\033[0;31m"
|
|
|
|
|
c_green="\033[0;32m"
|
|
|
|
|
c_yellow="\033[0;33m"
|
|
|
|
|
c_blue="\033[0;34m"
|
|
|
|
|
c_teal="\033[0;36m"
|
|
|
|
|
c_reset="\033[0m"
|
|
|
|
|
|
2024-06-03 22:49:14 +02:00
|
|
|
Timeout=10
|
2023-08-28 21:24:23 +02:00
|
|
|
Stopped=""
|
2024-06-03 22:15:08 +02:00
|
|
|
while getopts "aynpfrhlisvme:d:t:" options; do
|
2023-02-09 12:03:27 +00:00
|
|
|
case "${options}" in
|
2023-12-23 20:47:23 +01:00
|
|
|
a|y) AutoUp="yes" ;;
|
|
|
|
|
n) AutoUp="no" ;;
|
|
|
|
|
r) DRunUp="yes" ;;
|
|
|
|
|
p) AutoPrune="yes" ;;
|
2024-01-18 20:59:55 +01:00
|
|
|
l) OnlyLabel=true ;;
|
2024-11-16 18:24:58 +00:00
|
|
|
f) ForceRestartPods=true ;;
|
2024-02-01 20:19:04 +01:00
|
|
|
i) [ -s "$ScriptWorkDir"/notify.sh ] && { source "$ScriptWorkDir"/notify.sh ; Notify="yes" ; } ;;
|
2023-12-13 19:50:58 +01:00
|
|
|
e) Exclude=${OPTARG} ;;
|
2023-12-19 22:52:11 +01:00
|
|
|
m) declare c_{red,green,yellow,blue,teal,reset}="" ;;
|
2023-12-13 19:50:58 +01:00
|
|
|
s) Stopped="-a" ;;
|
2024-08-17 08:50:39 -04:00
|
|
|
t) Timeout="${OPTARG}" ;;
|
2024-02-02 20:52:01 +01:00
|
|
|
v) printf "%s\n" "$VERSION" ; exit 0 ;;
|
2023-12-13 19:50:58 +01:00
|
|
|
d) DaysOld=${OPTARG}
|
|
|
|
|
if ! [[ $DaysOld =~ ^[0-9]+$ ]] ; then { printf "Days -d argument given (%s) is not a number.\n" "${DaysOld}" ; exit 2 ; } ; fi ;;
|
|
|
|
|
h|*) Help ; exit 2 ;;
|
2023-02-09 12:03:27 +00:00
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
shift "$((OPTIND-1))"
|
2023-01-19 12:09:29 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Self-update functions
|
2023-03-04 19:56:26 +01:00
|
|
|
self_update_curl() {
|
|
|
|
|
cp "$ScriptPath" "$ScriptPath".bak
|
2024-11-16 18:24:58 +00:00
|
|
|
if [[ $(command -v curl) ]]; then
|
2024-08-17 08:50:39 -04:00
|
|
|
curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath"
|
2024-01-31 21:33:14 +01:00
|
|
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
2024-11-16 18:24:58 +00:00
|
|
|
exec "$ScriptPath" "${ScriptArgs[@]}" # Run the new script with old arguments
|
|
|
|
|
exit 1 # Exit the old instance
|
|
|
|
|
elif [[ $(command -v wget) ]]; then
|
2024-01-31 21:33:14 +01:00
|
|
|
wget $RawUrl -O "$ScriptPath" ; chmod +x "$ScriptPath"
|
|
|
|
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
2024-11-16 18:24:58 +00:00
|
|
|
exec "$ScriptPath" "${ScriptArgs[@]}" # Run the new script with old arguments
|
|
|
|
|
exit 1 # Exit the old instance
|
2023-03-04 19:56:26 +01:00
|
|
|
else
|
2024-04-22 21:02:13 +02:00
|
|
|
printf "curl/wget not available - download the update manually: %s \n" "$Github"
|
2023-03-04 19:56:26 +01:00
|
|
|
fi
|
|
|
|
|
}
|
2024-01-31 21:33:14 +01:00
|
|
|
|
|
|
|
|
self_update() {
|
|
|
|
|
cd "$ScriptWorkDir" || { printf "Path error, skipping update.\n" ; return ; }
|
2024-11-17 14:52:00 +00:00
|
|
|
if [[ $(command -v git) ]] && [[ "$(git ls-remote --get-url 2>/dev/null)" =~ .*"sudo-kraken/podcheck".* ]] ; then
|
2024-01-31 21:33:14 +01:00
|
|
|
printf "\n%s\n" "Pulling the latest version."
|
|
|
|
|
git pull --force || { printf "Git error, manually pull/clone.\n" ; return ; }
|
|
|
|
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
|
|
|
|
cd - || { printf "Path error.\n" ; return ; }
|
2024-11-16 18:24:58 +00:00
|
|
|
exec "$ScriptPath" "${ScriptArgs[@]}" # Run the new script with old arguments
|
|
|
|
|
exit 1 # Exit the old instance
|
2024-01-31 21:33:14 +01:00
|
|
|
else
|
2024-02-01 20:19:04 +01:00
|
|
|
cd - || { printf "Path error.\n" ; return ; }
|
2024-01-31 21:33:14 +01:00
|
|
|
self_update_curl
|
2023-03-04 19:56:26 +01:00
|
|
|
fi
|
2023-03-05 14:08:56 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Choose from list function
|
2023-03-05 14:08:56 +01:00
|
|
|
choosecontainers() {
|
|
|
|
|
while [[ -z "$ChoiceClean" ]]; do
|
|
|
|
|
read -r -p "Enter number(s) separated by comma, [a] for all - [q] to quit: " Choice
|
2024-08-17 08:50:39 -04:00
|
|
|
if [[ "$Choice" =~ [qQnN] ]] ; then
|
2023-03-05 14:08:56 +01:00
|
|
|
exit 0
|
|
|
|
|
elif [[ "$Choice" =~ [aAyY] ]] ; then
|
|
|
|
|
SelectedUpdates=( "${GotUpdates[@]}" )
|
|
|
|
|
ChoiceClean=${Choice//[,.:;]/ }
|
|
|
|
|
else
|
|
|
|
|
ChoiceClean=${Choice//[,.:;]/ }
|
|
|
|
|
for CC in $ChoiceClean ; do
|
2024-11-16 18:24:58 +00:00
|
|
|
if [[ "$CC" -lt 1 || "$CC" -gt $UpdCount ]] ; then
|
2023-03-05 14:08:56 +01:00
|
|
|
echo "Number not in list: $CC" ; unset ChoiceClean ; break 1
|
|
|
|
|
else
|
|
|
|
|
SelectedUpdates+=( "${GotUpdates[$CC-1]}" )
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
printf "\nUpdating containers:\n"
|
|
|
|
|
printf "%s\n" "${SelectedUpdates[@]}"
|
|
|
|
|
printf "\n"
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 19:50:58 +01:00
|
|
|
datecheck() {
|
2024-10-08 09:41:32 +02:00
|
|
|
ImageDate=$($regbin -v error image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
|
2024-01-28 20:08:17 +01:00
|
|
|
ImageAge=$(( ( $(date +%s) - $(date -d "$ImageDate" +%s) )/86400 ))
|
2024-02-01 20:19:04 +01:00
|
|
|
if [ "$ImageAge" -gt "$DaysOld" ] ; then
|
2023-12-13 19:50:58 +01:00
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-17 20:26:18 +01:00
|
|
|
progress_bar() {
|
|
|
|
|
QueCurrent="$1"
|
|
|
|
|
QueTotal="$2"
|
2024-02-01 20:19:04 +01:00
|
|
|
((Percent=100*QueCurrent/QueTotal))
|
2024-11-16 18:24:58 +00:00
|
|
|
((Complete=50*Percent/100)) # Change first number for width (50)
|
|
|
|
|
((Left=50-Complete)) # Change first number for width (50)
|
2024-01-17 20:26:18 +01:00
|
|
|
BarComplete=$(printf "%${Complete}s" | tr " " "#")
|
|
|
|
|
BarLeft=$(printf "%${Left}s" | tr " " "-")
|
2024-02-01 20:19:04 +01:00
|
|
|
[[ "$QueTotal" == "$QueCurrent" ]] || printf "\r[%s%s] %s/%s " "$BarComplete" "$BarLeft" "$QueCurrent" "$QueTotal"
|
|
|
|
|
[[ "$QueTotal" == "$QueCurrent" ]] && printf "\r[%b%s%b] %s/%s \n" "$c_teal" "$BarComplete" "$c_reset" "$QueCurrent" "$QueTotal"
|
2024-01-17 20:26:18 +01:00
|
|
|
}
|
2023-12-13 19:50:58 +01:00
|
|
|
|
2024-11-25 14:05:30 +01:00
|
|
|
# Static binary downloader for dependencies
|
|
|
|
|
binary_downloader() {
|
|
|
|
|
BinaryName="$1"
|
|
|
|
|
BinaryUrl="$2"
|
|
|
|
|
case "$(uname --machine)" in
|
|
|
|
|
x86_64|amd64) architecture="amd64" ;;
|
|
|
|
|
arm64|aarch64) architecture="arm64";;
|
|
|
|
|
*) printf "\n%bArchitecture not supported, exiting.%b\n" "$c_red" "$c_reset" ; exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
GetUrl="${BinaryUrl/TEMP/"$architecture"}"
|
|
|
|
|
if [[ $(command -v curl) ]]; then curl -L $GetUrl > "$ScriptWorkDir/$BinaryName" ;
|
|
|
|
|
elif [[ $(command -v wget) ]]; then wget $GetUrl -O "$ScriptWorkDir/$BinaryName" ;
|
|
|
|
|
else printf "%s\n" "curl/wget not available - get $BinaryName manually from the repo link, exiting."; exit 1;
|
|
|
|
|
fi
|
|
|
|
|
[[ -f "$ScriptWorkDir/$BinaryName" ]] && chmod +x "$ScriptWorkDir/$BinaryName"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
distro_checker() {
|
|
|
|
|
if [[ -f /etc/arch-release ]] ; then PkgInstaller="pacman -S"
|
|
|
|
|
elif [[ -f /etc/redhat-release ]] ; then PkgInstaller="dnf install"
|
|
|
|
|
elif [[ -f /etc/SuSE-release ]] ; then PkgInstaller="zypper install"
|
|
|
|
|
elif [[ -f /etc/debian_version ]] ; then PkgInstaller="apt-get install"
|
|
|
|
|
else PkgInstaller="ERROR" ; printf "\n%bNo distribution could be determined%b, falling back to static binary.\n" "$c_yellow" "$c_reset"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Version check & initiate self update
|
|
|
|
|
if [[ "$VERSION" != "$LatestRelease" ]] && [[ -n "$LatestRelease" ]]; then
|
2024-01-31 21:33:14 +01:00
|
|
|
printf "New version available! %b%s%b ⇒ %b%s%b \n Change Notes: %s \n" "$c_yellow" "$VERSION" "$c_reset" "$c_green" "$LatestRelease" "$c_reset" "$LatestChanges"
|
2024-08-17 08:50:39 -04:00
|
|
|
if [[ -z "$AutoUp" ]] ; then
|
2024-01-31 21:33:14 +01:00
|
|
|
read -r -p "Would you like to update? y/[n]: " SelfUpdate
|
|
|
|
|
[[ "$SelfUpdate" =~ [yY] ]] && self_update
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2023-03-04 19:56:26 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Set $1 to a variable for name filtering later
|
2023-02-09 12:03:27 +00:00
|
|
|
SearchName="$1"
|
2024-11-16 18:24:58 +00:00
|
|
|
# Create array of excludes
|
2023-02-26 07:49:57 +01:00
|
|
|
IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
|
2023-01-19 12:09:29 +01:00
|
|
|
|
2024-11-25 14:05:30 +01:00
|
|
|
# Dependency check for jq in PATH or directory
|
|
|
|
|
if [[ $(command -v jq) ]]; then jqbin="jq" ;
|
|
|
|
|
elif [[ -f "$ScriptWorkDir/jq" ]]; then jqbin="$ScriptWorkDir/jq" ;
|
|
|
|
|
else
|
|
|
|
|
printf "%s\n" "Required dependency 'jq' missing, do you want to install it?"
|
|
|
|
|
read -r -p "y: With packagemanager (sudo). / s: Download static binary. y/s/[n] " GetJq
|
|
|
|
|
GetJq=${GetJq:-no} # set default to no if nothing is given
|
|
|
|
|
if [[ "$GetJq" =~ [yYsS] ]] ; then
|
|
|
|
|
[[ "$GetJq" =~ [yY] ]] && distro_checker
|
|
|
|
|
if [[ -n "$PkgInstaller" && "$PkgInstaller" != "ERROR" ]] ; then
|
|
|
|
|
(sudo $PkgInstaller jq) ; PkgExitcode="$?"
|
|
|
|
|
[[ "$PkgExitcode" == 0 ]] && jqbin="jq" || printf "\n%bPackagemanager install failed%b, falling back to static binary.\n" "$c_yellow" "$c_reset"
|
|
|
|
|
fi
|
|
|
|
|
if [[ "$GetJq" =~ [nN] || "$PkgInstaller" == "ERROR" || "$PkgExitcode" != 0 ]] ; then
|
|
|
|
|
binary_downloader "jq" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP"
|
|
|
|
|
[[ -f "$ScriptWorkDir/jq" ]] && jqbin="$ScriptWorkDir/jq"
|
|
|
|
|
fi
|
|
|
|
|
else printf "\n%bDependency missing, exiting.%b\n" "$c_red" "$c_reset" ; exit 1 ;
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
# Final check if binary is correct
|
|
|
|
|
$jqbin --version &> /dev/null || { printf "%s\n" "jq is not working - try to remove it and re-download it, exiting."; exit 1; }
|
|
|
|
|
|
|
|
|
|
# Dependency check for regctl in PATH or directory
|
2024-11-19 21:01:39 +01:00
|
|
|
if [[ $(command -v regctl) ]]; then regbin="regctl" ;
|
2023-11-19 20:20:05 +01:00
|
|
|
elif [[ -f "$ScriptWorkDir/regctl" ]]; then regbin="$ScriptWorkDir/regctl" ;
|
2023-02-09 12:03:27 +00:00
|
|
|
else
|
2024-11-25 14:05:30 +01:00
|
|
|
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetRegctl
|
|
|
|
|
if [[ "$GetRegctl" =~ [yY] ]] ; then
|
|
|
|
|
binary_downloader "regctl" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
|
|
|
|
|
[[ -f "$ScriptWorkDir/regctl" ]] && regbin="$ScriptWorkDir/regctl"
|
|
|
|
|
else printf "\n%bDependency missing, exiting.%b\n" "$c_red" "$c_reset" ; exit 1 ;
|
2023-02-09 12:03:27 +00:00
|
|
|
fi
|
|
|
|
|
fi
|
2024-11-16 18:24:58 +00:00
|
|
|
# Final check if binary is correct
|
2023-02-15 13:16:31 +01:00
|
|
|
$regbin version &> /dev/null || { printf "%s\n" "regctl is not working - try to remove it and re-download it, exiting."; exit 1; }
|
|
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Check podman compose binary
|
|
|
|
|
if podman compose version &> /dev/null ; then PodmanComposeBin="podman compose" ;
|
|
|
|
|
elif command -v podman-compose &> /dev/null; then PodmanComposeBin="podman-compose" ;
|
|
|
|
|
elif podman version &> /dev/null; then
|
|
|
|
|
printf "%s\n" "No podman-compose binary available, using plain podman"
|
2023-02-09 12:03:27 +00:00
|
|
|
else
|
2024-11-16 18:24:58 +00:00
|
|
|
printf "%s\n" "No podman binaries available, exiting."
|
2023-02-15 13:16:31 +01:00
|
|
|
exit 1
|
2023-02-09 12:03:27 +00:00
|
|
|
fi
|
2023-01-30 10:08:13 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Numbered List function
|
2023-02-09 12:03:27 +00:00
|
|
|
options() {
|
2023-02-15 13:16:31 +01:00
|
|
|
num=1
|
|
|
|
|
for i in "${GotUpdates[@]}"; do
|
2023-02-09 12:03:27 +00:00
|
|
|
echo "$num) $i"
|
|
|
|
|
((num++))
|
|
|
|
|
done
|
|
|
|
|
}
|
2023-01-30 10:08:13 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Listing typed exclusions
|
2023-06-21 20:09:31 +02:00
|
|
|
if [[ -n ${Excludes[*]} ]] ; then
|
2024-02-01 20:19:04 +01:00
|
|
|
printf "\n%bExcluding these names:%b\n" "$c_blue" "$c_reset"
|
2023-06-21 20:09:31 +02:00
|
|
|
printf "%s\n" "${Excludes[@]}"
|
|
|
|
|
printf "\n"
|
|
|
|
|
fi
|
|
|
|
|
|
2024-01-17 20:26:18 +01:00
|
|
|
# Variables for progress_bar function
|
2024-11-19 21:01:39 +01:00
|
|
|
ContCount=$(podman ps $Stopped --filter "name=$SearchName" --format '{{.Names}}' | wc -l)
|
2024-01-17 20:26:18 +01:00
|
|
|
RegCheckQue=0
|
|
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Testing and setting timeout binary
|
2024-11-19 21:01:39 +01:00
|
|
|
t_out=$(command -v timeout)
|
2024-06-16 07:51:32 +02:00
|
|
|
if [[ $t_out ]]; then
|
|
|
|
|
t_out=$(realpath $t_out 2>/dev/null || readlink -f $t_out)
|
|
|
|
|
if [[ $t_out =~ "busybox" ]]; then
|
|
|
|
|
t_out="timeout ${Timeout}"
|
|
|
|
|
else t_out="timeout --foreground ${Timeout}"
|
|
|
|
|
fi
|
|
|
|
|
else t_out=""
|
|
|
|
|
fi
|
|
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Check the image-hash of every running container VS the registry
|
|
|
|
|
for i in $(podman ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
|
2024-01-17 20:26:18 +01:00
|
|
|
((RegCheckQue+=1))
|
2024-11-19 21:01:39 +01:00
|
|
|
progress_bar "$RegCheckQue" "$ContCount"
|
2024-11-16 18:24:58 +00:00
|
|
|
# Looping every item over the list of excluded names and skipping
|
2024-08-17 08:50:39 -04:00
|
|
|
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
|
2024-11-16 18:24:58 +00:00
|
|
|
RepoUrl=$(podman inspect "$i" --format='{{.ImageName}}')
|
2024-11-17 17:03:31 +01:00
|
|
|
LocalHash=$(podman image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
2024-11-16 18:24:58 +00:00
|
|
|
# Checking for errors while setting the variable
|
2024-10-08 09:41:32 +02:00
|
|
|
if RegHash=$(${t_out} $regbin -v error image digest --list "$RepoUrl" 2>&1) ; then
|
2024-11-17 15:00:30 +00:00
|
|
|
if [[ "$LocalHash" == *"$RegHash"* ]] ; then
|
2024-08-17 08:50:39 -04:00
|
|
|
NoUpdates+=("$i")
|
|
|
|
|
else
|
2023-12-13 19:50:58 +01:00
|
|
|
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
2024-08-17 08:50:39 -04:00
|
|
|
NoUpdates+=("+$i ${ImageAge}d")
|
|
|
|
|
else
|
2023-12-13 19:50:58 +01:00
|
|
|
GotUpdates+=("$i")
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2023-02-09 12:03:27 +00:00
|
|
|
else
|
2024-11-16 18:24:58 +00:00
|
|
|
# Here the RegHash is the result of an error code
|
2024-01-15 20:27:45 +01:00
|
|
|
GotErrors+=("$i - ${RegHash}")
|
2023-02-09 12:03:27 +00:00
|
|
|
fi
|
|
|
|
|
done
|
2023-01-18 11:50:00 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Sort arrays alphabetically
|
2024-06-12 20:50:10 +02:00
|
|
|
IFS=$'\n'
|
|
|
|
|
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
|
|
|
|
|
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
|
|
|
|
|
unset IFS
|
|
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Define how many updates are available
|
2023-02-15 13:16:31 +01:00
|
|
|
UpdCount="${#GotUpdates[@]}"
|
2023-01-30 10:08:13 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# List what containers got updates or not
|
2023-02-12 19:40:42 +01:00
|
|
|
if [[ -n ${NoUpdates[*]} ]] ; then
|
2023-12-19 20:24:34 +01:00
|
|
|
printf "\n%bContainers on latest version:%b\n" "$c_green" "$c_reset"
|
2023-01-18 11:50:00 +01:00
|
|
|
printf "%s\n" "${NoUpdates[@]}"
|
|
|
|
|
fi
|
2023-02-12 19:40:42 +01:00
|
|
|
if [[ -n ${GotErrors[*]} ]] ; then
|
2024-11-16 18:24:58 +00:00
|
|
|
printf "\n%bContainers with errors; won't get updated:%b\n" "$c_red" "$c_reset"
|
2023-01-20 12:47:17 +01:00
|
|
|
printf "%s\n" "${GotErrors[@]}"
|
2024-04-22 21:02:13 +02:00
|
|
|
printf "%binfo:%b 'unauthorized' often means not found in a public registry.\n" "$c_blue" "$c_reset"
|
2023-01-20 12:47:17 +01:00
|
|
|
fi
|
2024-08-17 08:50:39 -04:00
|
|
|
if [[ -n ${GotUpdates[*]} ]] ; then
|
2023-12-19 20:24:34 +01:00
|
|
|
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
|
2023-12-23 20:47:23 +01:00
|
|
|
[[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}"
|
2024-02-01 20:19:04 +01:00
|
|
|
[[ -n "$Notify" ]] && { [[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n" ; }
|
2023-01-30 10:08:13 +01:00
|
|
|
fi
|
2023-01-18 11:50:00 +01:00
|
|
|
|
2024-11-16 18:24:58 +00:00
|
|
|
# Optionally get updates if there's any
|
2023-01-18 21:45:31 +01:00
|
|
|
if [ -n "$GotUpdates" ] ; then
|
2023-12-23 20:47:23 +01:00
|
|
|
if [ -z "$AutoUp" ] ; then
|
2024-11-16 18:24:58 +00:00
|
|
|
printf "\n%bChoose what containers to update.%b\n" "$c_teal" "$c_reset"
|
|
|
|
|
choosecontainers
|
2023-01-30 10:08:13 +01:00
|
|
|
else
|
|
|
|
|
SelectedUpdates=( "${GotUpdates[@]}" )
|
|
|
|
|
fi
|
2023-12-23 20:47:23 +01:00
|
|
|
if [ "$AutoUp" == "${AutoUp#[Nn]}" ] ; then
|
2023-06-27 19:34:20 +02:00
|
|
|
NumberofUpdates="${#SelectedUpdates[@]}"
|
|
|
|
|
CurrentQue=0
|
2023-01-30 10:08:13 +01:00
|
|
|
for i in "${SelectedUpdates[@]}"
|
2023-03-01 20:39:02 +01:00
|
|
|
do
|
2023-06-27 19:34:20 +02:00
|
|
|
((CurrentQue+=1))
|
2023-03-01 20:39:02 +01:00
|
|
|
unset CompleteConfs
|
2024-11-16 18:24:58 +00:00
|
|
|
# Extract labels and metadata
|
|
|
|
|
ContLabels=$(podman inspect "$i" --format '{{json .Config.Labels}}')
|
2024-11-19 21:00:07 +01:00
|
|
|
ContImage=$(podman inspect "$i" --format='{{.ImageName}}')
|
2024-11-25 14:05:30 +01:00
|
|
|
ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
|
2024-11-16 18:24:58 +00:00
|
|
|
[ "$ContPath" == "null" ] && ContPath=""
|
2024-11-25 14:05:30 +01:00
|
|
|
ContConfigFile=$($jqbin -r '."com.docker.compose.project.config_files"' <<< "$ContLabels")
|
2024-11-16 18:24:58 +00:00
|
|
|
[ "$ContConfigFile" == "null" ] && ContConfigFile=""
|
2024-11-25 14:05:30 +01:00
|
|
|
ContName=$($jqbin -r '."com.docker.compose.service"' <<< "$ContLabels")
|
2024-11-16 18:24:58 +00:00
|
|
|
[ "$ContName" == "null" ] && ContName=""
|
2024-11-25 14:05:30 +01:00
|
|
|
ContEnv=$($jqbin -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels")
|
2024-11-16 18:24:58 +00:00
|
|
|
[ "$ContEnv" == "null" ] && ContEnv=""
|
2024-11-25 14:05:30 +01:00
|
|
|
ContUpdateLabel=$($jqbin -r '."sudo-kraken.podcheck.update"' <<< "$ContLabels")
|
2024-11-16 18:24:58 +00:00
|
|
|
[ "$ContUpdateLabel" == "null" ] && ContUpdateLabel=""
|
2024-11-25 14:05:30 +01:00
|
|
|
ContRestartStack=$($jqbin -r '."sudo-kraken.podcheck.restart-stack"' <<< "$ContLabels")
|
2024-11-16 18:24:58 +00:00
|
|
|
[ "$ContRestartStack" == "null" ] && ContRestartStack=""
|
|
|
|
|
|
|
|
|
|
# Checking if compose-values are empty - possibly started with podman run or managed by Quadlet
|
2024-08-17 08:50:39 -04:00
|
|
|
if [ -z "$ContPath" ] ; then
|
2024-11-16 18:24:58 +00:00
|
|
|
# Check if a systemd unit exists with the same name as the container
|
|
|
|
|
if systemctl --user status "$i.service" &> /dev/null; then
|
|
|
|
|
echo "Detected Quadlet-managed container: $i (unit: $i.service)"
|
|
|
|
|
podman pull "$ContImage"
|
|
|
|
|
systemctl --user restart "$i.service"
|
|
|
|
|
echo "Quadlet container $i updated and restarted."
|
|
|
|
|
elif [ "$(id -u)" -eq 0 ] && systemctl status "$i.service" &> /dev/null; then
|
|
|
|
|
echo "Detected Quadlet-managed container: $i (unit: $i.service)"
|
|
|
|
|
podman pull "$ContImage"
|
|
|
|
|
systemctl restart "$i.service"
|
|
|
|
|
echo "Quadlet container $i updated and restarted."
|
2023-02-10 21:06:12 +01:00
|
|
|
else
|
2024-11-16 18:24:58 +00:00
|
|
|
if [ "$DRunUp" == "yes" ] ; then
|
|
|
|
|
podman pull "$ContImage"
|
|
|
|
|
printf "%s\n" "$i got a new image downloaded; rebuild manually with preferred 'podman run' parameters"
|
|
|
|
|
else
|
|
|
|
|
printf "\n%b%s%b has no compose labels or associated systemd unit; %bskipping%b\n\n" "$c_yellow" "$i" "$c_reset" "$c_yellow" "$c_reset"
|
|
|
|
|
fi
|
2023-02-10 21:06:12 +01:00
|
|
|
fi
|
2024-08-17 08:50:39 -04:00
|
|
|
continue
|
2023-02-10 21:06:12 +01:00
|
|
|
fi
|
2024-11-16 18:24:58 +00:00
|
|
|
# cd to the compose-file directory to account for people who use relative volumes
|
2024-04-22 21:12:00 +02:00
|
|
|
cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; }
|
2024-11-16 18:24:58 +00:00
|
|
|
# Reformatting path + multi compose
|
2023-02-09 12:00:29 +00:00
|
|
|
if [[ $ContConfigFile = '/'* ]] ; then
|
2024-04-22 21:12:00 +02:00
|
|
|
CompleteConfs=$(for conf in ${ContConfigFile//,/ } ; do printf -- "-f %s " "$conf"; done)
|
2023-02-09 12:00:29 +00:00
|
|
|
else
|
2024-04-22 21:12:00 +02:00
|
|
|
CompleteConfs=$(for conf in ${ContConfigFile//,/ } ; do printf -- "-f %s/%s " "$ContPath" "$conf"; done)
|
2023-02-09 12:00:29 +00:00
|
|
|
fi
|
2023-12-19 20:24:34 +01:00
|
|
|
printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
|
2024-11-16 18:24:58 +00:00
|
|
|
# Checking if Label Only option is set, and if container got the label
|
|
|
|
|
[[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != "true" ]] && { echo "No update label, skipping." ; continue ; } }
|
|
|
|
|
podman pull "$ContImage"
|
|
|
|
|
# Check if the container got an environment file set and reformat it
|
2024-04-22 21:12:00 +02:00
|
|
|
if [ -n "$ContEnv" ]; then ContEnvs=$(for env in ${ContEnv//,/ } ; do printf -- "--env-file %s " "$env"; done) ; fi
|
2024-11-16 18:24:58 +00:00
|
|
|
# Check if the whole pod should be restarted
|
|
|
|
|
if [[ "$ContRestartStack" == "true" ]] || [[ "$ForceRestartPods" == true ]] ; then
|
|
|
|
|
$PodmanComposeBin ${CompleteConfs} down ; $PodmanComposeBin ${CompleteConfs} ${ContEnvs} up -d
|
2023-02-19 14:21:22 +01:00
|
|
|
else
|
2024-11-16 18:24:58 +00:00
|
|
|
$PodmanComposeBin ${CompleteConfs} ${ContEnvs} up -d ${ContName}
|
2023-02-19 14:21:22 +01:00
|
|
|
fi
|
2023-01-30 10:08:13 +01:00
|
|
|
done
|
2023-12-19 20:24:34 +01:00
|
|
|
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
|
2024-08-17 22:56:04 +02:00
|
|
|
if [[ -z "$AutoPrune" ]] && [[ -z "$AutoUp" ]]; then read -r -p "Would you like to prune dangling images? y/[n]: " AutoPrune ; fi
|
2024-11-16 18:24:58 +00:00
|
|
|
[[ "$AutoPrune" =~ [yY] ]] && podman image prune -f
|
2023-01-30 10:08:13 +01:00
|
|
|
else
|
|
|
|
|
printf "\nNo updates installed, exiting.\n"
|
2023-01-20 11:52:47 +01:00
|
|
|
fi
|
2023-01-18 11:50:00 +01:00
|
|
|
else
|
2023-01-18 21:45:31 +01:00
|
|
|
printf "\nNo updates available, exiting.\n"
|
2023-01-18 11:50:00 +01:00
|
|
|
fi
|
2023-01-30 10:08:13 +01:00
|
|
|
|
|
|
|
|
exit 0
|