-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgitbucket-update
executable file
·56 lines (48 loc) · 1.67 KB
/
gitbucket-update
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
#!/usr/bin/env bash
################################################################################
# gitbucket-update - downloads the latest version of GitBucket, an open-source
# GitHub clone (https://github.com/gitbucket/gitbucket). This script is likely
# to be a bit brittle, but to the best of my knowledge there is no "clean" way
# to retrieve the latest project release from GitHub.
#
# Version 1
# Matthew Malensek <matt@malensek.net>
################################################################################
checksum() {
if command -v md5sum > /dev/null 2>&1; then
md5sum "${1}" | awk '{ print $1 }'
elif command -v md5 > /dev/null 2>&1; then
md5 -q "${1}"
else
>&2 echo "Error: no md5 utility found!"
fi
}
dir="${1}"
if [[ -z "${dir}" ]]; then
echo "No download directory set. Using $(pwd)"
fi
# Grab the latest gitbucket version's URL. -L follows the redirect.
url=$(curl -s -L 'https://github.com/gitbucket/gitbucket/releases/latest' \
| grep -o '"/gitbucket/gitbucket/releases/download/.*/gitbucket.war"' \
| sed 's|"\(.*\)"|\1|g')
ver=$(sed 's|.*/\(.*\)/gitbucket.war|\1|g' <<< "${url}")
dl="${ver}.war"
if [[ -n "${dir}" ]]; then
dl="${dir}/${dl}"
fi
if [[ -e "${dl}" ]]; then
echo "File already exists: ${dl}"
exit 1
fi
echo "Latest version: ${ver}"
echo "Downloading to: ${dl}"
curl -L "https://github.com/${url}" -o "${dl}"
echo "Verifying checksum..."
md5=$(curl -L "https://github.com/${url}.md5" | awk '{ print $1 }')
chk=$(checksum "${dl}")
if [[ "${md5}" != "${chk}" ]]; then
echo "ERROR: Checksum mismatch: ${chk}"
echo " Remote: ${md5}"
else
echo "Checksum ok: ${chk}"
fi