forked from diddip21/openHAB-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade-images.sh
40 lines (35 loc) · 1.11 KB
/
upgrade-images.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
ERROR_FILE="/tmp/docker-images-update.error"
# make sure that docker is running
DOCKER_INFO_OUTPUT=$(docker info 2> /dev/null | grep "Containers:" | awk '{print $1}')
if [ "$DOCKER_INFO_OUTPUT" == "Containers:" ]
then
echo "Docker is running, so we can continue"
else
echo "Docker is not running, exiting"
exit 1
fi
# remove unused items
docker system prune -f> $ERROR_FILE
# get a list of docker images that are currently installed
IMAGES_WITH_TAGS=$(docker images | grep -v REPOSITORY | grep -v TAG | grep -v "<none>" | awk '{printf("%s:%s\n", $1, $2)}')
# run docker pull on all of the images
for IMAGE in $IMAGES_WITH_TAGS; do
echo "*****"
echo "Updating $IMAGE"
docker pull $IMAGE 2> $ERROR_FILE
if [ $? != 0 ]; then
ERROR=$(cat $ERROR_FILE | grep "not found")
if [ "$ERROR" != "" ]; then
echo "WARNING: Docker image $IMAGE not found in repository, skipping"
else
echo "ERROR: docker pull failed on image - $IMAGE"
exit 2
fi
fi
echo "*****"
echo
done
# did everything finish correctly? Then we can exit
echo "Docker images are now up to date"
exit 0