Skip to content

Instantly share code, notes, and snippets.

@Mister-Meeseeks
Last active August 2, 2024 07:06
Show Gist options
  • Save Mister-Meeseeks/77d76cef1b6204fdb05ca0cde1ceb95f to your computer and use it in GitHub Desktop.
Save Mister-Meeseeks/77d76cef1b6204fdb05ca0cde1ceb95f to your computer and use it in GitHub Desktop.
Download apt-get packages and recursive dependencies
#!/bin/bash -eu
# Uses apt-get to download packages and all recursive dependencies to an apt
# repository compatible directory.
#
# Usage:
# aptRecurse [-o OUT_DIRECTORY] PACKAGE_NAME [PACKAGE_NAME]...
#
# (Credit to this StackOverflow comment
# https://stackoverflow.com/a/45489718/868777)
archiveDir=.
while getopts "o:" opt ; do
case $opt in
o) archiveDir="$OPTARG"
esac
done
shift $(( $OPTIND - 1 ))
packages="$@"
function listDepends() {
apt-cache depends --recurse --no-recommends --no-suggests \
--no-conflicts --no-breaks --no-replaces --no-enhances \
$packages \
| grep "^\w"
}
function downloadPacks() {
apt-get download $@
}
function declarePacks() {
dpkg-scanpackages -m . | gzip -c > Packages.gz
}
cd $archiveDir
downloadPacks $(listDepends)
declarePacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment