soaplin/kernel/get-deps

92 lines
No EOL
2.8 KiB
Bash
Executable file

#! /bin/sh
srcdir="$(dirname "$0")"
test -z "$srcdir" && srcdir=.
cd "$srcdir"
clone_repo_commit() {
echo " DEPS Cloning $1 to $2 (commit: $3)"
if test -d "$2/.git"; then
git -C "$2" reset --hard > /dev/null 2>&1
git -C "$2" clean -fd > /dev/null 2>&1
if ! git -C "$2" checkout $3; then
rm -rf "$2"
fi
else
if test -d "$2"; then
set +x
echo "error: '$2' is not a Git repository"
exit 1
fi
fi
if ! test -d "$2"; then
git clone $1 "$2" > /dev/null 2>&1
if ! git -C "$2" checkout $3 > /dev/null 2>&1; then
rm -rf "$2"
exit 1
fi
fi
}
download_by_hash() {
DOWNLOAD_COMMAND="curl -Lo"
if ! command -v "${DOWNLOAD_COMMAND%% *}" >/dev/null 2>&1; then
DOWNLOAD_COMMAND="wget -O"
if ! command -v "${DOWNLOAD_COMMAND%% *}" >/dev/null 2>&1; then
set +x
echo "error: Neither curl nor wget found"
exit 1
fi
fi
SHA256_COMMAND="sha256sum"
if ! command -v "${SHA256_COMMAND%% *}" >/dev/null 2>&1; then
SHA256_COMMAND="sha256"
if ! command -v "${SHA256_COMMAND%% *}" >/dev/null 2>&1; then
set +x
echo "error: Cannot find sha256(sum) command"
exit 1
fi
fi
echo " DEPS Downloading $1 to $2"
if ! test -f "$2" || ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
rm -f "$2"
mkdir -p "$2" && rm -rf "$2"
$DOWNLOAD_COMMAND "$2" $1 > /dev/null 2>&1
if ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
set +x
echo "error: Cannot download file '$2' by hash"
echo "incorrect hash:"
$SHA256_COMMAND "$2"
rm -f "$2"
exit 1
fi
fi
}
mkdir src/deps
clone_repo_commit \
https://codeberg.org/mintsuki/flanterm \
src/deps/flanterm \
bdecdcb1b7dad05ab5249e2c3e4d2c27a661e864
clone_repo_commit \
https://codeberg.org/osdev/freestnd-c-hdrs-0bsd.git \
src/deps/freestnd-c-hdrs \
a87c192f3eb66b0806740dc67325f9ad23fc2d0b
download_by_hash \
https://codeberg.org/osdev/cc-runtime/raw/commit/d5425655388977fa12ff9b903e554a20b20c426e/cc-runtime.c \
src/deps/cc-runtime.c \
60bb1af4f6541077b736f19bf0f5a22b5dd8a2f3bed0d9d9d89846a33ef24b74
download_by_hash \
https://github.com/limine-bootloader/limine/raw/4687a182be23939c2d9f15db970382dc353ed956/limine.h \
src/deps/limine.h \
6879e626f34c1be25ac2f72bf43b083fc2b53887280bb0fcdaee790e258c6974
download_by_hash \
https://github.com/charlesnicholson/nanoprintf/raw/49628bd79977478dbd7c9a1b5277c44e5d49b118/nanoprintf.h \
src/deps/npf.h \
ef496c71868b3942695f63e0215da9d25ebdfa21569c854950e8f91adb9e0bea