skyview/scripts/build-deb.sh
Ole-Morten Duesund 7c9f7dc8c9 Implement incremental changelog generation for Debian packages
Fixes #22: Improve Debian package changelog to show incremental version history

The Debian package changelog now includes the complete version history
instead of just changes since the previous release. This provides users
with full visibility into the software's evolution when reviewing
package updates.

Changes:
- Rewrote changelog generation to iterate through all git tags
- Generate entries for each tagged version in reverse chronological order
- Include current development version if commits exist after latest tag
- Fixed shellcheck warnings for better script quality
- Added -f flag to gzip to force overwrite existing changelog.gz files

Benefits:
- Complete version history visible in every package
- Standard Debian changelog format compliance
- Better integration with apt changelog and dpkg tools
- Improved transparency for users reviewing updates
- Proper audit trail for administrators

The changelog now shows all versions with their respective changes,
making it easier for users to understand what has changed between
their installed version and the available update.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-25 08:32:43 +02:00

211 lines
No EOL
6.4 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 incremental changelog from git history
echo_info "Generating incremental changelog from git history..."
CHANGELOG_DIR="$DEB_DIR/usr/share/doc/skyview-adsb"
mkdir -p "$CHANGELOG_DIR"
# Function to generate incremental changelog
generate_incremental_changelog() {
local changelog_file="$1"
# Get all tags in reverse chronological order
local tags
tags=$(git tag -l --sort=-version:refname)
# If no tags exist, create a single entry for current state
if [ -z "$tags" ]; then
local current_version
current_version=$(git describe --tags --always)
echo_info "No tags found, generating initial changelog for $current_version"
{
echo "skyview-adsb ($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_file"
return
fi
# Create empty changelog
: > "$changelog_file"
# Add entry for current development version if there are commits after the last tag
local latest_tag
latest_tag=$(echo "$tags" | head -n1)
local commits_since_tag
commits_since_tag=$(git rev-list "$latest_tag"..HEAD --count 2>/dev/null || echo 0)
if [ "$commits_since_tag" -gt 0 ]; then
local current_version
current_version=$(git describe --tags --always)
echo_info "Adding entry for current development version: $current_version"
{
echo "skyview-adsb ($current_version) unstable; urgency=medium"
echo ""
git log --pretty=format:" * %s" "$latest_tag"..HEAD | head -20
echo ""
echo ""
echo " -- $(git config user.name) <$(git config user.email)> $(date -R)"
echo ""
} >> "$changelog_file"
fi
# Process all tags to create incremental changelog
local prev_tag=""
for tag in $tags; do
echo_info "Processing version $tag"
# Get tag date and author info
local tag_date
tag_date=$(git log -1 --format=%aD "$tag")
local tag_author
tag_author=$(git log -1 --format='%an <%ae>' "$tag")
# Add version header
{
echo "skyview-adsb ($tag) unstable; urgency=medium"
echo ""
} >> "$changelog_file"
# Add changes for this version
if [ -n "$prev_tag" ]; then
# Show changes between this tag and the previous one
git log --pretty=format:" * %s" "$tag..$prev_tag" | head -20 >> "$changelog_file"
else
# For the oldest tag, show changes from the beginning
git log --pretty=format:" * %s" "$tag" | head -20 >> "$changelog_file"
fi
# Add footer
{
echo ""
echo ""
echo " -- $tag_author $tag_date"
echo ""
} >> "$changelog_file"
prev_tag="$tag"
done
}
# Generate the incremental changelog
generate_incremental_changelog "$CHANGELOG_DIR/changelog"
echo_info "Generated incremental changelog with $(grep -c '^skyview-adsb (' "$CHANGELOG_DIR/changelog") version entries"
# Compress changelog as per Debian standards (force overwrite if exists)
gzip -9f "$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