chore(deps): update github/codeql-action action to v3.27.6
[ArchiSteamFarm.git] / run.sh
blob9ea6571ced65a9308429904cdb9d338abf6b542d
1 #!/usr/bin/env sh
2 set -eu
4 CONFIG_PATH="config/ASF.json"
5 OS_TYPE="$(uname -s)"
7 case "$OS_TYPE" in
8 "Darwin") SCRIPT_PATH="$(readlink "$0")" ;;
9 "FreeBSD") SCRIPT_PATH="$(readlink -f "$0")" ;;
10 "Linux") SCRIPT_PATH="$(readlink -f "$0")" ;;
11 *) echo "ERROR: Unknown OS type: ${OS_TYPE}. If you believe that our script should work on your machine, please let us know."; exit 1
12 esac
14 SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
15 BINARY_DIR="${SCRIPT_DIR}/out/result"
16 BINARY="${BINARY_DIR}/ArchiSteamFarm.dll"
18 if [ ! -d "$BINARY_DIR" ]; then
19 echo "ERROR: $BINARY_DIR could not be found!"
20 exit 1
23 if [ ! -f "$BINARY" ]; then
24 echo "ERROR: $BINARY could not be found!"
25 exit 1
28 cd "$BINARY_DIR"
30 BINARY_ARGS=""
31 PATH_NEXT=0
32 SERVICE=0
34 PARSE_ARG() {
35 BINARY_ARGS="$BINARY_ARGS $1"
37 case "$1" in
38 --path) PATH_NEXT=1 ;;
39 --path=*)
40 if [ "$PATH_NEXT" -eq 1 ]; then
41 PATH_NEXT=0
42 cd "$1"
43 else
44 cd "$(echo "$1" | cut -d '=' -f 2-)"
47 --service) SERVICE=1 ;;
49 if [ "$PATH_NEXT" -eq 1 ]; then
50 PATH_NEXT=0
51 cd "$1"
53 esac
56 if [ -n "${ASF_PATH-}" ]; then
57 cd "$ASF_PATH"
60 if [ -n "${ASF_ARGS-}" ]; then
61 for ARG in $ASF_ARGS; do
62 if [ -n "$ARG" ]; then
63 PARSE_ARG "$ARG"
65 done
68 for ARG in "$@"; do
69 if [ -n "$ARG" ]; then
70 PARSE_ARG "$ARG"
72 done
74 CONFIG_PATH="$(pwd)/${CONFIG_PATH}"
76 # Kill underlying ASF process on shell process exit
77 trap "trap - TERM && kill -- -$$" INT TERM
79 if ! command -v dotnet >/dev/null; then
80 echo "ERROR: dotnet CLI tools are not installed!"
81 exit 1
84 dotnet --info
86 if [ "$SERVICE" -eq 1 ] || ([ -f "$CONFIG_PATH" ] && grep -Eq '"Headless":\s+?true' "$CONFIG_PATH"); then
87 # We're running ASF in headless mode so we don't need STDIN
88 dotnet "$BINARY" $BINARY_ARGS & # Start ASF in the background, trap will work properly due to non-blocking call
89 wait $! # This will forward dotnet error code, set -e will abort the script if it's non-zero
90 else
91 # We're running ASF in non-headless mode, so we need STDIN to be operative
92 dotnet "$BINARY" $BINARY_ARGS # Start ASF in the foreground, trap won't work until process exit