Skip to content

Commit 55924e6

Browse files
committed
chore: add archive-sparse-checkout.sh
It is a script to do sparse checkout of btfhub-archive repository. It can be used like this: ARCH=x86_64 ./tools/archive-sparse-checkout.sh ARCH=arm64 DISTRO=ubuntu VERSION=20.04 ./tools/archive-sparse-checkout.sh
1 parent 1b9da65 commit 55924e6

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

archive/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

custom-archive/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/archive-sparse-checkout.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/sh
2+
3+
die() {
4+
echo "${@}"
5+
exit 1
6+
}
7+
8+
if [ -z "$ARCH" ]; then
9+
ARCH="*"
10+
else
11+
case ${ARCH} in
12+
"x86_64")
13+
ARCH="x86_64"
14+
;;
15+
"aarch64"|"arm64")
16+
ARCH="arm64"
17+
;;
18+
*)
19+
die "unsupported architecture: ${ARCH}"
20+
;;
21+
esac
22+
fi
23+
24+
if [ -z "$DISTRO" ]; then
25+
DISTRO="*"
26+
fi
27+
28+
if [ -z "$VERSION" ]; then
29+
VERSION="*"
30+
fi
31+
32+
BASE_DIR=$(dirname "$(realpath "$0")")
33+
ARCHIVE_DIR=$(realpath "$BASE_DIR/../archive")
34+
REPO_URL="https://github.com/aquasecurity/btfhub-archive.git"
35+
36+
if [ ! -d "$ARCHIVE_DIR" ]; then
37+
echo "Directory does not exist. Creating $ARCHIVE_DIR..."
38+
mkdir -p "$ARCHIVE_DIR"
39+
fi
40+
41+
# if the directory is already a git repository, skip cloning
42+
if [ -d "$ARCHIVE_DIR/.git" ]; then
43+
echo "Directory is already a Git repository."
44+
else
45+
# clone into the directory
46+
git clone --sparse --filter=blob:none "$REPO_URL" "$ARCHIVE_DIR"
47+
fi
48+
49+
# initialize sparse-checkout
50+
git -C "$ARCHIVE_DIR" sparse-checkout init --no-cone
51+
52+
# write patterns for the files we want to pull
53+
echo "$DISTRO/$VERSION/$ARCH/*.btf.tar.xz" > "$ARCHIVE_DIR/.git/info/sparse-checkout"
54+
git -C "$ARCHIVE_DIR" sparse-checkout reapply || die "failed to reapply sparse-checkout"
55+
56+
echo "Sparse checkout completed successfully in $ARCHIVE_DIR"

0 commit comments

Comments
 (0)