mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-15 07:48:14 +01:00
Merge pull request #111 from mag37/dependency_download_rewrite
Dependency download rewrite + jq installer
This commit is contained in:
commit
b4943df46c
2 changed files with 66 additions and 35 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
___
|
___
|
||||||
## :bell: Changelog
|
## :bell: Changelog
|
||||||
|
|
||||||
|
- **v0.5.2**: Rewrite of dependency downloads, now jq can be auto-downloaded 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.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!
|
- **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.
|
- Copy the custom settings from your current template to the new version of the same template.
|
||||||
|
|
@ -27,8 +28,6 @@ ___
|
||||||
- Verbosity changed of `regctl`.
|
- 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)
|
- **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)
|
||||||
- **v0.4.8**: Rewrote prune logic to not prompt with options `-a|-y` or `-n`. Auto prune with `-p`.
|
- **v0.4.8**: Rewrote prune logic to not prompt with options `-a|-y` or `-n`. Auto prune with `-p`.
|
||||||
- **v0.4.7**: Notification Template changes to gotify(new!), DSM(improved), SMTP(deprecation alternative).
|
|
||||||
- **v0.4.6**: Compatibility changes to timeout, due to busybox.
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -57,7 +56,6 @@ Options:"
|
||||||
-v Prints current version.
|
-v Prints current version.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Basic example:
|
### Basic example:
|
||||||
```
|
```
|
||||||
$ ./dockcheck.sh
|
$ ./dockcheck.sh
|
||||||
|
|
@ -82,6 +80,8 @@ ___
|
||||||
## :nut_and_bolt: Dependencies
|
## :nut_and_bolt: Dependencies
|
||||||
- Running docker (duh) and compose, either standalone or plugin. (see [Podman fork](https://github.com/sudo-kraken/podcheck)
|
- Running docker (duh) and compose, either standalone or plugin. (see [Podman fork](https://github.com/sudo-kraken/podcheck)
|
||||||
- Bash shell or compatible shell of at least v4.3
|
- Bash shell or compatible shell of at least v4.3
|
||||||
|
- [jq](https://github.com/jqlang/jq)
|
||||||
|
- User will be prompted to install with package manager or download static binary.
|
||||||
- [regclient/regctl](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
|
- [regclient/regctl](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
|
||||||
- User will be prompted to download `regctl` if not in `PATH` or `PWD`.
|
- User will be prompted to download `regctl` if not in `PATH` or `PWD`.
|
||||||
- regctl requires `amd64/arm64` - see [workaround](#roller_coaster-workaround-for-non-amd64--arm64) if other architecture is used.
|
- regctl requires `amd64/arm64` - see [workaround](#roller_coaster-workaround-for-non-amd64--arm64) if other architecture is used.
|
||||||
|
|
|
||||||
95
dockcheck.sh
95
dockcheck.sh
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.5.1"
|
VERSION="v0.5.2"
|
||||||
### ChangeNotes: DEPENDENCY WARNING: now requires jq. And upstreaming changes from sudo-kraken/podcheck
|
# ChangeNotes: DEPENDENCY REMINDER: now requires jq. UPDATE: Rewrite of dependency installer.
|
||||||
Github="https://github.com/mag37/dockcheck"
|
Github="https://github.com/mag37/dockcheck"
|
||||||
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
||||||
|
|
||||||
|
|
@ -173,27 +173,64 @@ SearchName="$1"
|
||||||
# Create array of excludes
|
# Create array of excludes
|
||||||
IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
|
IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
|
||||||
|
|
||||||
# Check if required binary exists in PATH or directory
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
if [[ $(command -v regctl) ]]; then regbin="regctl" ;
|
if [[ $(command -v regctl) ]]; then regbin="regctl" ;
|
||||||
elif [[ -f "$ScriptWorkDir/regctl" ]]; then regbin="$ScriptWorkDir/regctl" ;
|
elif [[ -f "$ScriptWorkDir/regctl" ]]; then regbin="$ScriptWorkDir/regctl" ;
|
||||||
else
|
else
|
||||||
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetDep
|
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetRegctl
|
||||||
if [[ "$GetDep" =~ [yY] ]] ; then
|
if [[ "$GetRegctl" =~ [yY] ]] ; then
|
||||||
# Check architecture
|
binary_downloader "regctl" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
|
||||||
case "$(uname --machine)" in
|
[[ -f "$ScriptWorkDir/regctl" ]] && regbin="$ScriptWorkDir/regctl"
|
||||||
x86_64|amd64) architecture="amd64" ;;
|
else printf "\n%bDependency missing, exiting.%b\n" "$c_red" "$c_reset" ; exit 1 ;
|
||||||
arm64|aarch64) architecture="arm64";;
|
|
||||||
*) echo "Architecture not supported, exiting." ; exit 1;;
|
|
||||||
esac
|
|
||||||
RegUrl="https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$architecture"
|
|
||||||
if [[ $(command -v curl) ]]; then curl -L $RegUrl > "$ScriptWorkDir/regctl" ; chmod +x "$ScriptWorkDir/regctl" ; regbin="$ScriptWorkDir/regctl" ;
|
|
||||||
elif [[ $(command -v wget) ]]; then wget $RegUrl -O "$ScriptWorkDir/regctl" ; chmod +x "$ScriptWorkDir/regctl" ; regbin="$ScriptWorkDir/regctl" ;
|
|
||||||
else
|
|
||||||
printf "%s\n" "curl/wget not available - get regctl manually from the repo link, quitting."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
printf "%s\n" "Dependency missing, quitting."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Final check if binary is correct
|
# Final check if binary is correct
|
||||||
|
|
@ -210,12 +247,6 @@ else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for jq binary
|
|
||||||
if [[ ! $(command -v jq) ]] ; then
|
|
||||||
printf "%s\n" "No jq binary, please install jq and try again, exiting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Numbered List function
|
# Numbered List function
|
||||||
options() {
|
options() {
|
||||||
num=1
|
num=1
|
||||||
|
|
@ -315,17 +346,17 @@ if [ -n "$GotUpdates" ] ; then
|
||||||
# Extract labels and metadata
|
# Extract labels and metadata
|
||||||
ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}')
|
ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}')
|
||||||
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
ContPath=$(jq -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
|
ContPath=$(jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
|
||||||
[ "$ContPath" == "null" ] && ContPath=""
|
[ "$ContPath" == "null" ] && ContPath=""
|
||||||
ContConfigFile=$(jq -r '."com.docker.compose.project.config_files"' <<< "$ContLabels")
|
ContConfigFile=$(jqbin -r '."com.docker.compose.project.config_files"' <<< "$ContLabels")
|
||||||
[ "$ContConfigFile" == "null" ] && ContConfigFile=""
|
[ "$ContConfigFile" == "null" ] && ContConfigFile=""
|
||||||
ContName=$(jq -r '."com.docker.compose.service"' <<< "$ContLabels")
|
ContName=$(jqbin -r '."com.docker.compose.service"' <<< "$ContLabels")
|
||||||
[ "$ContName" == "null" ] && ContName=""
|
[ "$ContName" == "null" ] && ContName=""
|
||||||
ContEnv=$(jq -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels")
|
ContEnv=$(jqbin -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels")
|
||||||
[ "$ContEnv" == "null" ] && ContEnv=""
|
[ "$ContEnv" == "null" ] && ContEnv=""
|
||||||
ContUpdateLabel=$(jq -r '."mag37.dockcheck.update"' <<< "$ContLabels")
|
ContUpdateLabel=$(jqbin -r '."mag37.dockcheck.update"' <<< "$ContLabels")
|
||||||
[ "$ContUpdateLabel" == "null" ] && ContUpdateLabel=""
|
[ "$ContUpdateLabel" == "null" ] && ContUpdateLabel=""
|
||||||
ContRestartStack=$(jq -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels")
|
ContRestartStack=$(jqbin -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels")
|
||||||
[ "$ContRestartStack" == "null" ] && ContRestartStack=""
|
[ "$ContRestartStack" == "null" ] && ContRestartStack=""
|
||||||
|
|
||||||
# Checking if compose-values are empty - hence started with docker run
|
# Checking if compose-values are empty - hence started with docker run
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue