ArchiSteamFarm/run.sh

92 lines
2 KiB
Bash
Raw Normal View History

2019-11-07 21:02:59 +00:00
#!/usr/bin/env sh
set -eu
2016-03-29 20:58:18 +00:00
CONFIG_PATH="config/ASF.json"
OS_TYPE="$(uname -s)"
case "$OS_TYPE" in
"Darwin") SCRIPT_PATH="$(readlink "$0")" ;;
"FreeBSD") SCRIPT_PATH="$(readlink -f "$0")" ;;
"Linux") SCRIPT_PATH="$(readlink -f "$0")" ;;
*) echo "ERROR: Unknown OS type: ${OS_TYPE}. If you believe that our script should work on your machine, please let us know."; exit 1
esac
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
BINARY_DIR="${SCRIPT_DIR}/out/result"
BINARY="${BINARY_DIR}/ArchiSteamFarm.dll"
if [ ! -d "$BINARY_DIR" ]; then
echo "ERROR: $BINARY_DIR could not be found!"
2018-12-25 19:31:32 +00:00
exit 1
fi
if [ ! -f "$BINARY" ]; then
echo "ERROR: $BINARY could not be found!"
2018-12-25 19:31:32 +00:00
exit 1
fi
cd "$BINARY_DIR"
2019-11-07 21:02:59 +00:00
BINARY_ARGS=""
2017-10-21 21:03:45 +00:00
PATH_NEXT=0
2017-10-21 21:03:45 +00:00
PARSE_ARG() {
2019-11-07 21:02:59 +00:00
BINARY_ARGS="$BINARY_ARGS $1"
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
esac
2017-10-21 21:03:45 +00:00
}
2019-11-07 21:02:59 +00:00
if [ -n "${ASF_PATH-}" ]; then
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
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
dotnet "$BINARY_PATH" $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
dotnet "$BINARY_PATH" $BINARY_ARGS # Start ASF in the foreground, trap won't work until process exit
2017-10-18 13:03:52 +00:00
fi