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