Adjust code for setting up Top Speed.

This commit is contained in:
Storm Dragon
2026-04-17 15:01:34 -04:00
parent 793e8829d7
commit 5e64317744
+27 -38
View File
@@ -3,9 +3,11 @@
topspeedUser="topspeed" topspeedUser="topspeed"
topspeedHome="/var/lib/topspeed" topspeedHome="/var/lib/topspeed"
topspeedInstallDir="${topspeedHome}/server" topspeedInstallDir="${topspeedHome}/server"
topspeedRuntimeDir="${topspeedInstallDir}/topspeed"
topspeedServiceFile="/etc/systemd/system/topspeed.service" 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"
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$'
@@ -117,14 +119,14 @@ install_topspeed_server() {
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.
# shellcheck disable=SC2154 # shellcheck disable=SC2154
if ! sudo "${sudoFlags[@]}" install -d -o "$topspeedUser" -g "$topspeedUser" -m 755 "$topspeedInstallDir"; then if ! sudo "${sudoFlags[@]}" install -d -o "$topspeedUser" -g "$topspeedUser" -m 755 "$topspeedRuntimeDir"; then
rm -rf "$archiveDir" rm -rf "$archiveDir"
msgbox "Failed to create the Top Speed install directory." msgbox "Failed to create the Top Speed install directory."
return 1 return 1
fi fi
# shellcheck disable=SC2154 # shellcheck disable=SC2154
if ! sudo "${sudoFlags[@]}" unzip -o -d "$topspeedInstallDir" "$archivePath"; then if ! sudo "${sudoFlags[@]}" unzip -o -d "$topspeedRuntimeDir" "$archivePath"; then
rm -rf "$archiveDir" rm -rf "$archiveDir"
msgbox "Failed to extract the Top Speed server archive." msgbox "Failed to extract the Top Speed server archive."
return 1 return 1
@@ -138,7 +140,19 @@ install_topspeed_server() {
fi fi
# shellcheck disable=SC2154 # shellcheck disable=SC2154
sudo "${sudoFlags[@]}" find "$topspeedInstallDir" -type f -name 'TopSpeed.Server*' -exec chmod 755 {} + || true if ! sudo "${sudoFlags[@]}" test -f "$topspeedBinaryPath"; then
rm -rf "$archiveDir"
msgbox "The Top Speed server archive did not contain ${topspeedBinaryPath}."
return 1
fi
# shellcheck disable=SC2154
if ! sudo "${sudoFlags[@]}" chmod 755 "$topspeedBinaryPath"; then
rm -rf "$archiveDir"
msgbox "Failed to make ${topspeedBinaryPath} executable."
return 1
fi
rm -rf "$archiveDir" rm -rf "$archiveDir"
return 0 return 0
} }
@@ -150,50 +164,28 @@ write_topspeed_runtime_scripts() {
tempServiceScript="$(mktemp)" tempServiceScript="$(mktemp)"
tempStopScript="$(mktemp)" tempStopScript="$(mktemp)"
cat > "$tempServiceScript" <<EOF cat > "$tempServiceScript" <<EOF
#!/usr/bin/env bash #!/usr/bin/env bash
sessionName="${topspeedSessionName}" sessionName="${topspeedSessionName}"
installDir="${topspeedInstallDir}" runtimeDir="${topspeedRuntimeDir}"
stopFlagPath="${topspeedHome}/.stopping" binaryPath="${topspeedBinaryPath}"
binaryPath=""
find_topspeed_binary() { cd "\$runtimeDir" || exit 1
local exactBinary=""
local fallbackBinary=""
exactBinary="\$(find "\$installDir" -type f -name 'TopSpeed.Server' | sort | head -n 1)"
if [[ -n "\$exactBinary" ]]; then
printf '%s\n' "\$exactBinary"
return 0
fi
fallbackBinary="\$(find "\$installDir" -type f -name 'TopSpeed.Server*' | sort | head -n 1)"
if [[ -n "\$fallbackBinary" ]]; then
printf '%s\n' "\$fallbackBinary"
return 0
fi
return 1
}
rm -f "\$stopFlagPath"
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
binaryPath="\$(find_topspeed_binary)" || exit 1 if [[ ! -x "\$binaryPath" ]]; then
tmux new-session -d -s "\$sessionName" "\$binaryPath" || exit 1 exit 1
fi
tmux new-session -d -s "\$sessionName" "./TopSpeed.Server" || exit 1
while tmux has-session -t "\$sessionName" &> /dev/null; do while tmux has-session -t "\$sessionName" &> /dev/null; do
sleep 5 sleep 5
done done
if [[ -f "\$stopFlagPath" ]]; then
rm -f "\$stopFlagPath"
exit 0
fi
exit 1 exit 1
EOF EOF
@@ -201,9 +193,6 @@ EOF
#!/usr/bin/env bash #!/usr/bin/env bash
sessionName="${topspeedSessionName}" sessionName="${topspeedSessionName}"
stopFlagPath="${topspeedHome}/.stopping"
touch "\$stopFlagPath"
if tmux has-session -t "\$sessionName" &> /dev/null; then if tmux has-session -t "\$sessionName" &> /dev/null; then
tmux send-keys -t "\$sessionName" C-c tmux send-keys -t "\$sessionName" C-c
sleep 2 sleep 2
@@ -246,7 +235,7 @@ Wants=network-online.target
Type=simple Type=simple
User=${topspeedUser} User=${topspeedUser}
Group=${topspeedUser} Group=${topspeedUser}
WorkingDirectory=${topspeedInstallDir} WorkingDirectory=${topspeedRuntimeDir}
ExecStart=${topspeedServiceScript} ExecStart=${topspeedServiceScript}
ExecStop=${topspeedStopScript} ExecStop=${topspeedStopScript}
Restart=on-failure Restart=on-failure