From 128b6d2e5bdbd1007414d64f420d5c891b3a327b Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 14 Oct 2017 11:32:47 +0200 Subject: [PATCH] Add stdin handling for generic scripts --- .../scripts/generic/ArchiSteamFarm-Service.sh | 11 +++++++++-- ArchiSteamFarm/scripts/generic/ArchiSteamFarm.sh | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ArchiSteamFarm/scripts/generic/ArchiSteamFarm-Service.sh b/ArchiSteamFarm/scripts/generic/ArchiSteamFarm-Service.sh index 5878ee54f..331931118 100755 --- a/ArchiSteamFarm/scripts/generic/ArchiSteamFarm-Service.sh +++ b/ArchiSteamFarm/scripts/generic/ArchiSteamFarm-Service.sh @@ -12,8 +12,15 @@ ASF_ARGS+=" $*" trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT while :; do - dotnet ArchiSteamFarm.dll $ASF_ARGS & # We need to start ASF in the background for trap to work - wait $! # This will forward dotnet error code, set -e will abort the script if it's non-zero + if grep -Fq '"Headless": true' 'config/ASF.json'; then + # We're running ASF in headless mode so we don't need STDIN + dotnet ArchiSteamFarm.dll $ASF_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 ArchiSteamFarm.dll $ASF_ARGS # Start ASF in the foreground, trap sadly won't work until process exit + fi + chmod +x "$0" # If ASF exited by itself, we need to ensure that our script is still set to +x after auto-update sleep 1 done diff --git a/ArchiSteamFarm/scripts/generic/ArchiSteamFarm.sh b/ArchiSteamFarm/scripts/generic/ArchiSteamFarm.sh index 5f9c633f4..048eb2b4c 100755 --- a/ArchiSteamFarm/scripts/generic/ArchiSteamFarm.sh +++ b/ArchiSteamFarm/scripts/generic/ArchiSteamFarm.sh @@ -11,6 +11,13 @@ ASF_ARGS+=" $*" # Kill underlying ASF process on shell process exit trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT -dotnet ArchiSteamFarm.dll $ASF_ARGS & # We need to start ASF in the background for trap to work -wait $! # This will forward dotnet error code, set -e will abort the script if it's non-zero +if grep -Fq '"Headless": true' 'config/ASF.json'; then + # We're running ASF in headless mode so we don't need STDIN + dotnet ArchiSteamFarm.dll $ASF_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 ArchiSteamFarm.dll $ASF_ARGS # Start ASF in the foreground, trap won't work until process exit +fi + chmod +x "$0" # If ASF exited by itself, we need to ensure that our script is still set to +x after auto-update