Try to insure thatTop Speed sserver updates get applied and the service doesn't restart the old binary.

This commit is contained in:
Storm Dragon
2026-04-29 20:57:42 -04:00
parent 863495d169
commit 8959f1ba94

View File

@@ -8,6 +8,7 @@ topspeedServiceFile="/etc/systemd/system/topspeed.service"
topspeedServiceScript="${topspeedInstallDir}/topspeed-service.sh"
topspeedStopScript="${topspeedInstallDir}/topspeed-stop.sh"
topspeedBinaryPath="${topspeedRuntimeDir}/TopSpeed.Server"
topspeedInstalledAssetFile="${topspeedRuntimeDir}/.installed-release"
topspeedSessionName="topspeed"
topspeedRepoApi="https://api.github.com/repos/diamondStar35/top_speed/releases"
topspeedAssetPattern='^TopSpeed\.Server-linux-arm64-Release-v-.*\.zip$'
@@ -112,9 +113,12 @@ stop_topspeed_service_if_present() {
install_topspeed_server() {
local archivePath=""
local archiveDir=""
local assetName=""
local tempAssetFile=""
archivePath="$(fetch_topspeed_asset)" || return 1
archiveDir="$(dirname "$archivePath")"
assetName="$(basename "$archivePath")"
stop_topspeed_service_if_present
# `sudoFlags` is initialized by the main launcher before sourcing this file.
@@ -153,7 +157,18 @@ install_topspeed_server() {
return 1
fi
tempAssetFile="$(mktemp)"
printf '%s\n' "$assetName" > "$tempAssetFile"
# shellcheck disable=SC2154
if ! sudo "${sudoFlags[@]}" install -o "$topspeedUser" -g "$topspeedUser" -m 644 "$tempAssetFile" "$topspeedInstalledAssetFile"; then
rm -rf "$archiveDir"
rm -f "$tempAssetFile"
msgbox "Failed to record the installed Top Speed release."
return 1
fi
rm -rf "$archiveDir"
rm -f "$tempAssetFile"
return 0
}
@@ -170,12 +185,63 @@ cat > "$tempServiceScript" <<EOF
sessionName="${topspeedSessionName}"
runtimeDir="${topspeedRuntimeDir}"
binaryPath="${topspeedBinaryPath}"
installedAssetFile="${topspeedInstalledAssetFile}"
repoApi="${topspeedRepoApi}"
assetPattern="${topspeedAssetPattern}"
update_from_latest_release() {
local tempDir=""
local metadataFile=""
local latestAssetName=""
local latestAssetUrl=""
local currentAssetName=""
local archivePath=""
tempDir="\$(mktemp -d)" || return 0
metadataFile="\${tempDir}/topspeed-release.json"
if ! curl -fsSL -H "Accept: application/vnd.github+json" "\$repoApi" -o "\$metadataFile"; then
rm -rf "\$tempDir"
return 0
fi
latestAssetName="\$(jq -r --arg assetPattern "\$assetPattern" '
([.[] | .assets[] | select(.name | test(\$assetPattern))] | .[0].name) // empty
' "\$metadataFile")"
latestAssetUrl="\$(jq -r --arg assetPattern "\$assetPattern" '
([.[] | .assets[] | select(.name | test(\$assetPattern))] | .[0].browser_download_url) // empty
' "\$metadataFile")"
if [[ -f "\$installedAssetFile" ]]; then
currentAssetName="\$(< "\$installedAssetFile")"
fi
if [[ -z "\$latestAssetName" || -z "\$latestAssetUrl" || "\$latestAssetName" == "null" || "\$latestAssetUrl" == "null" || "\$latestAssetName" == "\$currentAssetName" ]]; then
rm -rf "\$tempDir"
return 0
fi
archivePath="\${tempDir}/\${latestAssetName}"
if ! curl -fL --retry 5 -o "\$archivePath" "\$latestAssetUrl"; then
rm -rf "\$tempDir"
return 0
fi
if unzip -o -d "\$runtimeDir" "\$archivePath" && chmod 755 "\$binaryPath"; then
printf '%s\n' "\$latestAssetName" > "\$installedAssetFile"
fi
rm -rf "\$tempDir"
return 0
}
cd "\$runtimeDir" || exit 1
if tmux has-session -t "\$sessionName" &> /dev/null; then
tmux kill-session -t "\$sessionName"
fi
update_from_latest_release
if [[ ! -x "\$binaryPath" ]]; then
exit 1
fi