Compare commits

..

7 Commits

Author SHA1 Message Date
mag37
1490c97a87 Merge pull request #17 from mag37/dev
## Code Cleaning
- printf formatting fixes
- read formatting fixes
- find/replace instead of sed
- directly check error on regctl instead of indirectly 
- safer array-checks (not expanding without index)
2023-02-12 19:47:15 +01:00
mag
53f8e8cdf9 code cleaning
printf formatting fixes
read formatting fixes
find/replace instead of sed
directly check error on regctl instead of indirectly
safer array-checks (not expanding without index)
2023-02-12 19:40:42 +01:00
mag37
b955649a5d BugSquash
Added note about fixed `${PWD}` breakage.
2023-02-12 06:32:10 +01:00
mag37
a2ffff2df2 BugSquash
Added note about fixed `${PWD}` breakage.
2023-02-12 06:30:18 +01:00
mag37
b9cfa851bd cd to compose-file extras
Added some error handling of the new cd-line, if the cd breaks for some reason that container will be skipped with a message.
2023-02-11 23:46:56 +01:00
mag37
555e472528 Merge pull request #16 from F0x06/relative_path_cd
cd to the compose-file directory before bringing the container up.
2023-02-11 23:41:56 +01:00
F0x06
0dfc8ca04f Make sure to be in the same folder as 'docker-compose.yml' file before pull & up -d 2023-02-11 21:18:55 +01:00
2 changed files with 20 additions and 16 deletions

View File

@@ -63,7 +63,8 @@ Containers need to be manually stopped, removed and created again to run on the
- ~~Old `docker-compose` binary-check sometimes returned false error~~
- ~~Stacks gets updated as whole, even if only one service is chosen.~~
- ~~Path broken occationally (from inspect) - probably due to old docker-compose binary.~~
- ~~Script breaks if one of the chosen containers are a `docker run` container.
- ~~Script breaks if one of the chosen containers are a `docker run` container.~~
- ~~Using relative paths for volumes eg. `${PWD}/data:data` will create the volumes where you stand.~~
### :hammer: Known issues
- ~~No granular choice of what to update (except initial name filter).~~

View File

@@ -1,10 +1,10 @@
#!/bin/bash
VERSION="v0.1.6"
VERSION="v0.1.7"
Github="https://github.com/mag37/dockcheck"
### Check if there's a new release of the script:
LatestRelease="$(curl -s -r 0-30 https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
[ "$VERSION" != "$LatestRelease" ] && printf "New version available! Latest: "$LatestRelease" - Local: "$VERSION" \nGrab it here: "$Github" \n\n"
[ "$VERSION" != "$LatestRelease" ] && printf "New version available! Latest: %s - Local: %s \nGrab it here: %s \n\n" "$LatestRelease" "$VERSION" "$Github"
### Help Function:
Help() {
@@ -38,7 +38,7 @@ elif [[ -f "./regctl" ]]; then
regbin="./regctl"
else
printf "Required dependency 'regctl' missing, do you want it downloaded? y/[n] "
read GetDep
read -r GetDep
if [ "$GetDep" != "${GetDep#[Yy]}" ]; then
### Check arch:
case "$(uname --machine)" in
@@ -79,14 +79,16 @@ done
### Choose from list -function:
choosecontainers() {
while [[ "$ChoiceClean" =~ [A-Za-z] || -z "$ChoiceClean" ]]; do
read -p "Enter number(s) separated by comma, [q] to quit: " Choice
read -r -p "Enter number(s) separated by comma, [q] to quit: " Choice
if [[ "$Choice" =~ [qQnN] ]] ; then
exit 0
elif [ "$Choice" == "0" ] ; then
SelectedUpdates=( "${NumberedUpdates[@]:1}" )
ChoiceClean=$(echo "$Choice" |sed 's/[,.:;]/ /g')
ChoiceClean=${Choice//[,.:;]/ }
# ChoiceClean=$(echo "$Choice" |sed 's/[,.:;]/ /g')
else
ChoiceClean=$(echo "$Choice" |sed 's/[,.:;]/ /g')
ChoiceClean=${Choice//[,.:;]/ }
# ChoiceClean=$(echo "$Choice" |sed 's/[,.:;]/ /g')
for s in $ChoiceClean; do
SelectedUpdates+=( "${NumberedUpdates[$s]}" )
done
@@ -102,9 +104,8 @@ for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
printf ". "
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null)
# Add container to GotErrors if regctl encounter problems.
if [ $? -eq 0 ] ; then
### Checking for errors while setting the variable:
if RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null) ; then
if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
else
GotErrors+=("$i")
@@ -121,17 +122,17 @@ unset IFS
NumberedUpdates=(ALL "${GotUpdates[@]}")
### List what containers got updates or not
if [ -n "$NoUpdates" ] ; then
if [[ -n ${NoUpdates[*]} ]] ; then
printf "\n\033[32;1mContainers on latest version:\033[0m\n"
printf "%s\n" "${NoUpdates[@]}"
fi
if [ -n "$GotErrors" ] ; then
if [[ -n ${GotErrors[*]} ]] ; then
printf "\n\033[33;1mContainers with errors, wont get updated:\033[0m\n"
printf "%s\n" "${GotErrors[@]}"
fi
if [ -n "$GotUpdates" ] ; then
if [[ -n ${GotUpdates[*]} ]] ; then
printf "\n\033[31;1mContainers with updates available:\033[0m\n"
[ -z "$UpdYes" ] && options || printf "%s\n" "${GotUpdates[@]}"
[[ -z "$UpdYes" ]] && options || printf "%s\n" "${GotUpdates[@]}"
fi
### Optionally get updates if there's any
@@ -152,10 +153,10 @@ if [ -n "$GotUpdates" ] ; then
if [ -z "$ContPath" ] ; then
if [ "$DrUp" == "yes" ] ; then
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
docker pull $ContImage
docker pull "$ContImage"
printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
else
printf "\n\033[33;1m$i\033[0m has no compose labels, probably started with docker run - \033[33;1mskipping\033[0m\n\n"
printf "\n\033[33;1m%s\033[0m has no compose labels, probably started with docker run - \033[33;1mskipping\033[0m\n\n" "$i"
fi
continue
fi
@@ -165,6 +166,8 @@ if [ -n "$GotUpdates" ] ; then
else
ComposeFile="$ContPath/$ContConfigFile"
fi
### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data
cd "$(dirname "${ComposeFile}")" || { echo "Path error - skipping $i" ; continue ; }
$DockerBin -f "$ComposeFile" pull "$ContName"
$DockerBin -f "$ComposeFile" up -d "$ContName"
done