install script

This commit is contained in:
Chris Wanstrath 2026-03-10 16:30:28 -07:00
parent 3652ce9fad
commit b71b3d12b4
3 changed files with 82 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
# bin # bin
shout shout
dist/
# Binaries for programs and plugins # Binaries for programs and plugins
*.exe *.exe

View File

@ -1,7 +1,12 @@
.PHONY: build test unit integration clean .PHONY: build test unit integration clean dist release
VERSION ?= $(shell git describe --tags --always --dirty)
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION)"
GITEA_URL := https://git.nose.space
REPO := defunkt/go-shout
build: build:
go build -o shout . go build $(LDFLAGS) -o shout .
test: unit integration test: unit integration
@ -13,6 +18,33 @@ integration: build
clean: clean:
rm -f shout rm -f shout
rm -rf dist
dist: clean
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o dist/shout-darwin-arm64 .
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o dist/shout-linux-amd64 .
release: dist
@test -n "$(TAG)" || (echo "usage: make release TAG=v0.1.0" && exit 1)
git tag $(TAG)
git push origin $(TAG)
@echo "Creating release $(TAG)..."
@RELEASE_ID=$$(curl -sf \
-X POST \
-H "Authorization: token $${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"tag_name":"$(TAG)","name":"$(TAG)"}' \
"$(GITEA_URL)/api/v1/repos/$(REPO)/releases" | \
python3 -c "import sys,json; print(json.load(sys.stdin)['id'])") && \
for f in dist/shout-*; do \
echo "Uploading $$f..."; \
curl -sf \
-X POST \
-H "Authorization: token $${GITEA_TOKEN}" \
-F "attachment=@$$f" \
"$(GITEA_URL)/api/v1/repos/$(REPO)/releases/$$RELEASE_ID/assets?name=$$(basename $$f)" > /dev/null; \
done
@echo "Released $(TAG): $(GITEA_URL)/$(REPO)/releases/tag/$(TAG)"
install: build install: build
sudo cp ./shout /usr/local/bin sudo cp ./shout /usr/local/bin

46
install.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/sh
set -e
REPO="defunkt/go-shout"
GITEA_URL="https://git.nose.space"
INSTALL_DIR="/usr/local/bin"
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH" && exit 1 ;;
esac
BINARY="shout-${OS}-${ARCH}"
# Get latest release tag
TAG=$(curl -sf "${GITEA_URL}/api/v1/repos/${REPO}/releases/latest" | \
grep -o '"tag_name":"[^"]*"' | head -1 | cut -d'"' -f4)
if [ -z "$TAG" ]; then
echo "Error: could not find latest release"
exit 1
fi
echo "Installing shout ${TAG}..."
curl -sfL "${GITEA_URL}/${REPO}/releases/download/${TAG}/${BINARY}" -o shout
if [ ! -s shout ]; then
echo "Error: no binary available for ${OS}/${ARCH}"
rm -f shout
exit 1
fi
chmod +x shout
if [ -w "$INSTALL_DIR" ]; then
mv shout "${INSTALL_DIR}/shout"
else
sudo mv shout "${INSTALL_DIR}/shout"
fi
echo "Installed shout ${TAG} to ${INSTALL_DIR}/shout"