cln-nip47/tests/setup.sh

98 lines
3.1 KiB
Bash
Raw Permalink Normal View History

2025-04-02 17:38:52 +02:00
#!/bin/bash
set -x
# Get the directory of the script
script_dir=$(dirname -- "$(readlink -f -- "$0")")
cargo_toml_path="$script_dir/../Cargo.toml"
# Use grep and awk to extract the name and version
name=$(awk -F'=' '/^\[package\]/ { in_package = 1 } in_package && /name/ { gsub(/[" ]/, "", $2); print $2; exit }' "$cargo_toml_path")
version=$(awk -F'=' '/^\[package\]/ { in_package = 1 } in_package && /version/ { gsub(/[" ]/, "", $2); print $2; exit }' "$cargo_toml_path")
get_platform_file_end() {
machine=$(uname -m)
kernel=$(uname -s)
case $kernel in
Darwin)
echo 'universal-apple-darwin.zip'
;;
Linux)
case $machine in
x86_64)
echo 'x86_64-linux-gnu.tar.gz'
;;
armv7l)
echo 'armv7-linux-gnueabihf.tar.gz'
;;
aarch64)
echo 'aarch64-linux-gnu.tar.gz'
;;
*)
echo "No self-compiled binary found and unsupported release-architecture: $machine" >&2
exit 1
;;
esac
;;
*)
echo "No self-compiled binary found and unsupported OS: $kernel" >&2
exit 1
;;
esac
}
platform_file_end=$(get_platform_file_end)
archive_file=$name-v$version-$platform_file_end
github_url="https://github.com/daywalker90/$name/releases/download/v$version/$archive_file"
# Download the archive using curl
if ! curl -L "$github_url" -o "$script_dir/$archive_file"; then
echo "Error downloading the file from $github_url" >&2
2025-08-19 11:26:00 +02:00
exit 1
2025-04-02 17:38:52 +02:00
fi
# Extract the contents
if [[ $archive_file == *.tar.gz ]]; then
if ! tar -xzvf "$script_dir/$archive_file" -C "$script_dir"; then
echo "Error extracting the contents of $archive_file" >&2
2025-08-19 11:26:00 +02:00
exit 1
2025-04-02 17:38:52 +02:00
fi
elif [[ $archive_file == *.zip ]]; then
if ! unzip "$script_dir/$archive_file" -d "$script_dir"; then
echo "Error extracting the contents of $archive_file" >&2
2025-08-19 11:26:00 +02:00
exit 1
2025-04-02 17:38:52 +02:00
fi
else
echo "Unknown archive format or unsupported file extension: $archive_file" >&2
2025-08-19 11:26:00 +02:00
exit 1
2025-04-02 17:38:52 +02:00
fi
if ! tar -xzvf "$script_dir/nostr-rs-relay.tar.gz" -C "$script_dir"; then
echo "Error extracting the contents of nostr-rs-relay.tar.gz" >&2
exit 1
fi
2025-04-02 17:38:52 +02:00
proto_path="$script_dir/../proto"
if [ -d "$proto_path" ]; then
# Generate grpc files
2025-08-18 12:09:45 +02:00
if ! uv run python -m grpc_tools.protoc --proto_path="$proto_path" --python_out=$script_dir --grpc_python_out=$script_dir $proto_path/*.proto; then
2025-04-02 17:38:52 +02:00
echo "Error generating grpc files" >&2
exit 1
fi
fi
2025-11-08 13:41:11 +01:00
hold_url="https://github.com/BoltzExchange/hold/releases/download/v0.3.3/hold-linux-amd64.tar.gz"
if ! curl -L "$hold_url" -o "$script_dir/hold-linux-amd64.tar.gz"; then
echo "Error downloading the file from $hold_url" >&2
exit 1
fi
if ! tar -xzvf "$script_dir/hold-linux-amd64.tar.gz" -C "$script_dir"; then
echo "Error extracting the contents of hold-linux-amd64.tar.gz" >&2
exit 1
fi
mv "$script_dir/build/hold-linux-amd64" "$script_dir/hold"