-
Notifications
You must be signed in to change notification settings - Fork 2
/
homebrew_check_latest_release.sh
executable file
·92 lines (75 loc) · 2.5 KB
/
homebrew_check_latest_release.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
#!/bin/bash
set -e
# echo to stderr: https://stackpointer.io/script/shell-script-echo-to-stderr/355/
# get_latest_release from here https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
get_latest_release() {
curl -L --silent "$1" | jq -r '.[] | select(.tag_name != "debs") | limit(1; .) | .tag_name' | head -n1
}
SPECFILE=$(find "$(pwd)" -type f -name '*.rb' | head -n1)
if [ -z "${SPECFILE}" ]; then
echo "Failed to find specfile, bailing!"
exit 1
else
echo "SPECFILE: ${SPECFILE}"
fi
LATEST="$(get_latest_release "https://api.github.com/repos/kanidm/kanidm/releases")"
# grab the update url from the spec file
# URL=$(grep -E homepage "${SPECFILE}" | awk '{print $NF}' | tr -d '"')
# if [ -z "${URL}" ]; then
# echo "Failed to find check URL, bailing!"
# exit 1
# else
# echo "Check URL: ${URL}"
# fi
# pull the latest version
# LATEST="$(curl -sL "${URL}" | jq -r '.tag_name')"
if [ -z "${LATEST}" ]; then
echo "Failed to find latest version, bailing!"
exit 1
else
# echo "::set-env name=LATEST::${LATEST}"
echo "Latest version ${LATEST}"
fi
CURRENT=$(grep -E 'url \"+' "${SPECFILE}" | awk '{print $NF}' | tr -d '"')
if [ -z "${CURRENT}" ]; then
echo "Failed to find current version, bailing!"
exit 1
fi
if [ "${CURRENT}" == "${LATEST}" ]; then
echo "No change in version, quitting."
exit
else
echo "Version going from '${CURRENT}' to '${LATEST}'"
fi
# pull the download url from the spec file and update it
echo "Grabbing download URL"
DOWNLOAD_URL=$(grep -E 'url \"http.*' "${SPECFILE}" | awk '{print $NF}' | tr -d '"' | sed -E "s/#\{version\}/$LATEST/g")
if [ -z "${DOWNLOAD_URL}" ]; then
echo "Failed to find download URL, bailing!"
exit 1
else
echo "Download URL: ${DOWNLOAD_URL}"
fi
echo "Grabbing filehash"
# calculate the shasum based on the file
FILEHASH=$(curl -L --silent "${DOWNLOAD_URL}" | shasum -a 256 | awk '{print $1}')
if [ -z "${FILEHASH}" ]; then
echo "Couldn't get file hash, bailing"
exit 1
else
echo "Hash: ${FILEHASH}"
fi
echo "Updating file: ${SPECFILE}"
# updates the file
sed -i'' -E "s/version \\\".*/version \"${LATEST}\"/g" "${SPECFILE}"
sed -i'' -E "s/sha256 \\\".*/sha256 \"${FILEHASH}\"/g" "${SPECFILE}"
DIFF_LINES="$(git diff | wc -l)"
if [ "${DIFF_LINES}" -ne 0 ]; then
echo "Changed, woo!"
else
echo "No changes required."
fi
echo "New script below"
echo "#####################################################"
cat "${SPECFILE}"
echo "#####################################################"