mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-15 22:10:30 +00:00
Rewrite ASF scripts to POSIX sh
This commit is contained in:
34
run.sh
34
run.sh
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
BINARY_PATH="$(dirname "$(readlink -f "$0")")/out"
|
||||
CONFIG_PATH="config/ASF.json"
|
||||
|
||||
if [[ ! -d "$BINARY_PATH" ]]; then
|
||||
if [ ! -d "$BINARY_PATH" ]; then
|
||||
echo "ERROR: $BINARY_PATH could not be found!"
|
||||
exit 1
|
||||
fi
|
||||
@@ -13,21 +13,21 @@ cd "$BINARY_PATH"
|
||||
|
||||
BINARY="$(pwd)/ArchiSteamFarm.dll"
|
||||
|
||||
if [[ ! -f "$BINARY" ]]; then
|
||||
if [ ! -f "$BINARY" ]; then
|
||||
echo "ERROR: $BINARY could not be found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BINARY_ARGS=()
|
||||
BINARY_ARGS=""
|
||||
PATH_NEXT=0
|
||||
|
||||
PARSE_ARG() {
|
||||
BINARY_ARGS+=("$1")
|
||||
BINARY_ARGS="$BINARY_ARGS $1"
|
||||
|
||||
case "$1" in
|
||||
--path) PATH_NEXT=1 ;;
|
||||
--path=*)
|
||||
if [[ "$PATH_NEXT" -eq 1 ]]; then
|
||||
if [ "$PATH_NEXT" -eq 1 ]; then
|
||||
PATH_NEXT=0
|
||||
cd "$1"
|
||||
else
|
||||
@@ -35,27 +35,27 @@ PARSE_ARG() {
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if [[ "$PATH_NEXT" -eq 1 ]]; then
|
||||
if [ "$PATH_NEXT" -eq 1 ]; then
|
||||
PATH_NEXT=0
|
||||
cd "$1"
|
||||
fi
|
||||
esac
|
||||
}
|
||||
|
||||
if [[ -n "${ASF_PATH-}" ]]; then
|
||||
if [ -n "${ASF_PATH-}" ]; then
|
||||
cd "$ASF_PATH"
|
||||
fi
|
||||
|
||||
if [[ -n "${ASF_ARGS-}" ]]; then
|
||||
if [ -n "${ASF_ARGS-}" ]; then
|
||||
for ARG in $ASF_ARGS; do
|
||||
if [[ -n "$ARG" ]]; then
|
||||
if [ -n "$ARG" ]; then
|
||||
PARSE_ARG "$ARG"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
for ARG in "$@"; do
|
||||
if [[ -n "$ARG" ]]; then
|
||||
if [ -n "$ARG" ]; then
|
||||
PARSE_ARG "$ARG"
|
||||
fi
|
||||
done
|
||||
@@ -63,20 +63,20 @@ done
|
||||
CONFIG_PATH="$(pwd)/${CONFIG_PATH}"
|
||||
|
||||
# Kill underlying ASF process on shell process exit
|
||||
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM
|
||||
trap "trap - TERM && kill -- -$$" INT TERM
|
||||
|
||||
if ! hash dotnet 2>/dev/null; then
|
||||
if ! command -v dotnet >/dev/null; then
|
||||
echo "ERROR: dotnet CLI tools are not installed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dotnet --info
|
||||
|
||||
if [[ -f "$CONFIG_PATH" ]] && grep -Eq '"Headless":\s+?true' "$CONFIG_PATH"; then
|
||||
if [ -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
|
||||
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
|
||||
dotnet "$BINARY" $BINARY_ARGS # Start ASF in the foreground, trap won't work until process exit
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user