From d0f4c8871b0ca9acb9a54c7f1f0091c249f6f916 Mon Sep 17 00:00:00 2001 From: firest Date: Tue, 21 Nov 2023 22:49:28 +0800 Subject: [PATCH] chore: add auxiliary scripts --- rebar.config | 6 +++++- scripts/fetch_fdb_cli.sh | 29 +++++++++++++++++++++++++++++ scripts/sdk_checking.erl | 17 +++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 scripts/fetch_fdb_cli.sh create mode 100644 scripts/sdk_checking.erl diff --git a/rebar.config b/rebar.config index 13baf96..5a48517 100644 --- a/rebar.config +++ b/rebar.config @@ -1,14 +1,18 @@ {plugins, [ coveralls, - pc + pc, + {rebar3_dynamic_plugin, {git, "https://github.com/lafirest/rebar3_dynamic_plugin.git"}} ]}. {project_plugins, [ erlfmt ]}. +{dynamic_plugin_script, "scripts/sdk_checking.erl"}. + {provider_hooks, [ {pre, [ + {compile, dynamic_plugin}, {compile, {pc, compile}}, {clean, {pc, clean}} ]} diff --git a/scripts/fetch_fdb_cli.sh b/scripts/fetch_fdb_cli.sh new file mode 100755 index 0000000..67daa6b --- /dev/null +++ b/scripts/fetch_fdb_cli.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -euo pipefail + +usage() { + echo "Usage: $0 " + echo "" + echo "Download the FoundationDB client binary package into specific directory" + exit 1 +} + +if [ "$#" -ne 3 ]; then + usage +fi + +FDB_VERSION="7.1.43" +TYPE="${1}" +OUTPUT="${2}" + +case "$TYPE" in + deb) + LINK="https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-clients_${FDB_VERSION}-1_amd64.deb" + ;; + rpm) + LINK="https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-clients-${FDB_VERSION}-1.el7.x86_64.rpm" + ;; +esac + +wget -P "$OUTPUT" "$LINK" diff --git a/scripts/sdk_checking.erl b/scripts/sdk_checking.erl new file mode 100644 index 0000000..167807a --- /dev/null +++ b/scripts/sdk_checking.erl @@ -0,0 +1,17 @@ +-module(sdk_checking). + +-export([main/1]). + +main(_State) -> + case os:cmd("which fdbcli") of + "" -> + help(), + {error, not_found_foundation_client}; + _ -> + ok + end. + +help() -> + io:format(">>> Checking SDK dependency failed <<<\n"), + io:format("You should install the FoundationDB client first\n"), + io:format("You can use the 'scripts/fetch_fdb_cli.sh' to download the install packeage\n").