Skip to content

Instantly share code, notes, and snippets.

@zhangyoufu
Last active April 26, 2026 02:17
Show Gist options
  • Select an option

  • Save zhangyoufu/15563bb6fc133b5883afe28c1062e180 to your computer and use it in GitHub Desktop.

Select an option

Save zhangyoufu/15563bb6fc133b5883afe28c1062e180 to your computer and use it in GitHub Desktop.
apt/apt-get install solution, including all dependency, shell version make use of --print-uris argument, python version is more versatile (Note: snapshot.debian.org requires https, either install ca-certificates or put one at /usr/lib/ssl/cert.pem)
import apt
import apt_pkg
import os
import tempfile
SNAPSHOT = '20260421T000000Z'
ARCH = 'arm64'
PACKAGES = [
'binutils',
'gcc-x86-64-linux-gnu',
'libc6-dev',
]
with tempfile.TemporaryDirectory() as var_lib_apt_lists:
os.chmod(var_lib_apt_lists, 0o755)
apt_pkg.init_config()
apt_pkg.config.set('APT::Architecture', ARCH)
apt_pkg.config.set('APT::Get::Never-Include-Phased-Updates', 'yes')
apt_pkg.config.set('APT::Install-Recommends', 'no')
apt_pkg.config.set('APT::Snapshot', SNAPSHOT)
apt_pkg.config.set('Dir::State::lists', var_lib_apt_lists)
apt_pkg.config.set('Dir::State::status', '/dev/null')
apt_pkg.config.set('Dir::State::extendedstatus', '/dev/null')
cache = apt.Cache()
cache.update()
cache.open(progress=None)
for pkg_name in PACKAGES:
cache[pkg_name].mark_install()
resolution = {}
for pkg in cache:
if pkg.marked_install or pkg.marked_upgrade:
resolution[pkg.name] = pkg.candidate.version
for name, version in sorted(resolution.items()):
print(f'{name}: {version}')
#!/bin/bash
SNAPSHOT=20260421T000000Z
ARCH=arm64
PACKAGES=(
binutils
gcc-x86-64-linux-gnu
libc6-dev
)
DIR=$(mktemp -d)
cleanup() { rm -rf "${DIR}"; }
trap cleanup EXIT
CACHE_OPT=(
-o "APT::Architecture=${ARCH}"
-o "Dir::State::lists=${DIR}"
)
INSTALL_OPT=(
-o APT::Get::Never-Include-Phased-Updates=yes
-o Acquire::ForceHash=SHA256
-o Dir::State::status=/dev/null
-o Dir::State::extendedstatus=/dev/null
)
apt-get update -qq --snapshot "${SNAPSHOT}" "${CACHE_OPT[@]}"
apt-get install -qq --print-uris --no-install-recommends "${CACHE_OPT[@]}" "${INSTALL_OPT[@]}" "${PACKAGES[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment