#! /usr/bin/env bash DEPENDENCIES=("nix" "nix-shell") NIX_DEPENDENCIES=("bats" "curl" "qbittorrent-nox" "gnugrep" "unixtools.netstat" "envsubst" "ps") if [[ "${QBTNOX_DIR:-plz}" = "plz" ]]; then export QBTNOX_DIR="$(mktemp -d)" fi ORIGDIR="$(pwd)" cd "$(dirname "$0")" source ../utils.sh SUBCOMMAND="${1:-test}" # Ensure nix shell with bats and curl... if we are running tests if [[ "$SUBCOMMAND" = "test" ]] && [[ "${IN_NIX_SHELL:-plz}" = "plz" ]]; then # Did test.sh perform depsCheck already? if [[ "${TESTRUNNER:-plz}" = "plz" ]]; then depsCheck fi # Are we in nix-shell already? IN_NIX_SHELL=1 nix-shell --pure -p ${NIX_DEPENDENCIES[@]} --keep CFGFILE --keep BIN_PATH --keep FREEPORT --run "\"$ORIGDIR\"/\"$0\" "$@"" exit $? fi export FREEPORT="$(findFreePort)" API="http://localhost:$FREEPORT" # Subcommand is test and checks succeeded subcommand "$SUBCOMMAND" STATUS=$? if [ $STATUS -eq 0 ]; then if [[ "$SUBCOMMAND" = "test" ]]; then cat ../default.toml | envsubst > "$QBTNOX_DIR"/config.toml export CFGFILE="$QBTNOX_DIR"/config.toml if ../qbittorrent-nox.sh start "$QBTNOX_DIR" "$FREEPORT"; then runTests "$API" STATUS=$? ../qbittorrent-nox.sh stop "$QBTNOX_DIR" else echo "qBittorrent did not start" STATUS=1 fi fi fi if [[ "${TESTRUNNER:-plz}" = "plz" ]]; then rm -R "$QBTNOX_DIR" fi cd "$ORIGDIR" exit $STATUS