mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-14 23:38:15 +01:00
Merge pull request #130 from mag37/osx_support
Some osx / bsd compatibility changes. Rewritten the dependency (jq + regctl) install method. Many thanks to @pshannon-git for testing!
This commit is contained in:
commit
210c076968
2 changed files with 51 additions and 52 deletions
14
README.md
14
README.md
|
|
@ -19,17 +19,11 @@
|
|||
___
|
||||
## :bell: Changelog
|
||||
|
||||
- **v0.5.5.0**: osx and bsd compatibility changes + rewrite of dependency installer
|
||||
- **v0.5.4.0**: Added support for a Prometheus+node_exporter metric collection through a file collector.
|
||||
- **v0.5.3.0**: Local image check changed (use imageId instead of name) and Gotify-template fixed (whale icon removed).
|
||||
- **v0.5.2.1**: Rewrite of dependency downloads, jq can be installed with package manager or static binary.
|
||||
- **v0.5.1**: DEPENDENCY WARNING: now requires **jq**. + Upstreaming changes from [sudo-kraken/podcheck](https://github.com/sudo-kraken/podcheck)
|
||||
- **v0.5.0**: Rewritten notify logic - all templates are adjusted and should be migrated!
|
||||
- Copy the custom settings from your current template to the new version of the same template.
|
||||
- Look into, copy and customize the `urls.list` file if that's of interest.
|
||||
- Other changes:
|
||||
- Added Discord notify template.
|
||||
- Verbosity changed of `regctl`.
|
||||
- **v0.4.9**: Added a function to enrich the notify-message with release note URLs. See [Release notes addon](https://github.com/mag37/dockcheck#date-release-notes-addon-to-notifications)
|
||||
___
|
||||
|
||||
|
||||
|
|
@ -90,7 +84,8 @@ ___
|
|||
- regctl requires `amd64/arm64` - see [workaround](#roller_coaster-workaround-for-non-amd64--arm64) if other architecture is used.
|
||||
|
||||
## :tent: Install Instructions
|
||||
Download the script to a directory in **PATH**, I'd suggest using `~/.local/bin` as that's usually in **PATH**.
|
||||
Download the script to a directory in **PATH**, I'd suggest using `~/.local/bin` as that's usually in **PATH**.
|
||||
For OSX/macOS preferably use `/usr/local/bin`.
|
||||
```sh
|
||||
# basic example with curl:
|
||||
curl -L https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh -o ~/.local/bin/dockcheck.sh
|
||||
|
|
@ -98,6 +93,9 @@ chmod +x ~/.local/bin/dockcheck.sh
|
|||
|
||||
# or oneliner with wget:
|
||||
wget -O ~/.local/bin/dockcheck.sh "https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh" && chmod +x ~/.local/bin/dockcheck.sh
|
||||
|
||||
# OSX or macOS version with curl:
|
||||
curl -L https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh -o /usr/local/bin/dockcheck.sh && chmod +x /usr/local/bin/dockcheck.sh
|
||||
```
|
||||
Then call the script anywhere with just `dockcheck.sh`.
|
||||
Add preferred `notify.sh`-template to the same directory - this will not be touched by the scripts self-update function.
|
||||
|
|
|
|||
89
dockcheck.sh
89
dockcheck.sh
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
VERSION="v0.5.4.0"
|
||||
### ChangeNotes: Added support for a Prometheus+node_exporter metric collection through a file collector.
|
||||
VERSION="v0.5.5.0"
|
||||
### ChangeNotes: osx and bsd compatibility changes + rewrite of dependency installer
|
||||
Github="https://github.com/mag37/dockcheck"
|
||||
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
||||
|
||||
|
|
@ -131,7 +131,8 @@ choosecontainers() {
|
|||
|
||||
datecheck() {
|
||||
ImageDate=$($regbin -v error image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
|
||||
ImageAge=$(( ( $(date +%s) - $(date -d "$ImageDate" +%s) )/86400 ))
|
||||
ImageEpoch=$(date -d "$ImageDate" +%s 2>/dev/null) || ImageEpoch=$(date -f "%Y-%m-%d" -j "$ImageDate" +%s)
|
||||
ImageAge=$(( ( $(date +%s) - $ImageEpoch )/86400 ))
|
||||
if [ "$ImageAge" -gt "$DaysOld" ] ; then
|
||||
return 0
|
||||
else
|
||||
|
|
@ -152,7 +153,7 @@ progress_bar() {
|
|||
}
|
||||
|
||||
# Function to add user-provided urls to releasenotes
|
||||
releasenotes() {
|
||||
releasenotes() {
|
||||
for update in ${GotUpdates[@]}; do
|
||||
found=false
|
||||
while read -r container url; do
|
||||
|
|
@ -180,14 +181,14 @@ IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
|
|||
binary_downloader() {
|
||||
BinaryName="$1"
|
||||
BinaryUrl="$2"
|
||||
case "$(uname --machine)" in
|
||||
case "$(uname -m)" 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" ;
|
||||
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"
|
||||
|
|
@ -195,49 +196,49 @@ binary_downloader() {
|
|||
|
||||
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"
|
||||
elif [[ -f /etc/redhat-release ]] ; then PkgInstaller="sudo dnf install"
|
||||
elif [[ -f /etc/SuSE-release ]] ; then PkgInstaller="sudo zypper install"
|
||||
elif [[ -f /etc/debian_version ]] ; then PkgInstaller="sudo apt-get install"
|
||||
elif [[ $(uname -s) == "Darwin" ]] ; then PkgInstaller="brew install"
|
||||
else PkgInstaller="ERROR" ; printf "\n%bNo distribution could be determined%b, falling back to static binary.\n" "$c_yellow" "$c_reset"
|
||||
fi
|
||||
}
|
||||
|
||||
# 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"
|
||||
# Dependency check + installer function
|
||||
dependency_check() {
|
||||
AppName="$1"
|
||||
AppVar="$2"
|
||||
AppUrl="$3"
|
||||
if [[ $(command -v $AppName) ]]; then export $AppVar="$AppName" ;
|
||||
elif [[ -f "$ScriptWorkDir/$AppName" ]]; then export $AppVar="$ScriptWorkDir/$AppName" ;
|
||||
else
|
||||
printf "%s\n" "Required dependency '$AppName' missing, do you want to install it?"
|
||||
read -r -p "y: With packagemanager (sudo). / s: Download static binary. y/s/[n] " GetBin
|
||||
GetBin=${GetBin:-no} # set default to no if nothing is given
|
||||
if [[ "$GetBin" =~ [yYsS] ]] ; then
|
||||
[[ "$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$AppName installed.%b\n" "$c_green" "$c_reset"; }
|
||||
else 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
|
||||
binary_downloader "$AppName" "$AppUrl"
|
||||
[[ -f "$ScriptWorkDir/$AppName" ]] && { export $AppVar="$ScriptWorkDir/$1" && printf "\n%b$AppName downloaded.%b\n" "$c_green" "$c_reset"; }
|
||||
fi
|
||||
else printf "\n%bDependency missing, exiting.%b\n" "$c_red" "$c_reset" ; exit 1 ;
|
||||
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; }
|
||||
# Final check if binary is correct
|
||||
[[ "$1" == "jq" ]] && VerFlag="--version"
|
||||
[[ "$1" == "regctl" ]] && VerFlag="version"
|
||||
${!AppVar} $VerFlag &> /dev/null || { printf "%s\n" "$AppName is not working - try to remove it and re-download it, exiting."; exit 1; }
|
||||
}
|
||||
|
||||
# Dependency check for regctl in PATH or directory
|
||||
if [[ $(command -v regctl) ]]; then regbin="regctl" ;
|
||||
elif [[ -f "$ScriptWorkDir/regctl" ]]; then regbin="$ScriptWorkDir/regctl" ;
|
||||
else
|
||||
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 ;
|
||||
fi
|
||||
fi
|
||||
# Final check if binary is correct
|
||||
$regbin version &> /dev/null || { printf "%s\n" "regctl is not working - try to remove it and re-download it, exiting."; exit 1; }
|
||||
dependency_check "regctl" "regbin" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
|
||||
dependency_check "jq" "jqbin" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP"
|
||||
|
||||
# Check docker compose binary
|
||||
if docker compose version &> /dev/null ; then DockerBin="docker compose" ;
|
||||
|
|
@ -315,7 +316,7 @@ unset IFS
|
|||
|
||||
# Run the prometheus exporter function
|
||||
if [ -n "$CollectorTextFileDirectory" ] ; then
|
||||
source "$ScriptWorkDir"/addons/prometheus/prometheus_collector.sh && prometheus_exporter ${#NoUpdates[@]} ${#GotUpdates[@]} ${#GotError[@]}
|
||||
source "$ScriptWorkDir"/addons/prometheus/prometheus_collector.sh && prometheus_exporter ${#NoUpdates[@]} ${#GotUpdates[@]} ${#GotErrors[@]}
|
||||
fi
|
||||
|
||||
# Define how many updates are available
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue