Skip to content

Commit 2d758a5

Browse files
author
Евгений Балякин
committed
fix in install.sh
1 parent 3929a90 commit 2d758a5

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

install.sh

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -eu
44
REPO="balyakin/sudocheck"
55
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
66
TMP_DIR="${TMPDIR:-/tmp}/sudocheck-install"
7+
API_URL="https://api.github.com/repos/$REPO/releases/latest"
78

89
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
910
arch="$(uname -m)"
@@ -26,17 +27,56 @@ case "$arch" in
2627
;;
2728
esac
2829

29-
latest="$(curl -sSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | cut -d '"' -f 4)"
30-
archive="sudocheck_${os}_${arch}.tar.gz"
31-
base_url="https://github.com/$REPO/releases/download/$latest"
30+
release_json="$(curl -fsSL "$API_URL")"
31+
latest="$(printf '%s\n' "$release_json" | grep '"tag_name"' | cut -d '"' -f 4 | head -n 1)"
32+
archive_url="$(
33+
printf '%s\n' "$release_json" |
34+
grep '"browser_download_url":' |
35+
cut -d '"' -f 4 |
36+
grep "${os}_${arch}.*\\.tar\\.gz$" |
37+
head -n 1
38+
)"
39+
checksum_url="$(
40+
printf '%s\n' "$release_json" |
41+
grep '"browser_download_url":' |
42+
cut -d '"' -f 4 |
43+
grep '/checksums.txt$' |
44+
head -n 1
45+
)"
46+
47+
if [ -z "$latest" ]; then
48+
echo "could not determine latest release tag for $REPO" >&2
49+
exit 1
50+
fi
51+
52+
if [ -z "$archive_url" ]; then
53+
echo "could not find release archive for ${os}/${arch}" >&2
54+
echo "available assets:" >&2
55+
printf '%s\n' "$release_json" | grep '"browser_download_url":' | cut -d '"' -f 4 >&2
56+
exit 1
57+
fi
58+
59+
if [ -z "$checksum_url" ]; then
60+
echo "could not find checksums.txt in latest release" >&2
61+
exit 1
62+
fi
63+
64+
archive="$(basename "$archive_url")"
3265

3366
rm -rf "$TMP_DIR"
3467
mkdir -p "$TMP_DIR"
3568
cd "$TMP_DIR"
3669

37-
curl -sSLO "$base_url/$archive"
38-
curl -sSLO "$base_url/checksums.txt"
39-
grep "$archive" checksums.txt | sha256sum -c -
70+
curl -fsSLO "$archive_url"
71+
curl -fsSLO "$checksum_url"
72+
checksum_line="$(grep "[ *]$archive$" checksums.txt || true)"
73+
if [ -z "$checksum_line" ]; then
74+
echo "checksums.txt does not contain checksum for $archive" >&2
75+
echo "checksums.txt contents:" >&2
76+
cat checksums.txt >&2
77+
exit 1
78+
fi
79+
printf '%s\n' "$checksum_line" | sha256sum -c -
4080
tar xzf "$archive"
4181

4282
if [ -w "$INSTALL_DIR" ]; then
@@ -46,4 +86,3 @@ else
4686
fi
4787

4888
echo "sudocheck $latest installed to $INSTALL_DIR/sudocheck"
49-

0 commit comments

Comments
 (0)