forked from JustArchiNET/ArchiSteamFarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·93 lines (76 loc) · 2.06 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env sh
set -eu
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!"
exit 1
fi
if [ ! -f "$BINARY" ]; then
echo "ERROR: $BINARY could not be found!"
exit 1
fi
cd "$BINARY_DIR"
BINARY_ARGS=""
PATH_NEXT=0
SERVICE=0
PARSE_ARG() {
BINARY_ARGS="$BINARY_ARGS $1"
case "$1" in
--path) PATH_NEXT=1 ;;
--path=*)
if [ "$PATH_NEXT" -eq 1 ]; then
PATH_NEXT=0
cd "$1"
else
cd "$(echo "$1" | cut -d '=' -f 2-)"
fi
;;
--service) SERVICE=1 ;;
*)
if [ "$PATH_NEXT" -eq 1 ]; then
PATH_NEXT=0
cd "$1"
fi
esac
}
if [ -n "${ASF_PATH-}" ]; then
cd "$ASF_PATH"
fi
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
done
CONFIG_PATH="$(pwd)/${CONFIG_PATH}"
# Kill underlying ASF process on shell process exit
trap "trap - TERM && kill -- -$$" INT TERM
if ! command -v dotnet >/dev/null; then
echo "ERROR: dotnet CLI tools are not installed!"
exit 1
fi
dotnet --info
if [ "$SERVICE" -eq 1 ] || ([ -f "$CONFIG_PATH" ] && grep -Eq '"Headless":\s+?true' "$CONFIG_PATH"); then
# We're running ASF in headless mode so we don't need STDIN
dotnet "$BINARY" $BINARY_ARGS & # Start ASF in the background, trap will work properly due to non-blocking call
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" $BINARY_ARGS # Start ASF in the foreground, trap won't work until process exit
fi