-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpi-pir-sensor
53 lines (47 loc) · 1.34 KB
/
rpi-pir-sensor
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
retry() {
local -r -i max_attempts="$1"; shift
local -r cmd="$@"
local -i attempt_num=1
until $cmd
do
if (( attempt_num == max_attempts ))
then
echo "Attempt $attempt_num failed and there are no more attempts left!"
exit 1
else
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..."
sleep $(( attempt_num++ ))
fi
done
}
#######################################
# Build Job: takes an ID parameter
# and a TAG parameter.
# - ID: matches projects github and
# dockerhub repository.
# - TAG: What tag to use when pushing to
# dockerhub. Default to "latest"
#######################################
set -e
ID="goliatone/rpi-pir-sensor"
CID=$(docker ps | grep $ID | awk '{print $1}')
retry 5 docker pull $ID
echo "Checking for $CID"
for im in $CID
do
LATEST=`docker inspect --format "{{.Id}}" --type image $ID`
RUNNING=`docker inspect --format "{{.Image}}" $im`
NAME=`docker inspect --format '{{.Name}}' $im | sed "s/\///g"`
echo "Latest:" $LATEST
echo "Running:" $RUNNING
if [ "$RUNNING" != "$LATEST" ];then
echo "upgrading $NAME"
# stop docker
./$NAME-docker-stop
# start docker
./$NAME-docker-start
else
echo "$NAME up to date"
fi
done