chooseRework,pruneAdd,regctlChecks
Fixes: - Checks if curl/wget exist to not get an empty `regctl` binary. - Extra check if `regctl` binary is functional before continuing. - changed shebang to `#!/usr/bin/env bash` for portability. - General cleaning. (y/n checks and space saving) New: - Rework of the `choosecontainers` function - `[aA]` to update ALL (was `0` before and part of the list/array) - numbers starting from 1 (instead of 0) - will prompt for new choice if picking numbers/letters out of bound. - `docker prune` option after completed updates. - additionally a`-p` flag for automatic update+prune, eg `./dockcheck.sh -yp` - Added [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license.
This commit is contained in:
parent
791933ffaa
commit
95a603cdc3
64
dockcheck.sh
64
dockcheck.sh
@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.1.7"
|
VERSION="v0.1.8"
|
||||||
Github="https://github.com/mag37/dockcheck"
|
Github="https://github.com/mag37/dockcheck"
|
||||||
|
|
||||||
### Check if there's a new release of the script:
|
### Check if there's a new release of the script:
|
||||||
@ -15,14 +15,16 @@ Help() {
|
|||||||
echo "-h Print this Help."
|
echo "-h Print this Help."
|
||||||
echo "-a|y Automatic updates, without interaction."
|
echo "-a|y Automatic updates, without interaction."
|
||||||
echo "-n No updates, only checking availability."
|
echo "-n No updates, only checking availability."
|
||||||
|
echo "-p Auto-Prune dangling images after update."
|
||||||
echo "-r Allow updating images for docker run, wont update the container"
|
echo "-r Allow updating images for docker run, wont update the container"
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "aynrh" options; do
|
while getopts "aynprh" options; do
|
||||||
case "${options}" in
|
case "${options}" in
|
||||||
a|y) UpdYes="yes" ;;
|
a|y) UpdYes="yes" ;;
|
||||||
n) UpdYes="no" ;;
|
n) UpdYes="no" ;;
|
||||||
r) DrUp="yes" ;;
|
r) DrUp="yes" ;;
|
||||||
|
p) PruneQ="yes" ;;
|
||||||
h|*) Help ; exit 0 ;;
|
h|*) Help ; exit 0 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -32,28 +34,31 @@ shift "$((OPTIND-1))"
|
|||||||
SearchName="$1"
|
SearchName="$1"
|
||||||
|
|
||||||
### Check if required binary exists in PATH or directory:
|
### Check if required binary exists in PATH or directory:
|
||||||
if [[ $(builtin type -P "regctl") ]]; then
|
if [[ $(builtin type -P "regctl") ]]; then regbin="regctl" ;
|
||||||
regbin="regctl"
|
elif [[ -f "./regctl" ]]; then regbin="./regctl" ;
|
||||||
elif [[ -f "./regctl" ]]; then
|
|
||||||
regbin="./regctl"
|
|
||||||
else
|
else
|
||||||
printf "Required dependency 'regctl' missing, do you want it downloaded? y/[n] "
|
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetDep
|
||||||
read -r GetDep
|
if [[ "$GetDep" =~ [yY] ]] ; then
|
||||||
if [ "$GetDep" != "${GetDep#[Yy]}" ]; then
|
|
||||||
### Check arch:
|
### Check arch:
|
||||||
case "$(uname --machine)" in
|
case "$(uname --machine)" in
|
||||||
x86_64|amd64) architecture="amd64" ;;
|
x86_64|amd64) architecture="amd64" ;;
|
||||||
arm64|aarch64) architecture="arm64";;
|
arm64|aarch64) architecture="arm64";;
|
||||||
*) echo "Architecture not supported, exiting." ; exit ;;
|
*) echo "Architecture not supported, exiting." ; exit 1;;
|
||||||
esac
|
esac
|
||||||
curl -L https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$architecture >./regctl
|
RegUrl="https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$architecture"
|
||||||
chmod 755 ./regctl
|
if [[ $(builtin type -P curl) ]]; then curl -L $RegUrl > ./regctl ; chmod +x ./regctl ; regbin="./regctl" ;
|
||||||
regbin="./regctl"
|
elif [[ $(builtin type -P wget) ]]; then wget $RegUrl -O ./regctl ; chmod +x ./regctl ; regbin="./regctl" ;
|
||||||
|
else
|
||||||
|
printf "%s\n" "curl/wget not available - get regctl manually from the repo link, quitting."
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
printf "%s\n" "Dependency missing, quitting."
|
printf "%s\n" "Dependency missing, quitting."
|
||||||
exit
|
exit 1
|
||||||
fi
|
fi
|
||||||
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; }
|
||||||
|
|
||||||
### Check docker compose binary:
|
### Check docker compose binary:
|
||||||
if docker compose version &> /dev/null ; then
|
if docker compose version &> /dev/null ; then
|
||||||
DockerBin="docker compose"
|
DockerBin="docker compose"
|
||||||
@ -64,13 +69,13 @@ elif docker -v &> /dev/null; then
|
|||||||
printf "%s\n" "'docker run' will ONLY update images, not the container itself."
|
printf "%s\n" "'docker run' will ONLY update images, not the container itself."
|
||||||
else
|
else
|
||||||
printf "%s\n" "No docker binaries available, exiting."
|
printf "%s\n" "No docker binaries available, exiting."
|
||||||
exit
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Numbered List -function:
|
### Numbered List -function:
|
||||||
options() {
|
options() {
|
||||||
num=0
|
num=1
|
||||||
for i in "${NumberedUpdates[@]}"; do
|
for i in "${GotUpdates[@]}"; do
|
||||||
echo "$num) $i"
|
echo "$num) $i"
|
||||||
((num++))
|
((num++))
|
||||||
done
|
done
|
||||||
@ -78,17 +83,21 @@ done
|
|||||||
|
|
||||||
### Choose from list -function:
|
### Choose from list -function:
|
||||||
choosecontainers() {
|
choosecontainers() {
|
||||||
while [[ "$ChoiceClean" =~ [A-Za-z] || -z "$ChoiceClean" ]]; do
|
while [[ -z "$ChoiceClean" ]]; do
|
||||||
read -r -p "Enter number(s) separated by comma, [q] to quit: " Choice
|
read -r -p "Enter number(s) separated by comma, [a] for all - [q] to quit: " Choice
|
||||||
if [[ "$Choice" =~ [qQnN] ]] ; then
|
if [[ "$Choice" =~ [qQnN] ]] ; then
|
||||||
exit 0
|
exit 0
|
||||||
elif [ "$Choice" == "0" ] ; then
|
elif [[ "$Choice" =~ [aAyY] ]] ; then
|
||||||
SelectedUpdates=( "${NumberedUpdates[@]:1}" )
|
SelectedUpdates=( "${GotUpdates[@]}" )
|
||||||
ChoiceClean=${Choice//[,.:;]/ }
|
ChoiceClean=${Choice//[,.:;]/ }
|
||||||
else
|
else
|
||||||
ChoiceClean=${Choice//[,.:;]/ }
|
ChoiceClean=${Choice//[,.:;]/ }
|
||||||
for s in $ChoiceClean; do
|
for CC in $ChoiceClean ; do
|
||||||
SelectedUpdates+=( "${NumberedUpdates[$s]}" )
|
if [[ "$CC" -lt 1 || "$CC" -gt $UpdCount ]] ; then # reset choice if out of bounds
|
||||||
|
echo "Number not in list: $CC" ; unset ChoiceClean ; break 1
|
||||||
|
else
|
||||||
|
SelectedUpdates+=( "${GotUpdates[$CC-1]}" )
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -116,8 +125,8 @@ NoUpdates=($(sort <<<"${NoUpdates[*]}"))
|
|||||||
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
|
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
|
||||||
GotErrors=($(sort <<<"${GotErrors[*]}"))
|
GotErrors=($(sort <<<"${GotErrors[*]}"))
|
||||||
unset IFS
|
unset IFS
|
||||||
### Create new Array to use for the numbered list:
|
### Define how many updates are available
|
||||||
NumberedUpdates=(ALL "${GotUpdates[@]}")
|
UpdCount="${#GotUpdates[@]}"
|
||||||
|
|
||||||
### List what containers got updates or not
|
### List what containers got updates or not
|
||||||
if [[ -n ${NoUpdates[*]} ]] ; then
|
if [[ -n ${NoUpdates[*]} ]] ; then
|
||||||
@ -169,6 +178,9 @@ if [ -n "$GotUpdates" ] ; then
|
|||||||
$DockerBin -f "$ComposeFile" pull "$ContName"
|
$DockerBin -f "$ComposeFile" pull "$ContName"
|
||||||
$DockerBin -f "$ComposeFile" up -d "$ContName"
|
$DockerBin -f "$ComposeFile" up -d "$ContName"
|
||||||
done
|
done
|
||||||
|
printf "\033[0;32mAll done!\033[0m\n"
|
||||||
|
[[ -z "$PruneQ" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " PruneQ
|
||||||
|
[[ "$PruneQ" =~ [yY] ]] && docker image prune -f
|
||||||
else
|
else
|
||||||
printf "\nNo updates installed, exiting.\n"
|
printf "\nNo updates installed, exiting.\n"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user