diff --git a/.includes/topspeed.sh b/.includes/topspeed.sh index 2a10200..5852e76 100644 --- a/.includes/topspeed.sh +++ b/.includes/topspeed.sh @@ -3,9 +3,11 @@ topspeedUser="topspeed" topspeedHome="/var/lib/topspeed" topspeedInstallDir="${topspeedHome}/server" +topspeedRuntimeDir="${topspeedInstallDir}/topspeed" topspeedServiceFile="/etc/systemd/system/topspeed.service" topspeedServiceScript="${topspeedInstallDir}/topspeed-service.sh" topspeedStopScript="${topspeedInstallDir}/topspeed-stop.sh" +topspeedBinaryPath="${topspeedRuntimeDir}/TopSpeed.Server" topspeedSessionName="topspeed" topspeedRepoApi="https://api.github.com/repos/diamondStar35/top_speed/releases" topspeedAssetPattern='^TopSpeed\.Server-linux-arm64-Release-v-.*\.zip$' @@ -117,14 +119,14 @@ install_topspeed_server() { stop_topspeed_service_if_present # `sudoFlags` is initialized by the main launcher before sourcing this file. # 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" msgbox "Failed to create the Top Speed install directory." return 1 fi # shellcheck disable=SC2154 - if ! sudo "${sudoFlags[@]}" unzip -o -d "$topspeedInstallDir" "$archivePath"; then + if ! sudo "${sudoFlags[@]}" unzip -o -d "$topspeedRuntimeDir" "$archivePath"; then rm -rf "$archiveDir" msgbox "Failed to extract the Top Speed server archive." return 1 @@ -138,7 +140,19 @@ install_topspeed_server() { fi # 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" return 0 } @@ -150,50 +164,28 @@ write_topspeed_runtime_scripts() { tempServiceScript="$(mktemp)" tempStopScript="$(mktemp)" - cat > "$tempServiceScript" < "$tempServiceScript" < /dev/null; then tmux kill-session -t "\$sessionName" fi -binaryPath="\$(find_topspeed_binary)" || exit 1 -tmux new-session -d -s "\$sessionName" "\$binaryPath" || exit 1 +if [[ ! -x "\$binaryPath" ]]; then + exit 1 +fi + +tmux new-session -d -s "\$sessionName" "./TopSpeed.Server" || exit 1 while tmux has-session -t "\$sessionName" &> /dev/null; do sleep 5 done -if [[ -f "\$stopFlagPath" ]]; then - rm -f "\$stopFlagPath" - exit 0 -fi - exit 1 EOF @@ -201,9 +193,6 @@ EOF #!/usr/bin/env bash sessionName="${topspeedSessionName}" -stopFlagPath="${topspeedHome}/.stopping" - -touch "\$stopFlagPath" if tmux has-session -t "\$sessionName" &> /dev/null; then tmux send-keys -t "\$sessionName" C-c sleep 2 @@ -246,7 +235,7 @@ Wants=network-online.target Type=simple User=${topspeedUser} Group=${topspeedUser} -WorkingDirectory=${topspeedInstallDir} +WorkingDirectory=${topspeedRuntimeDir} ExecStart=${topspeedServiceScript} ExecStop=${topspeedStopScript} Restart=on-failure