From 633146a3f96c0ae1bb6169ee4d7f7646a736f2fe Mon Sep 17 00:00:00 2001 From: JustArchi Date: Thu, 7 Nov 2019 22:02:59 +0100 Subject: [PATCH] Rewrite ASF scripts to POSIX sh --- .../generic-netf/ArchiSteamFarm-Service.sh | 32 ++++++++--------- .../overlay/generic-netf/ArchiSteamFarm.sh | 32 ++++++++--------- .../overlay/generic/ArchiSteamFarm-Service.sh | 32 ++++++++--------- .../overlay/generic/ArchiSteamFarm.sh | 32 ++++++++--------- cc.sh | 36 +++++++++---------- run.sh | 34 +++++++++--------- 6 files changed, 99 insertions(+), 99 deletions(-) diff --git a/ArchiSteamFarm/overlay/generic-netf/ArchiSteamFarm-Service.sh b/ArchiSteamFarm/overlay/generic-netf/ArchiSteamFarm-Service.sh index af3714b27..dda3051d6 100755 --- a/ArchiSteamFarm/overlay/generic-netf/ArchiSteamFarm-Service.sh +++ b/ArchiSteamFarm/overlay/generic-netf/ArchiSteamFarm-Service.sh @@ -1,5 +1,5 @@ -#!/usr/bin/env bash -set -euo pipefail +#!/usr/bin/env sh +set -eu CONFIG_PATH="config/ASF.json" @@ -10,21 +10,21 @@ SCRIPT_PATH="${SCRIPT_DIR}/${0}" BINARY="${SCRIPT_DIR}/ArchiSteamFarm.exe" -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 @@ -32,27 +32,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 @@ -60,9 +60,9 @@ 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 mono 2>/dev/null; then +if ! command -v mono >/dev/null; then echo "ERROR: mono is not installed!" exit 1 fi @@ -70,13 +70,13 @@ fi mono --version while :; do - 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 - mono "${MONO_ARGS[@]-}" "$BINARY" "${BINARY_ARGS[@]-}" & # Start ASF in the background, trap will work properly due to non-blocking call + mono ${MONO_ARGS-} "$BINARY" $BINARY_ARGS & # Start ASF in the background, trap will work properly due to non-blocking call wait $! # This will forward mono 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 - mono "${MONO_ARGS[@]-}" "$BINARY" "${BINARY_ARGS[@]-}" # Start ASF in the foreground, trap sadly won't work until process exit + mono ${MONO_ARGS-} "$BINARY" $BINARY_ARGS # Start ASF in the foreground, trap sadly won't work until process exit fi chmod +x "$SCRIPT_PATH" # If ASF exited by itself, we need to ensure that our script is still set to +x after auto-update diff --git a/ArchiSteamFarm/overlay/generic-netf/ArchiSteamFarm.sh b/ArchiSteamFarm/overlay/generic-netf/ArchiSteamFarm.sh index 825150026..e60cbfe51 100755 --- a/ArchiSteamFarm/overlay/generic-netf/ArchiSteamFarm.sh +++ b/ArchiSteamFarm/overlay/generic-netf/ArchiSteamFarm.sh @@ -1,5 +1,5 @@ -#!/usr/bin/env bash -set -euo pipefail +#!/usr/bin/env sh +set -eu CONFIG_PATH="config/ASF.json" @@ -10,21 +10,21 @@ SCRIPT_PATH="${SCRIPT_DIR}/${0}" BINARY="${SCRIPT_DIR}/ArchiSteamFarm.exe" -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 @@ -32,27 +32,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 @@ -60,22 +60,22 @@ 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 mono 2>/dev/null; then +if ! command -v mono >/dev/null; then echo "ERROR: mono is not installed!" exit 1 fi mono --version -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 - mono "${MONO_ARGS[@]-}" "$BINARY" "${BINARY_ARGS[@]-}" & # Start ASF in the background, trap will work properly due to non-blocking call + mono ${MONO_ARGS-} "$BINARY" $BINARY_ARGS & # Start ASF in the background, trap will work properly due to non-blocking call wait $! # This will forward mono 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 - mono "${MONO_ARGS[@]-}" "$BINARY" "${BINARY_ARGS[@]-}" # Start ASF in the foreground, trap won't work until process exit + mono ${MONO_ARGS-} "$BINARY" $BINARY_ARGS # Start ASF in the foreground, trap won't work until process exit fi chmod +x "$SCRIPT_PATH" # If ASF exited by itself, we need to ensure that our script is still set to +x after auto-update diff --git a/ArchiSteamFarm/overlay/generic/ArchiSteamFarm-Service.sh b/ArchiSteamFarm/overlay/generic/ArchiSteamFarm-Service.sh index 349c63af1..75ebf7890 100755 --- a/ArchiSteamFarm/overlay/generic/ArchiSteamFarm-Service.sh +++ b/ArchiSteamFarm/overlay/generic/ArchiSteamFarm-Service.sh @@ -1,5 +1,5 @@ -#!/usr/bin/env bash -set -euo pipefail +#!/usr/bin/env sh +set -eu CONFIG_PATH="config/ASF.json" @@ -10,21 +10,21 @@ SCRIPT_PATH="${SCRIPT_DIR}/${0}" BINARY="${SCRIPT_DIR}/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 @@ -32,27 +32,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 @@ -60,9 +60,9 @@ 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 @@ -70,13 +70,13 @@ fi dotnet --info while :; do - 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 ${DOTNET_ARGS-} "$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 sadly won't work until process exit + dotnet ${DOTNET_ARGS-} "$BINARY" $BINARY_ARGS # Start ASF in the foreground, trap sadly won't work until process exit fi chmod +x "$SCRIPT_PATH" # If ASF exited by itself, we need to ensure that our script is still set to +x after auto-update diff --git a/ArchiSteamFarm/overlay/generic/ArchiSteamFarm.sh b/ArchiSteamFarm/overlay/generic/ArchiSteamFarm.sh index 15f8a337e..d8cc73dac 100755 --- a/ArchiSteamFarm/overlay/generic/ArchiSteamFarm.sh +++ b/ArchiSteamFarm/overlay/generic/ArchiSteamFarm.sh @@ -1,5 +1,5 @@ -#!/usr/bin/env bash -set -euo pipefail +#!/usr/bin/env sh +set -eu CONFIG_PATH="config/ASF.json" @@ -10,21 +10,21 @@ SCRIPT_PATH="${SCRIPT_DIR}/${0}" BINARY="${SCRIPT_DIR}/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 @@ -32,27 +32,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 @@ -60,22 +60,22 @@ 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 ${DOTNET_ARGS-} "$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 ${DOTNET_ARGS-} "$BINARY" $BINARY_ARGS # Start ASF in the foreground, trap won't work until process exit fi chmod +x "$SCRIPT_PATH" # If ASF exited by itself, we need to ensure that our script is still set to +x after auto-update diff --git a/cc.sh b/cc.sh index 9bad6bc68..bf2125827 100755 --- a/cc.sh +++ b/cc.sh @@ -1,5 +1,5 @@ -#!/usr/bin/env bash -set -euo pipefail +#!/usr/bin/env sh +set -eu TARGET_FRAMEWORK="netcoreapp3.0" @@ -43,26 +43,26 @@ for ARG in "$@"; do esac done -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 [[ "$PULL" -eq 1 && -d ".git" ]] && hash git 2>/dev/null; then +if [ "$PULL" -eq 1 ] && [ -d ".git" ] && command -v git >/dev/null; then git pull --recurse-submodules=on-demand || true fi -if [[ ! -f "$SOLUTION" ]]; then +if [ ! -f "$SOLUTION" ]; then echo "ERROR: $SOLUTION could not be found!" exit 1 fi -if [[ "$ASF_UI" -eq 1 ]]; then - if [[ -f "ASF-ui/package.json" ]] && hash npm 2>/dev/null; then +if [ "$ASF_UI" -eq 1 ]; then + if [ -f "ASF-ui/package.json" ] && command -v npm >/dev/null; then echo "Building ASF-ui..." # ASF-ui doesn't clean itself after old build @@ -81,26 +81,26 @@ if [[ "$ASF_UI" -eq 1 ]]; then fi fi -DOTNET_FLAGS=(-c "$CONFIGURATION" -f "$TARGET_FRAMEWORK" '/nologo') +DOTNET_FLAGS="-c $CONFIGURATION -f $TARGET_FRAMEWORK /nologo" -if [[ "$PUBLISH_TRIMMED" -eq 0 ]]; then - DOTNET_FLAGS+=('/p:PublishTrimmed=false') +if [ "$PUBLISH_TRIMMED" -eq 0 ]; then + DOTNET_FLAGS="$DOTNET_FLAGS /p:PublishTrimmed=false" fi -if [[ "$SHARED_COMPILATION" -eq 0 ]]; then - DOTNET_FLAGS+=('/p:UseSharedCompilation=false') +if [ "$SHARED_COMPILATION" -eq 0 ]; then + DOTNET_FLAGS="$DOTNET_FLAGS /p:UseSharedCompilation=false" fi -if [[ "$CLEAN" -eq 1 ]]; then - dotnet clean "${DOTNET_FLAGS[@]}" +if [ "$CLEAN" -eq 1 ]; then + dotnet clean $DOTNET_FLAGS rm -rf "$OUT" fi -if [[ "$TEST" -eq 1 ]]; then - dotnet test "$TESTS_PROJECT" "${DOTNET_FLAGS[@]}" +if [ "$TEST" -eq 1 ]; then + dotnet test "$TESTS_PROJECT" $DOTNET_FLAGS fi -dotnet publish "$MAIN_PROJECT" -o "$OUT" "${DOTNET_FLAGS[@]}" +dotnet publish "$MAIN_PROJECT" -o "$OUT" $DOTNET_FLAGS echo echo "SUCCESS: Compilation finished successfully! :)" diff --git a/run.sh b/run.sh index 1524e7343..3c5e04a44 100755 --- a/run.sh +++ b/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