skyview/scripts/update-database.sh
Ole-Morten Duesund 37c4fa2b57 feat: Add SQLite database integration for aircraft history and callsign enhancement
- Implement comprehensive database package with versioned migrations
- Add skyview-data CLI tool for managing aviation reference data
- Integrate database with merger for real-time aircraft history persistence
- Support OurAirports and OpenFlights data sources (runtime loading)
- Add systemd timer for automated database updates
- Fix transaction-based bulk loading for 2400% performance improvement
- Add callsign enhancement system with airline/airport lookups
- Update Debian packaging with database directory and permissions

Database features:
- Aircraft position history with configurable retention
- External aviation data loading (airlines, airports)
- Callsign parsing and enhancement
- API client for external lookups (OpenSky, etc.)
- Privacy mode for complete offline operation

CLI commands:
- skyview-data status: Show database statistics
- skyview-data update: Load aviation reference data
- skyview-data list: Show available data sources
- skyview-data clear: Remove specific data sources

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-31 16:48:28 +02:00

81 lines
No EOL
1.8 KiB
Bash
Executable file

#!/bin/bash
# SkyView Database Auto-Update Script
# Safe for cron execution - updates only public domain sources
set -e
# Configuration
SKYVIEW_DATA_CMD="${SKYVIEW_DATA_CMD:-skyview-data}"
LOCK_FILE="${TMPDIR:-/tmp}/skyview-data-update.lock"
LOG_FILE="${LOG_FILE:-/var/log/skyview/database-update.log}"
# Colors for output (disabled if not a tty)
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
NC=''
fi
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') $1" | tee -a "${LOG_FILE}" 2>/dev/null || echo "$(date '+%Y-%m-%d %H:%M:%S') $1"
}
error() {
echo -e "${RED}ERROR: $1${NC}" >&2
log "ERROR: $1"
}
success() {
echo -e "${GREEN}$1${NC}"
log "$1"
}
warn() {
echo -e "${YELLOW}WARNING: $1${NC}"
log "WARNING: $1"
}
# Check for lock file (prevent concurrent runs)
if [ -f "$LOCK_FILE" ]; then
if kill -0 "$(cat "$LOCK_FILE")" 2>/dev/null; then
error "Another instance is already running (PID: $(cat "$LOCK_FILE"))"
exit 1
else
warn "Removing stale lock file"
rm -f "$LOCK_FILE"
fi
fi
# Create lock file
echo $$ > "$LOCK_FILE"
trap 'rm -f "$LOCK_FILE"' EXIT
log "Starting SkyView database update"
# Check if skyview-data command exists
if ! command -v "$SKYVIEW_DATA_CMD" >/dev/null 2>&1; then
error "skyview-data command not found in PATH"
exit 1
fi
# Update database (this will auto-initialize if needed)
log "Running: $SKYVIEW_DATA_CMD update"
if "$SKYVIEW_DATA_CMD" update; then
success "Database update completed successfully"
# Show status for logging
"$SKYVIEW_DATA_CMD" status 2>/dev/null | while IFS= read -r line; do
log "STATUS: $line"
done
exit 0
else
error "Database update failed"
exit 1
fi