Skip to content

Commit

Permalink
chore: add archive-sparse-checkout.sh (#122)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
geyslan authored Dec 18, 2024
1 parent 1b9da65 commit b155ff3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
1 change: 0 additions & 1 deletion archive/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion custom-archive/.gitignore

This file was deleted.

56 changes: 56 additions & 0 deletions tools/archive-sparse-checkout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

die() {
echo "${@}"
exit 1
}

if [ -z "$ARCH" ]; then
ARCH="*"
else
case ${ARCH} in
"x86_64")
ARCH="x86_64"
;;
"aarch64"|"arm64")
ARCH="arm64"
;;
*)
die "unsupported architecture: ${ARCH}"
;;
esac
fi

if [ -z "$DISTRO" ]; then
DISTRO="*"
fi

if [ -z "$VERSION" ]; then
VERSION="*"
fi

BASE_DIR=$(dirname "$(realpath "$0")")
ARCHIVE_DIR=$(realpath "$BASE_DIR/../archive")
REPO_URL="https://github.com/aquasecurity/btfhub-archive.git"

if [ ! -d "$ARCHIVE_DIR" ]; then
echo "Directory does not exist. Creating $ARCHIVE_DIR..."
mkdir -p "$ARCHIVE_DIR"
fi

# if the directory is already a git repository, skip cloning
if [ -d "$ARCHIVE_DIR/.git" ]; then
echo "Directory is already a Git repository."
else
# clone into the directory
git clone --sparse --filter=blob:none "$REPO_URL" "$ARCHIVE_DIR"
fi

# initialize sparse-checkout
git -C "$ARCHIVE_DIR" sparse-checkout init --no-cone

# write patterns for the files we want to pull
echo "$DISTRO/$VERSION/$ARCH/*.btf.tar.xz" > "$ARCHIVE_DIR/.git/info/sparse-checkout"
git -C "$ARCHIVE_DIR" sparse-checkout reapply || die "failed to reapply sparse-checkout"

echo "Sparse checkout completed successfully in $ARCHIVE_DIR"

0 comments on commit b155ff3

Please sign in to comment.