2019-02-19 00:59:26 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -euo pipefail
|
2016-03-29 22:58:18 +02:00
|
|
|
|
2019-09-26 20:28:25 +02:00
|
|
|
BINARY_PATH="$(dirname "$(readlink -f "$0")")/out"
|
2017-10-19 12:46:42 +02:00
|
|
|
CONFIG_PATH="config/ASF.json"
|
|
|
|
|
|
2019-07-28 23:06:41 +02:00
|
|
|
if [[ ! -d "$BINARY_PATH" ]]; then
|
|
|
|
|
echo "ERROR: $BINARY_PATH could not be found!"
|
2018-12-25 20:31:32 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2019-07-28 23:06:41 +02:00
|
|
|
cd "$BINARY_PATH"
|
2016-03-29 22:58:18 +02:00
|
|
|
|
2017-11-05 08:23:21 +01:00
|
|
|
BINARY="$(pwd)/ArchiSteamFarm.dll"
|
2017-10-21 23:03:45 +02:00
|
|
|
|
2018-12-25 20:31:32 +01:00
|
|
|
if [[ ! -f "$BINARY" ]]; then
|
|
|
|
|
echo "ERROR: $BINARY could not be found!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
BINARY_ARGS=()
|
2017-10-21 23:03:45 +02:00
|
|
|
PATH_NEXT=0
|
2016-08-27 09:34:08 +02:00
|
|
|
|
2017-10-21 23:03:45 +02:00
|
|
|
PARSE_ARG() {
|
|
|
|
|
BINARY_ARGS+=("$1")
|
2017-08-31 07:54:07 +02:00
|
|
|
|
2017-10-21 23:03:45 +02:00
|
|
|
case "$1" in
|
|
|
|
|
--path) PATH_NEXT=1 ;;
|
2018-05-13 20:43:22 +02:00
|
|
|
--path=*)
|
|
|
|
|
if [[ "$PATH_NEXT" -eq 1 ]]; then
|
|
|
|
|
PATH_NEXT=0
|
|
|
|
|
cd "$1"
|
|
|
|
|
else
|
|
|
|
|
cd "$(echo "$1" | cut -d '=' -f 2-)"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2017-10-21 23:03:45 +02:00
|
|
|
*)
|
|
|
|
|
if [[ "$PATH_NEXT" -eq 1 ]]; then
|
|
|
|
|
PATH_NEXT=0
|
|
|
|
|
cd "$1"
|
|
|
|
|
fi
|
2017-10-19 12:46:42 +02:00
|
|
|
esac
|
2017-10-21 23:03:45 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-03 02:16:16 +02:00
|
|
|
if [[ -n "${ASF_PATH-}" ]]; then
|
|
|
|
|
cd "$ASF_PATH"
|
|
|
|
|
fi
|
|
|
|
|
|
2017-10-21 23:03:45 +02:00
|
|
|
if [[ -n "${ASF_ARGS-}" ]]; then
|
|
|
|
|
for ARG in $ASF_ARGS; do
|
|
|
|
|
if [[ -n "$ARG" ]]; then
|
|
|
|
|
PARSE_ARG "$ARG"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
for ARG in "$@"; do
|
|
|
|
|
if [[ -n "$ARG" ]]; then
|
|
|
|
|
PARSE_ARG "$ARG"
|
|
|
|
|
fi
|
2017-10-19 12:46:42 +02:00
|
|
|
done
|
|
|
|
|
|
2017-10-21 23:03:45 +02:00
|
|
|
CONFIG_PATH="$(pwd)/${CONFIG_PATH}"
|
|
|
|
|
|
2017-10-18 15:03:52 +02:00
|
|
|
# Kill underlying ASF process on shell process exit
|
2017-10-18 15:10:32 +02:00
|
|
|
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM
|
2016-03-29 22:58:18 +02:00
|
|
|
|
2017-10-18 15:03:52 +02:00
|
|
|
if ! hash dotnet 2>/dev/null; then
|
|
|
|
|
echo "ERROR: dotnet CLI tools are not installed!"
|
2016-03-29 22:58:18 +02:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2017-10-18 15:03:52 +02:00
|
|
|
dotnet --info
|
2017-06-26 05:14:44 +02:00
|
|
|
|
2017-10-19 12:46:42 +02:00
|
|
|
if [[ -f "$CONFIG_PATH" ]] && grep -Eq '"Headless":\s+?true' "$CONFIG_PATH"; then
|
2017-10-18 15:03:52 +02:00
|
|
|
# We're running ASF in headless mode so we don't need STDIN
|
2017-11-22 05:49:38 +01:00
|
|
|
dotnet "$BINARY" "${BINARY_ARGS[@]-}" & # Start ASF in the background, trap will work properly due to non-blocking call
|
2017-10-18 15:03:52 +02:00
|
|
|
wait $! # This will forward dotnet error code, set -e will abort the script if it's non-zero
|
|
|
|
|
else
|
|
|
|
|
# We're running ASF in non-headless mode, so we need STDIN to be operative
|
2017-11-22 05:49:38 +01:00
|
|
|
dotnet "$BINARY" "${BINARY_ARGS[@]-}" # Start ASF in the foreground, trap won't work until process exit
|
2017-10-18 15:03:52 +02:00
|
|
|
fi
|