build: add update script

This commit is contained in:
2025-01-06 17:13:07 +02:00
parent a40e30edd2
commit 88784bd3cf
3 changed files with 30 additions and 0 deletions

View File

@@ -7,3 +7,8 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[Makefile]
tab_width = 4
indent_size = 4
indent_style = tab

2
Makefile Normal file
View File

@@ -0,0 +1,2 @@
update-hash:
@./scripts/update-hash.sh

23
scripts/update-hash.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
if [[ -z "$REPO_NAME" ]]; then
read -r -p "Enter repository name: " REPO_NAME
fi
VERSION=$(curl -s "https://api.github.com/repos/chenasraf/$REPO_NAME/releases/latest" | jq -r .tag_name)
URL="https://github.com/chenasraf/$REPO_NAME/archive/refs/tags/$VERSION.tar.gz"
echo "Version: $VERSION"
echo "URL: $URL"
curl -Ls "$URL" -o "$REPO_NAME-$VERSION.tar.gz"
echo -n "SHA256: "
hash=$(sha256sum "$REPO_NAME-$VERSION.tar.gz" | awk '{print $1}')
echo "$hash"
rm "$REPO_NAME-$VERSION.tar.gz"
sed -i.bak "s/sha256 \".*\"/sha256 \"$hash\"/" "Formula/$REPO_NAME.rb"
rm "Formula/$REPO_NAME.rb.bak"
sed -i.bak "s|\\burl \".*\"|url \"$URL\"|" "Formula/$REPO_NAME.rb"
rm "Formula/$REPO_NAME.rb.bak"