-
Notifications
You must be signed in to change notification settings - Fork 8
/
check_version.sh
executable file
·101 lines (84 loc) · 2.44 KB
/
check_version.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
CHECKS=()
# Check for commands used in this script
command -v curl >/dev/null || CHECKS+=("curl")
command -v jq >/dev/null || CHECKS+=("jq")
command -v grep >/dev/null || CHECKS+=("grep")
command -v docker >/dev/null || CHECKS+=("docker")
command -v make >/dev/null || CHECKS+=("make")
if [ $CHECKS ]
then
echo "Please install the following programs for your platform:"
echo ${CHECKS[@]}
exit 1
fi
COMPOSE_DIR=${COMPOSE_DIR:-${1:-.}}
NUXEO_ENV="${COMPOSE_DIR}/.env"
IMAGE_NAME="nuxeo/nuxeo"
DOCKER_PRIVATE="docker-private.packages.nuxeo.com"
LTS_IMAGE="${DOCKER_PRIVATE}/${IMAGE_NAME}:"
CLOUD_IMAGE="docker.packages.nuxeo.com/${IMAGE_NAME}:"
FROM_IMAGE=$(grep '^NUXEO_IMAGE' ${NUXEO_ENV} | tail -n 1 | cut -d '=' -f2)
IMAGE_DESC="Unknown"
case ${FROM_IMAGE}
in
${LTS_IMAGE}*)
IMAGE_DESC="LTS"
;;
${CLOUD_IMAGE}*)
IMAGE_DESC="Cloud"
;;
*)
IMAGE_DESC="Unknown"
;;
esac
SONATYPE_AUTH=""
if [[ "${IMAGE_DESC}" == "LTS" ]]
then
echo ""
echo "Your image is hosted in a private repository. Please provide your Sonatype User Access Token"
echo " Get your token here: https://packages.nuxeo.com/#user/usertoken"
echo ""
# Prompt for Sonatype Login
while [ -z "${SONATYPE_USER}" ]
do
echo -n "Sonatype user token name code: "
read SONATYPE_USER
done
while [ -z "${SONATYPE_TOKEN}" ]
do
echo -n "Sonatype token pass code: "
read -s SONATYPE_TOKEN
echo ""
done
SONATYPE_AUTH="-u ${SONATYPE_USER}:${SONATYPE_TOKEN}"
fi
# Current Image SHA256
IMAGE_ID=$(docker inspect --format='{{index .RepoDigests 0}}' ${FROM_IMAGE})
IDS=(${IMAGE_ID//:/ })
TAGS=(${FROM_IMAGE//:/ })
# Search for latest with tag
LATEST=$(curl ${SONATYPE_AUTH} -fsSL -X GET "https://packages.nuxeo.com/service/rest/v1/search?name=${IMAGE_NAME}&format=docker&version=${TAGS[1]}")
REPO_SHA=$(echo ${LATEST} | jq -r '.items[].assets[].checksum.sha256')
REPO_TAG=$(echo ${LATEST} | jq -r '.items[].version')
REPO=$(echo ${LATEST} | jq -r '.items[].repository')
cat << EOM
Local Configuration
Label: ${FROM_IMAGE}
Type: ${IMAGE_DESC}
ID: ${IDS[1]}
Tag: ${TAGS[1]}
Repository Image
Repo: ${REPO}
ID: ${REPO_SHA}
Tag: ${REPO_TAG}
EOM
if [[ -n "${IDS[1]}" && -n "${REPO_SHA}" && "${REPO_SHA}" != "${IDS[1]}" ]]
then
echo -n "It appears there is a newer image available. Pull image and rebuild? y/n [y]: "
read UPDATE
if [[ -z "${UPDATE}" || "${UPDATE}" == "y" || "${UPDATE}" == "Y" ]]
then
make rebuild
fi
fi