2019-11-07 21:02:59 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
set -eu
|
2016-03-29 20:58:18 +00:00
|
|
|
|
2019-09-26 18:28:25 +00:00
|
|
|
BINARY_PATH="$(dirname "$(readlink -f "$0")")/out"
|
2017-10-19 10:46:42 +00:00
|
|
|
CONFIG_PATH="config/ASF.json"
|
|
|
|
|
2019-11-07 21:02:59 +00:00
|
|
|
if [ ! -d "$BINARY_PATH" ]; then
|
2019-07-28 21:06:41 +00:00
|
|
|
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
|
|
|
|
2019-11-07 21:02:59 +00:00
|
|
|
if [ ! -f "$BINARY" ]; then
|
2018-12-25 19:31:32 +00:00
|
|
|
echo "ERROR: $BINARY could not be found!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-07 21:02:59 +00:00
|
|
|
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() {
|
2019-11-07 21:02:59 +00:00
|
|
|
BINARY_ARGS="$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=*)
|
2019-11-07 21:02:59 +00:00
|
|
|
if [ "$PATH_NEXT" -eq 1 ]; then
|
2018-05-13 18:43:22 +00:00
|
|
|
PATH_NEXT=0
|
|
|
|
cd "$1"
|
|
|
|
else
|
|
|
|
cd "$(echo "$1" | cut -d '=' -f 2-)"
|
|
|
|
fi
|
|
|
|
;;
|
2017-10-21 21:03:45 +00:00
|
|
|
*)
|
2019-11-07 21:02:59 +00:00
|
|
|
if [ "$PATH_NEXT" -eq 1 ]; then
|
2017-10-21 21:03:45 +00:00
|
|
|
PATH_NEXT=0
|
|
|
|
cd "$1"
|
|
|
|
fi
|
2017-10-19 10:46:42 +00:00
|
|
|
esac
|
2017-10-21 21:03:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 21:02:59 +00:00
|
|
|
if [ -n "${ASF_PATH-}" ]; then
|
2019-08-03 00:16:16 +00:00
|
|
|
cd "$ASF_PATH"
|
|
|
|
fi
|
|
|
|
|
2019-11-07 21:02:59 +00:00
|
|
|
if [ -n "${ASF_ARGS-}" ]; then
|
2017-10-21 21:03:45 +00:00
|
|
|
for ARG in $ASF_ARGS; do
|
2019-11-07 21:02:59 +00:00
|
|
|
if [ -n "$ARG" ]; then
|
2017-10-21 21:03:45 +00:00
|
|
|
PARSE_ARG "$ARG"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
for ARG in "$@"; do
|
2019-11-07 21:02:59 +00:00
|
|
|
if [ -n "$ARG" ]; then
|
2017-10-21 21:03:45 +00:00
|
|
|
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
|
2019-11-07 21:02:59 +00:00
|
|
|
trap "trap - TERM && kill -- -$$" INT TERM
|
2016-03-29 20:58:18 +00:00
|
|
|
|
2019-11-07 21:02:59 +00:00
|
|
|
if ! command -v dotnet >/dev/null; then
|
2017-10-18 13:03:52 +00:00
|
|
|
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
|
|
|
|
2019-11-07 21:02:59 +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
|
2019-11-07 21:02:59 +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
|
2019-11-07 21:02:59 +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
|