From 300c1c19ec0d8115a7584dc8975771498fd2784e Mon Sep 17 00:00:00 2001 From: Archi Date: Sun, 26 Sep 2021 00:12:15 +0200 Subject: [PATCH] Implement some deduplication for overlay Including 3 same scripts for linux is overkill, osx and linux could also be aggregated to "unix" but too much work --- .github/workflows/publish.yml | 20 ++++- .../linux-x64/ArchiSteamFarm-Service.sh | 83 ------------------- .../ArchiSteamFarm-Service.sh | 0 .../overlay/osx-x64/ArchiSteamFarm-Service.sh | 83 ------------------- .../ArchiSteamFarm-Service.sh | 0 Dockerfile.Service | 1 + 6 files changed, 17 insertions(+), 170 deletions(-) delete mode 100755 ArchiSteamFarm/overlay/linux-x64/ArchiSteamFarm-Service.sh rename ArchiSteamFarm/overlay/{linux-arm => linux}/ArchiSteamFarm-Service.sh (100%) delete mode 100755 ArchiSteamFarm/overlay/osx-x64/ArchiSteamFarm-Service.sh rename ArchiSteamFarm/overlay/{linux-arm64 => osx}/ArchiSteamFarm-Service.sh (100%) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5cd26132d..b81a615f4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -126,15 +126,21 @@ jobs: publish() { if [ "$1" = 'generic' ]; then - local variantArgs="-p:TargetLatestRuntimePatch=false -p:UseAppHost=false" + variantArgs="-p:TargetLatestRuntimePatch=false -p:UseAppHost=false" else - local variantArgs="-p:PublishSingleFile=true -p:PublishTrimmed=true -r $1" + variantArgs="-p:PublishSingleFile=true -p:PublishTrimmed=true -r $1" fi dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/${1}" "-p:ASFVariant=$1" -p:ContinuousIntegrationBuild=true --no-restore --nologo $variantArgs # If we're including any overlay for this variant, copy it to output directory - if [ -d "ArchiSteamFarm/overlay/${1}" ]; then + variant_os="$(echo "$1" | cut -d '-' -f 1)" + + if [ -d "ArchiSteamFarm/overlay/${variant_os}" ]; then + cp -pR "ArchiSteamFarm/overlay/${variant_os}/"* "out/${1}" + fi + + if [ "$1" != "$variant_os" ] && [ -d "ArchiSteamFarm/overlay/${1}" ]; then cp -pR "ArchiSteamFarm/overlay/${1}/"* "out/${1}" fi @@ -249,7 +255,13 @@ jobs: } # If we're including any overlay for this variant, copy it to output directory - if (Test-Path "ArchiSteamFarm\overlay\$variant" -PathType Container) { + $variant_os = $variant.Split('-', 2)[0]; + + if (Test-Path "ArchiSteamFarm\overlay\$variant_os" -PathType Container) { + Copy-Item "ArchiSteamFarm\overlay\$variant_os\*" "out\$variant" -Recurse + } + + if (($variant -ne $variant_os) -and (Test-Path "ArchiSteamFarm\overlay\$variant" -PathType Container)) { Copy-Item "ArchiSteamFarm\overlay\$variant\*" "out\$variant" -Recurse } diff --git a/ArchiSteamFarm/overlay/linux-x64/ArchiSteamFarm-Service.sh b/ArchiSteamFarm/overlay/linux-x64/ArchiSteamFarm-Service.sh deleted file mode 100755 index cbbc09899..000000000 --- a/ArchiSteamFarm/overlay/linux-x64/ArchiSteamFarm-Service.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/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="${SCRIPT_DIR}/ArchiSteamFarm" - -if [ ! -f "$BINARY" ]; then - echo "ERROR: $BINARY could not be found!" - exit 1 -fi - -cd "$SCRIPT_DIR" - -BINARY_ARGS="" -PATH_NEXT=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 - ;; - *) - 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 - -while :; do - 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 - "$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 - "$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 - sleep 1 -done diff --git a/ArchiSteamFarm/overlay/linux-arm/ArchiSteamFarm-Service.sh b/ArchiSteamFarm/overlay/linux/ArchiSteamFarm-Service.sh similarity index 100% rename from ArchiSteamFarm/overlay/linux-arm/ArchiSteamFarm-Service.sh rename to ArchiSteamFarm/overlay/linux/ArchiSteamFarm-Service.sh diff --git a/ArchiSteamFarm/overlay/osx-x64/ArchiSteamFarm-Service.sh b/ArchiSteamFarm/overlay/osx-x64/ArchiSteamFarm-Service.sh deleted file mode 100755 index cbbc09899..000000000 --- a/ArchiSteamFarm/overlay/osx-x64/ArchiSteamFarm-Service.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/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="${SCRIPT_DIR}/ArchiSteamFarm" - -if [ ! -f "$BINARY" ]; then - echo "ERROR: $BINARY could not be found!" - exit 1 -fi - -cd "$SCRIPT_DIR" - -BINARY_ARGS="" -PATH_NEXT=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 - ;; - *) - 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 - -while :; do - 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 - "$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 - "$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 - sleep 1 -done diff --git a/ArchiSteamFarm/overlay/linux-arm64/ArchiSteamFarm-Service.sh b/ArchiSteamFarm/overlay/osx/ArchiSteamFarm-Service.sh similarity index 100% rename from ArchiSteamFarm/overlay/linux-arm64/ArchiSteamFarm-Service.sh rename to ArchiSteamFarm/overlay/osx/ArchiSteamFarm-Service.sh diff --git a/Dockerfile.Service b/Dockerfile.Service index 6995b6d62..9f15f22fd 100644 --- a/Dockerfile.Service +++ b/Dockerfile.Service @@ -42,6 +42,7 @@ RUN dotnet --info && \ if [ -f "ArchiSteamFarm/Localization/Strings.zh-TW.resx" ]; then ln -s "Strings.zh-TW.resx" "ArchiSteamFarm/Localization/Strings.zh-Hant.resx"; fi && \ if [ -n "${STEAM_TOKEN_DUMPER_TOKEN-}" ] && [ -f "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs" ]; then sed -i "s/STEAM_TOKEN_DUMPER_TOKEN/${STEAM_TOKEN_DUMPER_TOKEN}/g" "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs"; dotnet publish "${STEAM_TOKEN_DUMPER_NAME}" -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}" -p:ASFVariant=docker -p:ContinuousIntegrationBuild=true -p:SelfContained=false -p:UseAppHost=false -r "$asf_variant" --nologo; fi && \ dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -f "$NET_CORE_VERSION" -o "out/result" "-p:ASFVariant=${asf_variant}" -p:ContinuousIntegrationBuild=true -p:PublishSingleFile=true -p:PublishTrimmed=true -r "$asf_variant" --nologo && \ + if [ -d "ArchiSteamFarm/overlay/${TARGETOS}" ]; then cp -pR "ArchiSteamFarm/overlay/${TARGETOS}/"* "out/result"; fi && \ if [ -d "ArchiSteamFarm/overlay/${asf_variant}" ]; then cp -pR "ArchiSteamFarm/overlay/${asf_variant}/"* "out/result"; fi && \ if [ -d "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}" ]; then mkdir -p "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; cp -pR "out/${STEAM_TOKEN_DUMPER_NAME}/${NET_CORE_VERSION}/"* "out/result/plugins/${STEAM_TOKEN_DUMPER_NAME}"; fi