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
This commit is contained in:
Archi 2021-09-26 00:12:15 +02:00
parent c7fd08273b
commit 300c1c19ec
No known key found for this signature in database
GPG key ID: 6B138B4C64555AEA
6 changed files with 17 additions and 170 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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