Files
radicle-explorer/scripts/run-httpd-with-fixtures
T
2023-05-10 09:15:19 +02:00

121 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
set -e
REV=b29321dbf7999ec7ec9b7ac9192071e512ada407
REPO_ROOT=$(git rev-parse --show-toplevel)
FIXTURE=$REPO_ROOT/tests/fixtures/seeds/palm.tar.bz2
WORKSPACE=$REPO_ROOT/tests/tmp/palm
PASSPHRASE=asdf
BINARY_PATH="$REPO_ROOT/tests/tmp"
BINARY_NAME=radicle-httpd
OS=$(uname)
show_usage() {
echo
echo "Starts a ${BINARY_NAME} backend with test fixtures."
echo
echo "USAGE:"
echo " run-httpd-with-fixtures [-d|h|n]"
echo
echo "OPTIONS:"
echo " -d --download Download and use a precompiled binary."
echo " -h --help Print this Help."
echo " -n --non-interactive Run in non-interactive mode, no user prompts."
echo
}
prompt_workspace_removal() {
echo "This will irrevocably destroy the following directories:"
echo
echo $WORKSPACE
echo
read -r -p "Are you sure you want to continue? [yes/no]: " confirm
case "$confirm" in
[yY][eE][sS])
rm -rf $WORKSPACE
echo "Done"
;;
*)
echo "Ok, I won't touch your data."
exit
;;
esac
}
prepare_workspace() {
echo
echo "Unpacking fixture $FIXTURE"
mkdir -p $WORKSPACE
tar -xf $FIXTURE -C $WORKSPACE
}
NON_INTERACTIVE=false
DOWNLOAD=false
while [ $# -ne 0 ]; do
case "$1" in
--download | -d)
DOWNLOAD=true
;;
--non-interactive | -n)
NON_INTERACTIVE=true
;;
*)
show_usage
exit
;;
esac
shift
done
if [ "$DOWNLOAD" = true ]; then
CACHED_BINARY_NAME="$BINARY_NAME-${REV:0:7}"
if ! [ -x "$(command -v $BINARY_PATH/$CACHED_BINARY_NAME)" ]; then
case "$OS" in
Darwin)
echo Downloading $BINARY_NAME from https://files.radicle.xyz/$REV/aarch64-apple-darwin/$BINARY_NAME
curl --fail -s "https://files.radicle.xyz/$REV/aarch64-apple-darwin/$BINARY_NAME" --output "$BINARY_PATH/$CACHED_BINARY_NAME" || (echo "Download failed" && exit 1);;
Linux)
echo Downloading $BINARY_NAME from https://files.radicle.xyz/$REV/x86_64-unknown-linux-musl/$BINARY_NAME
curl --fail -s "https://files.radicle.xyz/$REV/x86_64-unknown-linux-musl/$BINARY_NAME" --output "$BINARY_PATH/$CACHED_BINARY_NAME" || (echo "Download failed" && exit 1);;
*) echo "There are no precompiled binaries for your OS: $OS, compile $BINARY_NAME manually and make sure it's in PATH." && exit 1 ;;
esac
chmod a+x "$BINARY_PATH/$CACHED_BINARY_NAME"
fi
export PATH="$BINARY_PATH:$PATH"
BINARY_NAME=$CACHED_BINARY_NAME
fi
if ! [ -x "$(command -v $BINARY_NAME)" ]; then
echo
echo "Couldn't find $BINARY_NAME binary in your PATH."
echo
echo "You can download it with the --download option, or"
echo "compile it from source:"
echo
echo " 👉 https://github.com/radicle-dev/heartwood"
echo
exit 1
fi
if [ "$NON_INTERACTIVE" = true ]; then
rm -rf $WORKSPACE
prepare_workspace
else
prompt_workspace_removal
prepare_workspace
fi
echo
echo "Starting $BINARY_NAME"
echo " RAD_HOME=$WORKSPACE RAD_PASSPHRASE=$PASSPHRASE $BINARY_NAME"
echo
RAD_HOME=$WORKSPACE RAD_PASSPHRASE=$PASSPHRASE $BINARY_NAME