-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add archive-sparse-checkout.sh (#122)
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
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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" |