-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·137 lines (113 loc) · 3.75 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·137 lines (113 loc) · 3.75 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
set -euo pipefail
RELEASES_URL="https://api.gitkraken.dev/releases/production/linux/x64/RELEASES"
force_run=false
bump_pkgrel=false
usage() {
cat <<'USAGE'
Usage: ./update.sh [options]
Options:
-f, --force Run even if pkgver matches upstream (no pkgrel bump).
-p, --bump-pkgrel Increment pkgrel when pkgver matches upstream.
-h, --help Show this help text.
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
-f | --force)
force_run=true
;;
-p | --bump-pkgrel)
bump_pkgrel=true
;;
-h | --help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 1
;;
esac
shift
done
echo "Fetching latest GitKraken release metadata..."
release_data=$(curl -fsSL "$RELEASES_URL") || {
echo "Failed to download release metadata" >&2
exit 1
}
if command -v jq >/dev/null 2>&1; then
latest_version=$(printf '%s' "$release_data" | jq -r '.name')
else
latest_version=$(printf '%s' "$release_data" | sed -n 's/.*"name":"\([^"]*\)".*/\1/p' | head -n1)
fi
if [[ -z "${latest_version:-}" || "${latest_version}" == "null" ]]; then
echo "Unable to determine the latest GitKraken version" >&2
exit 1
fi
echo "Latest upstream version: ${latest_version}"
pushd gitkraken-aur >/dev/null
trap 'popd >/dev/null' EXIT
update_field() {
local key="$1"
local value="$2"
tmp=$(mktemp)
awk -v key="$key" -v value="$value" '{ if ($0 ~ "^" key "=") { print key "=" value } else { print } }' PKGBUILD >"$tmp"
mv "$tmp" PKGBUILD
}
current_version=$(grep '^pkgver=' PKGBUILD | cut -d= -f2)
current_pkgrel=$(grep '^pkgrel=' PKGBUILD | cut -d= -f2)
if [[ "$current_version" == "$latest_version" ]]; then
if [[ "$bump_pkgrel" == true ]]; then
if [[ "$current_pkgrel" =~ ^[0-9]+$ ]]; then
new_pkgrel=$((current_pkgrel + 1))
echo "Incrementing pkgrel from ${current_pkgrel} to ${new_pkgrel}"
update_field pkgrel "$new_pkgrel"
else
echo "Current pkgrel (${current_pkgrel}) is not numeric; aborting." >&2
exit 1
fi
elif [[ "$force_run" == true ]]; then
echo "Pkgver matches upstream; continuing due to --force."
else
printf 'GitKraken %s is already packaged.\n\n' "$current_version"
exit 0
fi
else
echo "Updating PKGBUILD from ${current_version} to ${latest_version}"
update_field pkgver "$latest_version"
update_field pkgrel 1
export PREVIOUS_VERSION="$current_version"
fi
echo "Refreshing checksums"
updpkgsums
# updpkgsums only regenerates checksums for the build host's architecture, so the
# aarch64 tarball is never hashed on the x86_64 update runner. Compute it directly
# (just hashing a download, no emulation needed) and splice it into the PKGBUILD.
echo "Refreshing aarch64 checksum"
arm64_tarball_url="https://api.gitkraken.dev/releases/production/linux/arm64/${latest_version}/gitkraken-aarch64.tar.gz"
arm64_sum=$(curl -fsSL "$arm64_tarball_url" | sha256sum | cut -d' ' -f1)
if [[ -z "${arm64_sum}" || ${#arm64_sum} -ne 64 ]]; then
echo "Failed to compute aarch64 checksum" >&2
exit 1
fi
sed -i "s|^sha256sums_aarch64=.*|sha256sums_aarch64=('${arm64_sum}')|" PKGBUILD
echo "Removing previous build artifacts"
rm -rf pkg/ src/ ./*.pkg.tar.zst ./*.tar.gz
echo "Building package to validate sources"
makepkg --syncdeps --cleanbuild --noconfirm
echo "Regenerating .SRCINFO"
makepkg --printsrcinfo >.SRCINFO
if [[ -n "${GITHUB_ENV:-}" ]]; then
printf 'NEW_VERSION=%s\n' "$latest_version" >>"$GITHUB_ENV"
printf 'PREVIOUS_VERSION=%s\n' "${PREVIOUS_VERSION:-$current_version}" >>"$GITHUB_ENV"
fi
echo "Cleaning up build artifacts"
rm -rf pkg/ src/ ./*.pkg.tar.zst ./*.tar.gz
final_pkgver=$(grep '^pkgver=' PKGBUILD | cut -d= -f2)
final_pkgrel=$(grep '^pkgrel=' PKGBUILD | cut -d= -f2)
printf 'PKGBUILD now at %s-%s. Review changes and commit manually.\n' "$final_pkgver" "$final_pkgrel"
trap - EXIT
popd >/dev/null
printf '\nAll done!\n'