-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcheck-updates.sh
More file actions
executable file
·117 lines (98 loc) · 3.4 KB
/
check-updates.sh
File metadata and controls
executable file
·117 lines (98 loc) · 3.4 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
help=$(
cat <<'HEREDOC'
-----------------------------------------------------------------------------
This script updates the VERSION_SQLite3.txt and the Docker image.
-----------------------------------------------------------------------------
- Options:
--help : Shows this help.
--force : Force the update process even if the version is the same.
- Notes:
- By default, if there are no updates, the script exits with status 0.
HEREDOC
)
# Show help
echo "$@" | grep '\-h' >/dev/null && {
echo "$help"
exit 0
}
set -eu
# -----------------------------------------------------------------------------
# Constants
# -----------------------------------------------------------------------------
NAME_FILE_VERSION="VERSION_SQLite3.txt"
NAME_JSON_VERSION="SQLite3-shields.io-badge.json"
NAME_TAG_IMAGE_TEST="test-$(base64 </dev/urandom | tr -cd 'a-z0-9' | head -c 10)"
COLOR_RED='\033[0;31m'
COLOR_GREEN='\033[0;32m'
COLOR_NONE='\033[0m'
# -----------------------------------------------------------------------------
# Functions
# -----------------------------------------------------------------------------
# Colored echo function
echoGreen() {
echo -e "${COLOR_GREEN}${*}${COLOR_NONE}"
}
echoRed() {
echo -e "${COLOR_RED}${*}${COLOR_NONE}"
}
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
echoGreen "- Name of test image: ${NAME_TAG_IMAGE_TEST}"
# Include previous version of SQLite3
# shellcheck source=./VERSION_SQLite3.txt
source "$NAME_FILE_VERSION"
# Build and run container to get the version
echoGreen "- Building latest image to compare ..."
docker build --tag "$NAME_TAG_IMAGE_TEST" . || {
echo 'Fail to build the image.'
exit 1
}
VERSION_SQLITE3_LATEST=$(docker run --rm "$NAME_TAG_IMAGE_TEST" sqlite3 --version)
VERSION_OS_LATEST=$(docker run --rm "$NAME_TAG_IMAGE_TEST" cat /etc/alpine-release)
echoGreen "- Previous SQLite3 version was: ${VERSION_SQLITE3}"
echoGreen "- Current SQLite3 version is : ${VERSION_SQLITE3_LATEST}"
# Compare version
if [ "${VERSION_SQLITE3}" = "${VERSION_SQLITE3_LATEST}" ]; then
if [ "${VERSION_OS:-unknown}" = "${VERSION_OS_LATEST}" ]; then
echoGreen '- No update found.'
# If not forced then show message and exit
echo "$@" | grep 'force' >/dev/null || {
echo ' To force create image use "--force" option.'
exit 0
}
fi
fi
echo "$@" | grep 'force' >/dev/null || {
echoGreen "- Update found. Udating: ${NAME_FILE_VERSION} ..."
}
echo "$@" | grep 'force' >/dev/null && {
echoRed "- Force option detected. Forcing update the image ..."
}
# Get current short version of SQLite3
VERSION_SQLITE3_SHORT=$(echo "$VERSION_SQLITE3_LATEST" | awk '{print $1}')
# Update version (overwrites the version file)
echo "VERSION_SQLITE3='${VERSION_SQLITE3_LATEST}'" >"$NAME_FILE_VERSION" || {
echoRed '- Fail to update NAME_FILE_VERSION.'
exit 1
}
# Append the OS version
echo "VERSION_OS='${VERSION_OS_LATEST}'" >>"$NAME_FILE_VERSION" || {
echoRed '- Fail to update NAME_FILE_VERSION.'
exit 1
}
cat <<HEREDOC >"$NAME_JSON_VERSION"
{
"schemaVersion": 1,
"label": "SQLite",
"message": "${VERSION_SQLITE3_SHORT}",
"color": "blue",
"namedLogo": "sqlite"
}
HEREDOC
echoGreen "- Done."
git status | grep modified >/dev/null && {
echoGreen "- There are some changes. Please commit and push the changes."
}
echo