Try to insure thatTop Speed sserver updates get applied and the service doesn't restart the old binary.
This commit is contained in:
@@ -8,6 +8,7 @@ topspeedServiceFile="/etc/systemd/system/topspeed.service"
|
|||||||
topspeedServiceScript="${topspeedInstallDir}/topspeed-service.sh"
|
topspeedServiceScript="${topspeedInstallDir}/topspeed-service.sh"
|
||||||
topspeedStopScript="${topspeedInstallDir}/topspeed-stop.sh"
|
topspeedStopScript="${topspeedInstallDir}/topspeed-stop.sh"
|
||||||
topspeedBinaryPath="${topspeedRuntimeDir}/TopSpeed.Server"
|
topspeedBinaryPath="${topspeedRuntimeDir}/TopSpeed.Server"
|
||||||
|
topspeedInstalledAssetFile="${topspeedRuntimeDir}/.installed-release"
|
||||||
topspeedSessionName="topspeed"
|
topspeedSessionName="topspeed"
|
||||||
topspeedRepoApi="https://api.github.com/repos/diamondStar35/top_speed/releases"
|
topspeedRepoApi="https://api.github.com/repos/diamondStar35/top_speed/releases"
|
||||||
topspeedAssetPattern='^TopSpeed\.Server-linux-arm64-Release-v-.*\.zip$'
|
topspeedAssetPattern='^TopSpeed\.Server-linux-arm64-Release-v-.*\.zip$'
|
||||||
@@ -112,9 +113,12 @@ stop_topspeed_service_if_present() {
|
|||||||
install_topspeed_server() {
|
install_topspeed_server() {
|
||||||
local archivePath=""
|
local archivePath=""
|
||||||
local archiveDir=""
|
local archiveDir=""
|
||||||
|
local assetName=""
|
||||||
|
local tempAssetFile=""
|
||||||
|
|
||||||
archivePath="$(fetch_topspeed_asset)" || return 1
|
archivePath="$(fetch_topspeed_asset)" || return 1
|
||||||
archiveDir="$(dirname "$archivePath")"
|
archiveDir="$(dirname "$archivePath")"
|
||||||
|
assetName="$(basename "$archivePath")"
|
||||||
|
|
||||||
stop_topspeed_service_if_present
|
stop_topspeed_service_if_present
|
||||||
# `sudoFlags` is initialized by the main launcher before sourcing this file.
|
# `sudoFlags` is initialized by the main launcher before sourcing this file.
|
||||||
@@ -153,7 +157,18 @@ install_topspeed_server() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
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 -rf "$archiveDir"
|
||||||
|
rm -f "$tempAssetFile"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,12 +185,63 @@ cat > "$tempServiceScript" <<EOF
|
|||||||
sessionName="${topspeedSessionName}"
|
sessionName="${topspeedSessionName}"
|
||||||
runtimeDir="${topspeedRuntimeDir}"
|
runtimeDir="${topspeedRuntimeDir}"
|
||||||
binaryPath="${topspeedBinaryPath}"
|
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
|
cd "\$runtimeDir" || exit 1
|
||||||
if tmux has-session -t "\$sessionName" &> /dev/null; then
|
if tmux has-session -t "\$sessionName" &> /dev/null; then
|
||||||
tmux kill-session -t "\$sessionName"
|
tmux kill-session -t "\$sessionName"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
update_from_latest_release
|
||||||
|
|
||||||
if [[ ! -x "\$binaryPath" ]]; then
|
if [[ ! -x "\$binaryPath" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user