-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·32 lines (24 loc) · 912 Bytes
/
update.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
#!/bin/bash
set -euo pipefail
file="formula/${1}.rb"
new_version="${2}"
version_pattern="v[0-9]*\.[0-9]*\.[0-9]*"
old_version="$(grep "version \"${version_pattern}\"" "${file}" | grep -o "${version_pattern}")"
formula="$(cat "${file}")"
echo "${formula//${old_version}/${new_version}}" > "${file}"
url_pattern="https.*\.gz"
for url in $(grep "url \"${url_pattern}\"" "${file}" | grep -o "${url_pattern}")
do
base_url="$(echo "${url}" | grep -o "https.*${version_pattern}/")"
tar="${url//${base_url}/}"
curl -sLo "${tar}" "${base_url//${new_version}/${old_version}}${tar}"
old_sha="$(shasum -a 256 "${tar}")"
old_sha="${old_sha// ${tar}/}"
rm "${tar}"
curl -sLo "${tar}" "${base_url}${tar}"
new_sha="$(shasum -a 256 "${tar}")"
new_sha="${new_sha// ${tar}/}"
rm "${tar}"
formula="$(cat "${file}")"
echo "${formula//${old_sha}/${new_sha}}" > "${file}"
done