Something went wrong. Try again.
Reference server for Tieroute protocol.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136#!/usr/bin/env bash# Builds a rerouted release for Linux, amd64 and arm64, into dist/release/VERSION/:## rerouted-VERSION-linux-ARCH.tar.gz the binary, LICENSE, README.md, the settings example,# the man page, completions, and systemd units for a# binary in /usr/local/bin# SHA256SUMS the tarballs' checksums# rerouted_*.deb, rerouted-*.rpm, packages for apt, dnf, and pacman, made with nfpm# rerouted-*.pkg.tar.zst# latest.json {"version", "published", "notes"}, for the update check## scripts/release.sh VERSION such as 0.2.0 or 0.2.0-rc.1## It builds the committed tree (HEAD, or REF), not uncommitted changes. Nothing here is signed. The repositories that publish a release sign its packages and# SHA256SUMS with their own key. Needs Go only; nfpm is pinned below and built with Go.# env: REF (default HEAD), NOTES_URL (default: the GitHub release for vVERSION), SOURCE_DATE_EPOCH (default: the# last commit's time; file times in the packages and tarballs)set -euo pipefailcd "$(dirname "$0")/.."VERSION=${1:?usage: scripts/release.sh VERSION}[[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?$ ]] \ || { echo "$VERSION isn't a version like 0.2.0 or 0.2.0-rc.1" >&2; exit 1; }NFPM=github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.49.0NOTES_URL=${NOTES_URL:-https://github.com/rerouteholdings/rerouted/releases/tag/v$VERSION}REF=${REF:-HEAD}export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(git log -1 --format=%ct HEAD)}[ -z "$(git status --porcelain --untracked-files=no)" ] \ || echo "note: uncommitted changes aren't in the release; it builds $REF" >&2
OUT=$PWD/dist/release/$VERSIONSTAGE=dist/release/.stage-$VERSIONrm -rf "$OUT" "$STAGE"mkdir -p "$OUT" "$STAGE/bin" "$STAGE/src"STAGE=$(cd "$STAGE" && pwd)trap 'rm -rf "$STAGE"' EXITgit archive "$REF" | tar -x -C "$STAGE/src"cd "$STAGE/src"
echo "==> building rerouted $VERSION"LDFLAGS="-s -w -X github.com/rerouteholdings/rerouted/internal/version.Number=$VERSION"for arch in amd64 arm64; do CGO_ENABLED=0 GOOS=linux GOARCH=$arch go build -trimpath -ldflags "$LDFLAGS" -o "$STAGE/rerouted-linux-$arch" ./cmd/rerouteddone# One for this machine too, to write the shell completions.CGO_ENABLED=0 go build -trimpath -ldflags "$LDFLAGS" -o "$STAGE/bin/rerouted" ./cmd/reroutedGOBIN=$STAGE/bin go install "$NFPM"
# The settings example, for a packaged install.sed -e '1s|.*|# rerouted settings. sudo rerouted init writes /etc/rerouted/rerouted.env (or NAME.env, for rerouted@NAME), or copy this file there. Real environment variables override it.|' \ -e 's|^REROUTED_DATA_DIR=.*|REROUTED_DATA_DIR=/var/lib/rerouted|' .env.example > "$STAGE/rerouted.env.example"grep -q '^REROUTED_DATA_DIR=/var/lib/rerouted$' "$STAGE/rerouted.env.example" \ || { echo ".env.example has no REROUTED_DATA_DIR line to set" >&2; exit 1; }
# The man page and completions, when this version has them.EXTRA=()if [ -f docs/rerouted.1 ]; then gzip -9n < docs/rerouted.1 > "$STAGE/rerouted.1.gz" EXTRA+=("$STAGE/rerouted.1.gz /usr/share/man/man1/rerouted.1.gz")else echo "note: no docs/rerouted.1, so no man page" >&2fi# Each shell's script, if `rerouted completion SHELL` prints one. Run in an empty directory# with no settings, so an older binary that doesn't know the command can't start a server.complete_for() { # shell pattern local d; d=$(mktemp -d) if (cd "$d" && env -i PATH=/usr/bin:/bin "$STAGE/bin/rerouted" completion "$1") > "$STAGE/completion.$1" 2>/dev/null \ && grep -q -- "$2" "$STAGE/completion.$1"; then rm -rf "$d" return 0 fi rm -rf "$d" "$STAGE/completion.$1" return 1}mkdir -p "$STAGE/completions"if complete_for bash 'complete '; then mv "$STAGE/completion.bash" "$STAGE/completions/rerouted" EXTRA+=("$STAGE/completions/rerouted /usr/share/bash-completion/completions/rerouted")fiif complete_for zsh 'compdef'; then mv "$STAGE/completion.zsh" "$STAGE/completions/_rerouted" EXTRA+=("$STAGE/completions/_rerouted /usr/share/zsh/vendor-completions/_rerouted deb") EXTRA+=("$STAGE/completions/_rerouted /usr/share/zsh/site-functions/_rerouted rpm") EXTRA+=("$STAGE/completions/_rerouted /usr/share/zsh/site-functions/_rerouted archlinux")fiif complete_for fish 'complete -c'; then mv "$STAGE/completion.fish" "$STAGE/completions/rerouted.fish" EXTRA+=("$STAGE/completions/rerouted.fish /usr/share/fish/vendor_completions.d/rerouted.fish")fi[ -n "$(ls "$STAGE/completions")" ] || echo "note: rerouted has no completion command, so no completions" >&2
# nfpm's configuration, with those files added.cp packaging/nfpm.yaml "$STAGE/nfpm.yaml"for e in ${EXTRA[@]+"${EXTRA[@]}"}; do set -- $e printf ' - src: %s\n dst: %s\n file_info: { mode: 0644 }\n' "$1" "$2" >> "$STAGE/nfpm.yaml" [ -n "${3:-}" ] && printf ' packager: %s\n' "$3" >> "$STAGE/nfpm.yaml"done
# Tarballs, for installing by hand.if tar --version 2>/dev/null | grep -q bsdtar; then TAR=(env COPYFILE_DISABLE=1 tar --no-xattrs --no-mac-metadata --uid 0 --gid 0 --uname root --gname root)else TAR=(tar --owner=0 --group=0 --numeric-owner --sort=name --mtime="@$SOURCE_DATE_EPOCH")fifor arch in amd64 arm64; do name=rerouted-$VERSION-linux-$arch d=$STAGE/tar/$name mkdir -p "$d/systemd" install -m 755 "$STAGE/rerouted-linux-$arch" "$d/rerouted" install -m 644 LICENSE README.md "$STAGE/rerouted.env.example" "$d/" [ -f docs/rerouted.1 ] && install -m 644 docs/rerouted.1 "$d/" [ -n "$(ls "$STAGE/completions")" ] && cp -R "$STAGE/completions" "$d/" for u in rerouted.service rerouted@.service; do sed 's|/usr/bin/rerouted|/usr/local/bin/rerouted|g' "packaging/systemd/$u" > "$d/systemd/$u" done find "$d" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + 2>/dev/null \ || find "$d" -exec touch -h -t "$(date -u -r "$SOURCE_DATE_EPOCH" +%Y%m%d%H%M.%S)" {} + "${TAR[@]}" -czf "$OUT/$name.tar.gz" -C "$STAGE/tar" "$name"done(cd "$OUT" && if command -v sha256sum >/dev/null; then sha256sum rerouted-*.tar.gz; else shasum -a 256 rerouted-*.tar.gz; fi) > "$OUT/SHA256SUMS"
echo "==> packages"for arch in amd64 arm64; do for p in deb rpm archlinux; do # pacman's versions can't have a hyphen: 0.2.0-rc.1 is 0.2.0rc1 (as for Reroute), which # sorts before 0.2.0. v=$VERSION if [ "$p" = archlinux ] && [ "$VERSION" != "${VERSION%%-*}" ]; then pre=${VERSION#*-}; v=${VERSION%%-*}${pre//./}; fi ARCH=$arch VERSION=$v STAGE=$STAGE "$STAGE/bin/nfpm" package --config "$STAGE/nfpm.yaml" --packager "$p" --target "$OUT/" >/dev/null donedone
printf '{"version":"%s","published":"%s","notes":"%s"}\n' "$VERSION" "$(date -u +%F)" "$NOTES_URL" > "$OUT/latest.json"ls -1 "$OUT"echo "Built rerouted $VERSION in $OUT"