Files
zed-packager/find-deps.sh
Rawleenc 0dba8ae99a
All checks were successful
Build and Release Zed Editor / check-version (push) Successful in 3s
Build and Release Zed Editor / build-and-release (push) Successful in 1m21s
feat: switch to /usr layout and add dynamic dependency detection
- Move binaries to /usr/bin and /usr/libexec for system integration
- Add find-deps.sh script to detect required system packages from .so
  files
- Update Makefile to generate Depends field dynamically using apt-file
- Add list-deps target to Makefile for dependency analysis
- Update README with new usage, features, and instructions
- Update CI workflow to install apt-file and update its database
2025-10-14 11:46:28 +02:00

198 lines
5.8 KiB
Bash
Executable File

#!/bin/bash
# Script to find Debian/Ubuntu packages corresponding to zed.app .so files
# Requires apt-file (install with: sudo apt install apt-file && sudo apt-file update)
set -e
# Colors for display
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Parse arguments
QUIET=0
OUTPUT_FORMAT="human"
ZED_LIB_DIR=""
while [[ $# -gt 0 ]]; do
case $1 in
-q|--quiet)
QUIET=1
shift
;;
--format)
OUTPUT_FORMAT="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [OPTIONS] [LIBRARY_DIR]"
echo ""
echo "Options:"
echo " -q, --quiet Suppress progress messages"
echo " --format FORMAT Output format: human, makefile, list (default: human)"
echo " -h, --help Show this help"
echo ""
echo "Output formats:"
echo " human - Colored, verbose output with summary"
echo " makefile - Comma-separated list suitable for Makefile Depends field"
echo " list - One package per line"
exit 0
;;
*)
ZED_LIB_DIR="$1"
shift
;;
esac
done
# Default path if not provided
ZED_LIB_DIR="${ZED_LIB_DIR:-./build/extracted/zed.app/lib}"
# Disable colors in quiet mode or non-human formats
if [ "$QUIET" -eq 1 ] || [ "$OUTPUT_FORMAT" != "human" ]; then
RED=''
GREEN=''
YELLOW=''
BLUE=''
NC=''
fi
# Check if apt-file is installed
if ! command -v apt-file &> /dev/null; then
if [ "$QUIET" -eq 0 ]; then
echo -e "${RED}Error: apt-file is not installed${NC}" >&2
echo "Install it with: sudo apt install apt-file" >&2
echo "Then update the database: sudo apt-file update" >&2
fi
exit 1
fi
# Check if directory exists
if [ ! -d "$ZED_LIB_DIR" ]; then
if [ "$QUIET" -eq 0 ]; then
echo -e "${RED}Error: Directory $ZED_LIB_DIR does not exist${NC}" >&2
fi
exit 1
fi
# Human format: show header
if [ "$OUTPUT_FORMAT" = "human" ] && [ "$QUIET" -eq 0 ]; then
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo -e "${BLUE} Finding packages for Zed dependencies${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo ""
echo -e "Analyzing directory: ${YELLOW}$ZED_LIB_DIR${NC}"
echo ""
fi
# Counters
total=0
found=0
not_found=0
# Array to store results
declare -A packages
# Iterate through all .so files
for lib in "$ZED_LIB_DIR"/*.so*; do
if [ -f "$lib" ]; then
lib_name=$(basename "$lib")
total=$((total + 1))
if [ "$OUTPUT_FORMAT" = "human" ] && [ "$QUIET" -eq 0 ]; then
echo -e "${YELLOW}[$total]${NC} Searching for: ${GREEN}$lib_name${NC}"
fi
# Search for package with apt-file
# Look for the file name in /usr/lib or /lib
result=$(apt-file search "/$lib_name" 2>/dev/null | grep -E '(/usr/lib|/lib)' | head -n 1)
if [ -n "$result" ]; then
# Extract package name (before first :)
package=$(echo "$result" | cut -d':' -f1)
if [ "$OUTPUT_FORMAT" = "human" ] && [ "$QUIET" -eq 0 ]; then
echo -e " → Package found: ${GREEN}$package${NC}"
fi
packages["$package"]=1
found=$((found + 1))
else
if [ "$OUTPUT_FORMAT" = "human" ] && [ "$QUIET" -eq 0 ]; then
echo -e "${RED}No package found${NC}"
fi
not_found=$((not_found + 1))
fi
if [ "$OUTPUT_FORMAT" = "human" ] && [ "$QUIET" -eq 0 ]; then
echo ""
fi
fi
done
# Output based on format
case "$OUTPUT_FORMAT" in
makefile)
# Comma-separated list for Makefile Depends field
first=1
for pkg in "${!packages[@]}"; do
if [ $first -eq 1 ]; then
echo -n "$pkg"
first=0
else
echo -n ", $pkg"
fi
done
echo ""
;;
list)
# One package per line, sorted
for pkg in "${!packages[@]}"; do
echo "$pkg"
done | sort
;;
human)
# Summary
if [ "$QUIET" -eq 0 ]; then
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo -e "${BLUE} SUMMARY${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo -e "Total libraries analyzed: ${YELLOW}$total${NC}"
echo -e "Packages found: ${GREEN}$found${NC}"
echo -e "Not found: ${RED}$not_found${NC}"
echo ""
fi
# Unique package list
if [ ${#packages[@]} -gt 0 ]; then
if [ "$QUIET" -eq 0 ]; then
echo -e "${GREEN}Required unique packages:${NC}"
fi
for pkg in "${!packages[@]}"; do
echo -e " - $pkg"
done
if [ "$QUIET" -eq 0 ]; then
echo ""
echo -e "${BLUE}Installation command:${NC}"
install_cmd="sudo apt install"
for pkg in "${!packages[@]}"; do
install_cmd="$install_cmd $pkg"
done
echo -e "${GREEN}$install_cmd${NC}"
fi
fi
;;
esac
exit 0