#!/usr/bin/env bash set -euo pipefail scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" repo_dir="$(dirname "$scripts_dir")" if [ "${LUPHOTO_IN_CONTAINER:-0}" != "1" ]; then exec "$scripts_dir/dev.sh" env LUPHOTO_IN_CONTAINER=1 VERSION="${VERSION:-}" ARCHES="${ARCHES:-}" bash scripts/package.sh "$@" fi cd "$repo_dir" git config --global --add safe.directory "$repo_dir" >/dev/null 2>&1 || true nfpm_version="v2.35.3" arches="${ARCHES:-amd64 arm64}" version="${VERSION:-}" if [ -z "$version" ]; then described="$(git describe --tags --always --dirty 2>/dev/null || echo unknown)" case "$described" in v[0-9]*) version="${described#v}" ;; *) version="0.0.0+git.${described}" ;; esac fi tools_dir="$repo_dir/.tools" if [ ! -x "$tools_dir/nfpm" ]; then echo "package: installing nfpm $nfpm_version" GOBIN="$tools_dir" GOTOOLCHAIN=local go install "github.com/goreleaser/nfpm/v2/cmd/nfpm@$nfpm_version" fi rm -rf dist mkdir -p dist for arch in $arches; do out="dist/linux_$arch" mkdir -p "$out" echo "package: luphoto $version linux/$arch" CGO_ENABLED=0 GOOS=linux GOARCH="$arch" go build -trimpath -ldflags "-s -w -X main.version=$version" -o "$out/luphoto" ./cmd/luphoto rm -rf dist/package mkdir -p dist/package cp "$out/luphoto" dist/package/luphoto VERSION="$version" GOARCH="$arch" "$tools_dir/nfpm" package --config packaging/nfpm.yaml --packager deb --target dist/ rm -rf dist/package name="luphoto_${version}_linux_${arch}" stage="dist/$name" mkdir -p "$stage/examples" cp "$out/luphoto" "$stage/luphoto" cp packaging/luphoto.service packaging/config.toml packaging/INSTALL.md README.md "$stage/" cp packaging/Caddyfile packaging/Caddyfile.serve packaging/nginx.conf packaging/nginx.serve.conf packaging/cloudflared.yml packaging/cloudflare.md "$stage/examples/" tar -C dist -czf "dist/$name.tar.gz" "$name" rm -rf "$stage" done ls -l dist/*.deb dist/*.tar.gz