mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-18 02:17:46 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a8571c625 | ||
|
|
710cbc118f | ||
|
|
68ec749c39 | ||
|
|
778df1de3c |
@@ -21,6 +21,10 @@
|
||||
___
|
||||
## :bell: Changelog
|
||||
|
||||
- **v0.6.1**: Hotfixes: (try removing set+shopt+shopt if debugging more errors)
|
||||
- xargs/pipefail, removed `-set -e` bash option for now.
|
||||
- unbound variables fixed (hopefully)
|
||||
- dependency installer from pkgmanager rewritten
|
||||
- **v0.6.0**: Refactored a lot of code, cleaner logic and syntax, safer variables.
|
||||
- Safer bash options with `set -euo pipefail`, `shopt -s nullglob` and `failglob`.
|
||||
- Added a `default.conf` for user settings - persistent through updates.
|
||||
|
||||
34
dockcheck.sh
34
dockcheck.sh
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
VERSION="v0.6.0"
|
||||
### ChangeNotes: uservars file added. Lots of code refactoring, please report any bugs.
|
||||
VERSION="v0.6.1"
|
||||
### ChangeNotes: Hotfix - bug with xargs pipefail, pkgmanager logic, unbound variables
|
||||
Github="https://github.com/mag37/dockcheck"
|
||||
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
||||
|
||||
set -euo pipefail
|
||||
set -uo pipefail
|
||||
shopt -s nullglob
|
||||
shopt -s failglob
|
||||
|
||||
@@ -269,12 +269,16 @@ dependency_check() {
|
||||
[[ "$GetBin" =~ [yY] ]] && distro_checker
|
||||
if [[ -n "${PkgInstaller:-}" && "${PkgInstaller:-}" != "ERROR" ]]; then
|
||||
[[ $(uname -s) == "Darwin" && "$AppName" == "regctl" ]] && AppName="regclient"
|
||||
("$PkgInstaller" "$AppName"); PkgExitcode="$?" && AppName="$1"
|
||||
if [[ "$PkgExitcode" == 0 ]]; then { export "$AppVar"="$AppName" && printf "\n%b%b installed.%b\n" "$c_green" "$AppName" "$c_reset"; }
|
||||
else printf "\n%bPackagemanager install failed%b, falling back to static binary.\n" "$c_yellow" "$c_reset"
|
||||
if $PkgInstaller "$AppName"; then
|
||||
AppName="$1"
|
||||
export "$AppVar"="$AppName"
|
||||
printf "\n%b%b installed.%b\n" "$c_green" "$AppName" "$c_reset"
|
||||
else
|
||||
PkgExitcode="ERROR"
|
||||
printf "\n%bPackagemanager install failed%b, falling back to static binary.\n" "$c_yellow" "$c_reset"
|
||||
fi
|
||||
fi
|
||||
if [[ "$GetBin" =~ [sS] || "$PkgInstaller" == "ERROR" || "$PkgExitcode" != 0 ]]; then
|
||||
if [[ "$GetBin" =~ [sS] || "$PkgInstaller" == "ERROR" ]]; then
|
||||
binary_downloader "$AppName" "$AppUrl"
|
||||
[[ -f "$ScriptWorkDir/$AppName" ]] && { export "$AppVar"="$ScriptWorkDir/$1" && printf "\n%b%b downloaded.%b\n" "$c_green" "$AppName" "$c_reset"; }
|
||||
fi
|
||||
@@ -322,7 +326,7 @@ else
|
||||
fi
|
||||
|
||||
# Listing typed exclusions
|
||||
if [[ -n ${Excludes[*]} ]]; then
|
||||
if [[ -n ${Excludes[*]:-} ]]; then
|
||||
printf "\n%bExcluding these names:%b\n" "$c_blue" "$c_reset"
|
||||
printf "%s\n" "${Excludes[@]}"
|
||||
printf "\n"
|
||||
@@ -376,7 +380,7 @@ check_image() {
|
||||
|
||||
# Make required functions and variables available to subprocesses
|
||||
export -f check_image datecheck
|
||||
export Excludes_string="${Excludes[*]}" # Can only export scalar variables
|
||||
export Excludes_string="${Excludes[*]:-}" # Can only export scalar variables
|
||||
export t_out regbin RepoUrl DaysOld
|
||||
|
||||
# Check for POSIX xargs with -P option, fallback without async
|
||||
@@ -409,14 +413,14 @@ done < <( \
|
||||
|
||||
# Sort arrays alphabetically
|
||||
IFS=$'\n'
|
||||
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
|
||||
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
|
||||
NoUpdates=($(sort <<<"${NoUpdates[*]:-}"))
|
||||
GotUpdates=($(sort <<<"${GotUpdates[*]:-}"))
|
||||
unset IFS
|
||||
|
||||
# Run the prometheus exporter function
|
||||
if [[ -n "${CollectorTextFileDirectory:-}" ]]; then
|
||||
if type -t send_notification &>/dev/null; then
|
||||
prometheus_exporter ${#NoUpdates[@]} ${#GotUpdates[@]} ${#GotErrors[@]}
|
||||
prometheus_exporter ${#NoUpdates[@]:-} ${#GotUpdates[@]:-} ${#GotErrors[@]:-}
|
||||
else
|
||||
printf "%s\n" "Could not source prometheus exporter function."
|
||||
fi
|
||||
@@ -426,16 +430,16 @@ fi
|
||||
UpdCount="${#GotUpdates[@]}"
|
||||
|
||||
# List what containers got updates or not
|
||||
if [[ -n ${NoUpdates[*]} ]]; then
|
||||
if [[ -n ${NoUpdates[*]:-} ]]; then
|
||||
printf "\n%bContainers on latest version:%b\n" "$c_green" "$c_reset"
|
||||
printf "%s\n" "${NoUpdates[@]}"
|
||||
fi
|
||||
if [[ -n ${GotErrors[*]} ]]; then
|
||||
if [[ -n ${GotErrors[*]:-} ]]; then
|
||||
printf "\n%bContainers with errors, won't get updated:%b\n" "$c_red" "$c_reset"
|
||||
printf "%s\n" "${GotErrors[@]}"
|
||||
printf "%binfo:%b 'unauthorized' often means not found in a public registry.\n" "$c_blue" "$c_reset"
|
||||
fi
|
||||
if [[ -n ${GotUpdates[*]} ]]; then
|
||||
if [[ -n ${GotUpdates[*]:-} ]]; then
|
||||
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
|
||||
[[ "$AutoMode" == false ]] && options || printf "%s\n" "${GotUpdates[@]}"
|
||||
[[ "$Notify" == true ]] && { type -t send_notification &>/dev/null && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n"; }
|
||||
|
||||
Reference in New Issue
Block a user