skyview/scripts/build-deb.sh
Ole-Morten Duesund 802e964cc0 Add automatic changelog generation to Debian package build
The build script now automatically generates a proper Debian changelog from
git history between version tags. Features:

- Proper Debian changelog format with version, urgency, and timestamp
- Automatic version detection using git describe --tags
- Change list from previous version tag to current commit
- Compressed storage as per Debian standards (changelog.gz)
- Fallback logic for initial releases when no previous tags exist

The changelog is installed to /usr/share/doc/skyview/changelog.gz following
Debian packaging best practices.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-24 21:45:18 +02:00

150 lines
No EOL
4.3 KiB
Bash
Executable file

#!/bin/bash
set -e
# Build script for creating Debian package
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
BUILD_DIR="$PROJECT_DIR/build"
DEB_DIR="$PROJECT_DIR/debian"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
echo_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
echo_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Clean previous builds
echo_info "Cleaning previous builds..."
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
# Change to project directory
cd "$PROJECT_DIR"
# Build the applications
echo_info "Building SkyView applications..."
export CGO_ENABLED=0
export GOOS=linux
export GOARCH=amd64
VERSION=$(git describe --tags --always --dirty)
LDFLAGS="-w -s -X main.version=$VERSION"
# Build main skyview binary
echo_info "Building skyview..."
if ! go build -ldflags="$LDFLAGS" \
-o "$DEB_DIR/usr/bin/skyview" \
./cmd/skyview; then
echo_error "Failed to build skyview"
exit 1
fi
# Build beast-dump utility
echo_info "Building beast-dump..."
if ! go build -ldflags="$LDFLAGS" \
-o "$DEB_DIR/usr/bin/beast-dump" \
./cmd/beast-dump; then
echo_error "Failed to build beast-dump"
exit 1
fi
echo_info "Built binaries:"
echo_info " skyview: $(file "$DEB_DIR/usr/bin/skyview")"
echo_info " beast-dump: $(file "$DEB_DIR/usr/bin/beast-dump")"
# Set executable permissions
chmod +x "$DEB_DIR/usr/bin/skyview"
chmod +x "$DEB_DIR/usr/bin/beast-dump"
# Generate changelog from git history
echo_info "Generating changelog from git history..."
CHANGELOG_DIR="$DEB_DIR/usr/share/doc/skyview"
mkdir -p "$CHANGELOG_DIR"
# Get the current version and previous version
CURRENT_VERSION=$(git describe --tags --always)
PREV_VERSION=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_VERSION" ]; then
echo_info "Generating changelog from $PREV_VERSION to $CURRENT_VERSION"
# Create changelog with proper Debian format
{
echo "skyview ($CURRENT_VERSION) unstable; urgency=medium"
echo ""
echo " Changes since $PREV_VERSION:"
git log --pretty=format:" * %s" "$PREV_VERSION..HEAD" | head -20
echo ""
echo " -- $(git config user.name) <$(git config user.email)> $(date -R)"
echo ""
} > "$CHANGELOG_DIR/changelog"
else
echo_info "No previous version found, generating initial changelog"
# Create initial changelog
{
echo "skyview ($CURRENT_VERSION) unstable; urgency=medium"
echo ""
echo " * Initial release"
echo " * Multi-source ADS-B aircraft tracker with Beast format support"
echo ""
echo " -- $(git config user.name) <$(git config user.email)> $(date -R)"
echo ""
} > "$CHANGELOG_DIR/changelog"
fi
# Compress changelog as per Debian standards
gzip -9 "$CHANGELOG_DIR/changelog"
echo_info "Generated changelog: $CHANGELOG_DIR/changelog.gz"
# Get package info
VERSION=$(grep "Version:" "$DEB_DIR/DEBIAN/control" | cut -d' ' -f2)
PACKAGE=$(grep "Package:" "$DEB_DIR/DEBIAN/control" | cut -d' ' -f2)
ARCH=$(grep "Architecture:" "$DEB_DIR/DEBIAN/control" | cut -d' ' -f2)
DEB_FILE="${PACKAGE}_${VERSION}_${ARCH}.deb"
echo_info "Creating Debian package: $DEB_FILE"
# Calculate installed size
INSTALLED_SIZE=$(du -sk "$DEB_DIR" | cut -f1)
sed -i "s/Installed-Size:.*/Installed-Size: $INSTALLED_SIZE/" "$DEB_DIR/DEBIAN/control" 2>/dev/null || \
echo "Installed-Size: $INSTALLED_SIZE" >> "$DEB_DIR/DEBIAN/control"
# Build the package
if dpkg-deb --root-owner-group --build "$DEB_DIR" "$BUILD_DIR/$DEB_FILE"; then
echo_info "Successfully created: $BUILD_DIR/$DEB_FILE"
# Show package info
echo_info "Package information:"
dpkg-deb --info "$BUILD_DIR/$DEB_FILE"
echo_info "Package contents:"
dpkg-deb --contents "$BUILD_DIR/$DEB_FILE"
# Test the package (requires root)
if [ "$EUID" -eq 0 ]; then
echo_info "Testing package installation (as root)..."
dpkg --dry-run -i "$BUILD_DIR/$DEB_FILE"
else
echo_warn "Run as root to test package installation"
fi
echo_info "Debian package build complete!"
echo_info "Install with: sudo dpkg -i $BUILD_DIR/$DEB_FILE"
echo_info "Or upload to repository for apt installation"
else
echo_error "Failed to create Debian package"
exit 1
fi