Aptly

<< Back to wiki homepage

Table of contents:

Search for a package globally

aptly package search 'Name (% postgresql-13)'

Check out possible query params.

List packages inside a repo

aptly repo show -with-packages $REPO_NAME

Show where a package is and who uses it

aptly package show -with-files -with-references postgresql-13_13.5-1.pgdg100+1_amd64

Add a deb package to a repo

aptly repo add $REPO_NAME /package/location/wherever/it/is/postgresql-13_13.5-1.pgdg100+1_amd64.deb

Calculate real disk size of a mirror

#!/bin/bash

# Check if the mirror name is provided
if [ -z "$1" ]; then
  echo "Usage: $0 <mirror-name>"
  exit 1
fi

MIRROR_NAME="$1"
TOTAL_SIZE=0
COUNT=0
CHUNK_SIZE=10

# Get the number of packages
NUMBER_OF_PACKAGES=$(sudo -u aptly aptly mirror show --with-packages "$MIRROR_NAME" | grep -oP 'Number of packages: \K\d+')

# Get the list of packages
PACKAGES=($(sudo -u aptly aptly mirror show --with-packages "$MIRROR_NAME" | grep -oP '^  \K.+'))

# Process packages in chunks
for ((i=0; i<${#PACKAGES[@]}; i+=CHUNK_SIZE)); do
    CHUNK=("${PACKAGES[@]:i:CHUNK_SIZE}")
    PACKAGE_REGEX=$(IFS='|'; echo "${CHUNK[*]}")

    PACKAGE_SIZES=($(sudo -u aptly aptly package show "$PACKAGE_REGEX" | grep -oP '^Size: \K\d+'))

    for SIZE in "${PACKAGE_SIZES[@]}"; do
        if [ -n "$SIZE" ]; then
            TOTAL_SIZE=$((TOTAL_SIZE + SIZE))
            COUNT=$((COUNT + 1))
        else
            echo "Unable to find size for a package in the current chunk"
        fi
    done

    # Convert current total size to a human-readable format
    CURRENT_READABLE_SIZE=$(numfmt --to=iec-i --suffix=B ${TOTAL_SIZE})

    # Print progress and current size
    echo -ne "\rProcessing: $COUNT/$NUMBER_OF_PACKAGES packages done. Current size: $CURRENT_READABLE_SIZE"
done

# Print new line after progress report
echo

# Convert total size to a human-readable format
FINAL_READABLE_SIZE=$(numfmt --to=iec-i --suffix=B ${TOTAL_SIZE})

# Print the total size
echo "Total size of the mirror '$MIRROR_NAME': $FINAL_READABLE_SIZE"

Please be aware the user might be different on your env, so adjust the aptly commands given