get-archive-info will get a tar tvf
output and the .APKINFO for every file in the archive.
Last active
July 11, 2024 20:15
-
-
Save smoser/0a11e2643b884960c1e5349d4dc0b8c7 to your computer and use it in GitHub Desktop.
wolfi get file list and apk info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
msg() { echo "$(date -R)" "$@"; } | |
fail() { msg "$@"; exit 1; } | |
index="/gcsfuse/wolfi-production-registry-destination/os/x86_64/APKINDEX.tar.gz" | |
index="https://packages.wolfi.dev/os/x86_64/APKINDEX.tar.gz" | |
outd="$1" | |
[ -z "$outd" ] && outd=$PWD | |
outd=${outd%/} | |
[ -d "$outd" ] || mkdir -p "$outd" || exit 1 | |
tmpd=$(mktemp -d) | |
msg "generating packages.list" | |
apkrane ls --latest --full "$index" > "$tmpd/packages.list" || | |
fail "failed to get list with apkrane $index" | |
sort "$tmpd/packages.list" > "$tmpd/packages.list.sort" || | |
fail "sort failed. seriously" | |
# this is super hacky. I just shuffle list so that | |
# I can run two copies of this at once and double speed. | |
shuf "$tmpd/packages.list" > "$tmpd/packages.list.shuf" || | |
fail "shuf failed" | |
trap "rm -Rf $tmpd" EXIT | |
while read pkg; do | |
bn=${pkg##*/} | |
flist="$outd/$bn.flist" | |
info="$outd/$bn.info" | |
[ -f "$flist" -a -f "$info" ] && { msg "$bn: already done"; continue; } | |
msg "$bn: copying" | |
case "$pkg" in | |
http*) | |
out=$(wget "$pkg" -O "$tmpd/$bn" 2>&1) || { | |
echo "$out" | |
fail "failed wget $pkg"; | |
} | |
;; | |
*) cp "$pkg" "$tmpd/$bn" || fail "failed copy $pkg";; | |
esac | |
tmpf="${outd}/.$bn.info.tmp.$$" | |
tar --warning=none --to-stdout -xf "$tmpd/$bn" --occurrence=1 .PKGINFO > "$tmpf" && | |
mv "$tmpf" "$info" || { | |
rm -f "$tmpf" | |
fail "failed reading .PKGINFO" | |
} | |
msg "$bn: getting list" | |
tmpf="${outd}/.$bn.flist.tmp.$$" | |
tar --warning=none -tvf "$tmpd/$bn" > "$tmpf" && | |
mv "$tmpf" "$flist" || { | |
rm -f "$tmpf" | |
fail "$pkg: could not get list" | |
} | |
rm -f "$tmpd/$bn"* | |
done < "$tmpd/packages.list.shuf" | |
cp "$tmpd/packages.list.sort" "$outd/packages.list" || | |
fail "all that, and the cp failed" | |
msg "wrote $outd/packages.list" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment