Release / Build and publish (push) Successful in 22s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
85 lines
2.7 KiB
Bash
Executable File
85 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Installs lazysecrets from its releases: the archive for this OS and CPU,
|
|
# checked against the release's checksums.txt, into ~/.local/bin.
|
|
#
|
|
# curl -fsSL https://git.kebcloud.no/keb/lazysecrets/raw/branch/main/install.sh | sh
|
|
# curl -fsSL https://git.kebcloud.no/keb/lazysecrets/raw/branch/main/install.sh | sh -s -- v0.2.0
|
|
#
|
|
# LAZYSECRETS_INSTALL_DIR installs somewhere else. macOS and Linux, arm64
|
|
# and x86_64.
|
|
set -eu
|
|
|
|
repo=https://git.kebcloud.no/keb/lazysecrets
|
|
api=https://git.kebcloud.no/api/v1/repos/keb/lazysecrets
|
|
dir="${LAZYSECRETS_INSTALL_DIR:-$HOME/.local/bin}"
|
|
|
|
fail() {
|
|
echo "lazysecrets install: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
if command -v curl >/dev/null 2>&1; then
|
|
fetch() { curl -fsSL "$1"; }
|
|
download() { curl -fsSL -o "$2" "$1"; }
|
|
elif command -v wget >/dev/null 2>&1; then
|
|
fetch() { wget -qO- "$1"; }
|
|
download() { wget -qO "$2" "$1"; }
|
|
else
|
|
fail "needs curl or wget"
|
|
fi
|
|
|
|
case "$(uname -s)" in
|
|
Darwin) os=darwin ;;
|
|
Linux) os=linux ;;
|
|
*) fail "no release for $(uname -s); build it with: go install git.kebcloud.no/keb/lazysecrets/cmd/lazysecrets@latest" ;;
|
|
esac
|
|
case "$(uname -m)" in
|
|
x86_64 | amd64) arch=amd64 ;;
|
|
arm64 | aarch64) arch=arm64 ;;
|
|
*) fail "no release for $(uname -m)" ;;
|
|
esac
|
|
|
|
tag="${1:-}"
|
|
if [ -z "$tag" ]; then
|
|
tag=$(fetch "$api/releases/latest" | sed -n 's/.*"tag_name":"\([^"]*\)".*/\1/p') ||
|
|
fail "couldn't look up the latest release"
|
|
[ -n "$tag" ] || fail "couldn't look up the latest release"
|
|
fi
|
|
case "$tag" in
|
|
v*) ;;
|
|
*) tag="v$tag" ;;
|
|
esac
|
|
version="${tag#v}"
|
|
|
|
name="lazysecrets_${version}_${os}_${arch}"
|
|
tmp=$(mktemp -d)
|
|
trap 'rm -rf "$tmp"' EXIT
|
|
|
|
echo "Downloading lazysecrets $tag for $os/$arch"
|
|
download "$repo/releases/download/$tag/$name.tar.gz" "$tmp/$name.tar.gz" ||
|
|
fail "couldn't download $tag for $os/$arch: see $repo/releases"
|
|
download "$repo/releases/download/$tag/checksums.txt" "$tmp/checksums.txt" ||
|
|
fail "couldn't download $tag's checksums.txt"
|
|
|
|
want=$(awk -v f="$name.tar.gz" '$2 == f { print $1 }' "$tmp/checksums.txt")
|
|
[ -n "$want" ] || fail "$name.tar.gz isn't in checksums.txt"
|
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
got=$(sha256sum "$tmp/$name.tar.gz" | awk '{ print $1 }')
|
|
else
|
|
got=$(shasum -a 256 "$tmp/$name.tar.gz" | awk '{ print $1 }')
|
|
fi
|
|
[ "$got" = "$want" ] || fail "checksum mismatch for $name.tar.gz: the download is damaged or not the release"
|
|
|
|
tar -xzf "$tmp/$name.tar.gz" -C "$tmp"
|
|
mkdir -p "$dir"
|
|
# Replaced, not overwritten: a running lazysecrets keeps its binary.
|
|
cp "$tmp/$name/lazysecrets" "$dir/.lazysecrets.new"
|
|
chmod 755 "$dir/.lazysecrets.new"
|
|
mv -f "$dir/.lazysecrets.new" "$dir/lazysecrets"
|
|
echo "Installed $("$dir/lazysecrets" --version) in $dir"
|
|
|
|
case ":$PATH:" in
|
|
*":$dir:"*) ;;
|
|
*) echo "$dir isn't on your PATH: add it to your shell's profile, e.g. export PATH=\"$dir:\$PATH\"" ;;
|
|
esac
|