Bin cleanup

This commit is contained in:
Ryan Hughes
2025-08-28 19:14:28 +03:00
parent 9262d011f4
commit c5f7c41b3b
4 changed files with 164 additions and 163 deletions
+5 -4
View File
@@ -8,12 +8,13 @@ ARCH_DIR="$BUILD_ROOT/x86_64"
DB_FILE="$ARCH_DIR/omarchy.db.tar.zst" DB_FILE="$ARCH_DIR/omarchy.db.tar.zst"
if [[ ! -f "$DB_FILE" ]]; then if [[ ! -f "$DB_FILE" ]]; then
echo "Repository database not found" echo "Repository database not found"
exit 1 exit 1
fi fi
# Extract package names and versions from database # Extract package names and versions from database
tar -xOf "$DB_FILE" --wildcards "*/desc" 2>/dev/null | tar -xOf "$DB_FILE" --wildcards "*/desc" 2>/dev/null |
awk '/%NAME%/{getline; name=$0} awk '/%NAME%/{getline; name=$0}
/%VERSION%/{getline; print name "-" $0}' | /%VERSION%/{getline; print name "-" $0}' |
sort sort
-1
View File
@@ -33,4 +33,3 @@ for file in $FILES; do
done done
echo "Package '$1' removed" echo "Package '$1' removed"
+8 -8
View File
@@ -17,14 +17,14 @@ shift
# Parse optional arguments # Parse optional arguments
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
--remote) --remote)
REMOTE="$2" REMOTE="$2"
shift 2 shift 2
;; ;;
*) *)
echo "Unknown option: $1" echo "Unknown option: $1"
exit 1 exit 1
;; ;;
esac esac
done done
+128 -127
View File
@@ -4,183 +4,184 @@
set -e set -e
# Colors for output # Source common functions
RED='\033[0;31m' BUILD_ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..")
GREEN='\033[0;32m' source "$BUILD_ROOT/lib/common.sh"
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Repository configuration # Repository configuration
REPO_DIR="/home/ryan/Dev/omarchy-repo" ARCH_DIR="$BUILD_ROOT/x86_64"
ARCH_DIR="$REPO_DIR/x86_64"
REPO_NAME="omarchy" REPO_NAME="omarchy"
DB_FILE="$ARCH_DIR/${REPO_NAME}.db.tar.zst" DB_FILE="$ARCH_DIR/${REPO_NAME}.db.tar.zst"
FILES_FILE="$ARCH_DIR/${REPO_NAME}.files.tar.zst" FILES_FILE="$ARCH_DIR/${REPO_NAME}.files.tar.zst"
# Function to print colored messages
print_msg() {
local color=$1
local msg=$2
echo -e "${color}${msg}${NC}"
}
# Function to update repository database # Function to update repository database
update_database() { update_database() {
print_msg "$BLUE" "==> Updating repository database..." print_info "Updating repository database..."
# Change to architecture directory # Change to architecture directory
cd "$ARCH_DIR" cd "$ARCH_DIR"
# If clean build requested, remove ALL database files first
if [[ "$CLEAN_BUILD" == true ]]; then
print_warning "Clean build requested - removing all database files..."
rm -f "${REPO_NAME}.db"* "${REPO_NAME}.files"*
else
# Remove old database files and symlinks # Remove old database files and symlinks
rm -f "${REPO_NAME}.db" "${REPO_NAME}.db.tar.zst" rm -f "${REPO_NAME}.db" "${REPO_NAME}.db.tar.zst"
rm -f "${REPO_NAME}.files" "${REPO_NAME}.files.tar.zst" rm -f "${REPO_NAME}.files" "${REPO_NAME}.files.tar.zst"
rm -f "${REPO_NAME}.db.tar.zst.old" "${REPO_NAME}.files.tar.zst.old" rm -f "${REPO_NAME}.db.tar.zst.old" "${REPO_NAME}.files.tar.zst.old"
fi
# Check if there are any packages # Check if there are any packages
if ! ls *.pkg.tar.* 1> /dev/null 2>&1; then if ! ls *.pkg.tar.* 1>/dev/null 2>&1; then
print_msg "$YELLOW" "Warning: No packages found in $ARCH_DIR" print_warning "No packages found in $ARCH_DIR"
print_msg "$YELLOW" "Run ./scripts/build-packages.sh first to build packages" print_warning "Run ./bin/build first to build packages"
exit 1 exit 1
fi fi
# Add all packages to the database (excluding signature files) # Add all packages to the database (excluding signature files)
print_msg "$GREEN" " -> Adding packages to database..." print_success "Adding packages to database..."
# Process packages in smaller batches to avoid command line limits # Process packages in smaller batches to avoid command line limits
# Use -n 5 to process 5 packages at a time # Use -n 5 to process 5 packages at a time
find . -maxdepth 1 -name "*.pkg.tar.*" ! -name "*.sig" -exec basename {} \; | xargs -n 5 repo-add "$DB_FILE" || { find . -maxdepth 1 -name "*.pkg.tar.*" ! -name "*.sig" -exec basename {} \; | xargs -n 5 repo-add "$DB_FILE" || {
print_msg "$RED" "Error: Failed to update repository database" print_error "Failed to update repository database"
exit 1 exit 1
} }
# Create symlinks for compatibility # Create symlinks for compatibility
ln -sf "${REPO_NAME}.db.tar.zst" "${REPO_NAME}.db" ln -sf "${REPO_NAME}.db.tar.zst" "${REPO_NAME}.db"
ln -sf "${REPO_NAME}.files.tar.zst" "${REPO_NAME}.files" ln -sf "${REPO_NAME}.files.tar.zst" "${REPO_NAME}.files"
# Count packages # Count packages
PACKAGE_COUNT=$(ls -1 *.pkg.tar.* 2>/dev/null | wc -l) PACKAGE_COUNT=$(ls -1 *.pkg.tar.* 2>/dev/null | wc -l)
print_msg "$GREEN" " -> Database updated successfully!" print_success "Database updated successfully!"
print_msg "$BLUE" " -> Total packages in repository: $PACKAGE_COUNT" print_info "Total packages in repository: $PACKAGE_COUNT"
} }
# Function to verify database # Function to verify database
verify_database() { verify_database() {
print_msg "$BLUE" "\n==> Verifying repository database..." print_info "Verifying repository database..."
if [[ -f "$DB_FILE" ]]; then if [[ -f "$DB_FILE" ]]; then
# List packages in database # List packages in database
print_msg "$GREEN" " -> Packages in database:" print_success "Packages in database:"
tar -tf "$DB_FILE" 2>/dev/null | grep -E "^[^/]+/$" | sed 's|/$||' | sort -u | while read -r pkg; do tar -tf "$DB_FILE" 2>/dev/null | grep -E "^[^/]+/$" | sed 's|/$||' | sort -u | while read -r pkg; do
echo " - $pkg" echo " - $pkg"
done done
print_msg "$GREEN" " -> Database verification complete!" print_success "Database verification complete!"
else else
print_msg "$RED" "Error: Database file not found!" print_error "Database file not found!"
exit 1 exit 1
fi fi
} }
# Function to sign database (optional) # Function to sign database (optional)
sign_database() { sign_database() {
print_msg "$BLUE" "\n==> Signing repository database..." print_info "Signing repository database..."
# Check if GPG key is available # Check if GPG key is available
if ! gpg --list-secret-keys 2>/dev/null | grep -q "sec"; then if ! gpg --list-secret-keys 2>/dev/null | grep -q "sec"; then
print_msg "$YELLOW" "Warning: No GPG key found, skipping signing" print_warning "No GPG key found, skipping signing"
print_msg "$YELLOW" "To enable signing, create a GPG key and configure it" print_warning "To enable signing, create a GPG key and configure it"
return return
fi fi
# Sign the database # Sign the database
gpg --detach-sign --use-agent "$DB_FILE" 2>/dev/null && { gpg --detach-sign --use-agent "$DB_FILE" 2>/dev/null && {
print_msg "$GREEN" " -> Database signed successfully!" print_success "Database signed successfully!"
} || { } || {
print_msg "$YELLOW" " -> Database signing failed (optional)" print_warning "Database signing failed (optional)"
} }
} }
# Function to generate repository statistics # Function to generate repository statistics
generate_stats() { generate_stats() {
print_msg "$BLUE" "\n==> Repository Statistics:" print_info "Repository Statistics:"
cd "$ARCH_DIR" cd "$ARCH_DIR"
# Count packages by type # Count packages by type
local total_packages=$(ls -1 *.pkg.tar.* 2>/dev/null | wc -l) local total_packages=$(ls -1 *.pkg.tar.* 2>/dev/null | wc -l)
local total_size=$(du -sh . 2>/dev/null | cut -f1) local total_size=$(du -sh . 2>/dev/null | cut -f1)
print_msg "$GREEN" " -> Total packages: $total_packages" print_success "Total packages: $total_packages"
print_msg "$GREEN" " -> Repository size: $total_size" print_success "Repository size: $total_size"
# List largest packages # List largest packages
if [[ $total_packages -gt 0 ]]; then if [[ $total_packages -gt 0 ]]; then
print_msg "$GREEN" " -> Largest packages:" print_success "Largest packages:"
ls -lhS *.pkg.tar.* 2>/dev/null | head -5 | awk '{print " " $9 " (" $5 ")"}' ls -lhS *.pkg.tar.* 2>/dev/null | head -5 | awk '{print " " $9 " (" $5 ")"}'
fi fi
} }
# Main execution # Main execution
main() { main() {
print_msg "$BLUE" "================================" print_header "Omarchy Repository Database Manager"
print_msg "$BLUE" "Omarchy Repository Database Manager"
print_msg "$BLUE" "================================"
# Parse command line arguments # Parse command line arguments
VERIFY_ONLY=false VERIFY_ONLY=false
SIGN_DB=false SIGN_DB=false
STATS_ONLY=false STATS_ONLY=false
CLEAN_BUILD=false
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
--verify) --verify)
VERIFY_ONLY=true VERIFY_ONLY=true
shift shift
;; ;;
--sign) --sign)
SIGN_DB=true SIGN_DB=true
shift shift
;; ;;
--stats) --stats)
STATS_ONLY=true STATS_ONLY=true
shift shift
;; ;;
-h|--help) --clean)
echo "Usage: $0 [OPTIONS]" CLEAN_BUILD=true
echo "" shift
echo "Options:" ;;
echo " --verify Only verify the database" -h | --help)
echo " --sign Sign the database with GPG" echo "Usage: $0 [OPTIONS]"
echo " --stats Show repository statistics only" echo ""
echo " -h, --help Show this help message" echo "Options:"
exit 0 echo " --clean Remove existing database and rebuild from scratch"
;; echo " --verify Only verify the database"
*) echo " --sign Sign the database with GPG"
print_msg "$RED" "Unknown option: $1" echo " --stats Show repository statistics only"
exit 1 echo " -h, --help Show this help message"
;; exit 0
esac ;;
done *)
print_error "Unknown option: $1"
exit 1
;;
esac
done
# Execute based on options # Execute based on options
if [[ "$STATS_ONLY" == true ]]; then if [[ "$STATS_ONLY" == true ]]; then
generate_stats generate_stats
elif [[ "$VERIFY_ONLY" == true ]]; then elif [[ "$VERIFY_ONLY" == true ]]; then
verify_database verify_database
else else
update_database update_database
if [[ "$SIGN_DB" == true ]]; then if [[ "$SIGN_DB" == true ]]; then
sign_database sign_database
fi
verify_database
generate_stats
fi fi
print_msg "$GREEN" "\n==> Repository update complete!" verify_database
generate_stats
fi
echo ""
print_success "Repository update complete!"
} }
# Run main function # Run main function
main "$@" main "$@"