diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/Main.kt b/server/desktop/src/main/java/dev/slimevr/desktop/Main.kt index 6e27c6a41..0d8b19baf 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/Main.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/Main.kt @@ -61,7 +61,7 @@ fun main(args: Array) = runBlocking { } else { arrayOf("udevadm", "cat") } - featureFlags.udevRulesInstalled = executeShellCommand(*command)?.contains("slime") + featureFlags.udevRulesInstalled = executeShellCommand(*command)?.second?.contains("slime") } val configFolder = resolveConfigDirectory() ?: error("Unable to resolve config folder") diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/install/install.kt b/server/desktop/src/main/java/dev/slimevr/desktop/install/install.kt index 5521c994f..ce55682b3 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/install/install.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/install/install.kt @@ -16,16 +16,34 @@ suspend fun runInstaller() { } } -suspend fun executeShellCommand(vararg command: String): String? = try { - val process = withContext(Dispatchers.IO) { - ProcessBuilder(*command) +suspend fun executeShellCommand(vararg command: String): Pair? = try { + withContext(Dispatchers.IO) { + val process = ProcessBuilder(*command) .redirectErrorStream(true) .start() - } - process.inputStream.bufferedReader().readText().also { + + val output = process.inputStream.bufferedReader().readText() process.waitFor() + Pair(process.exitValue(), output) } } catch (e: IOException) { AppLogger.install.warn("Error executing shell command: ${e.message}") null } + +// vrpathreg returns 1 if the driver is not present +fun shouldInstallDriver(exitCode: Int): Boolean = exitCode == 1 + +// get a descriptive reason why we're skipping driver installation +// Exit codes from vrpathreg output: +// 0 : Success +// 1 : ( finddriver only ) Driver not present +// 2 : ( finddriver only ) Error, driver installed more than once +// -1 : Configuration or permission problem +// -2 : Argument problem +fun getDriverInstallSkipReason(exitCode: Int): String = when (exitCode) { + 0 -> "driver already installed" + 2 -> "driver installed more than once" + -1 -> "SteamVR is misconfigured" + else -> "unknown reason ($exitCode)" +} diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/install/linux.kt b/server/desktop/src/main/java/dev/slimevr/desktop/install/linux.kt index 9f04540d7..7c0c66502 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/install/linux.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/install/linux.kt @@ -2,7 +2,9 @@ package dev.slimevr.desktop.install import dev.slimevr.AppLogger import dev.slimevr.FeatureFlags +import dev.slimevr.desktop.linux.findAppLibraryLocation +private const val STEAMVR_APPID = 250820 private const val LINUX_STEAM_DRIVER_DIRECTORY = "slimevr-openvr-driver-x64-linux" suspend fun installLinux() { @@ -10,21 +12,32 @@ suspend fun installLinux() { } private suspend fun installLinuxSteamVRDriver() { - val path = System.getProperty("user.dir") - val vrPathReg = "${System.getProperty("user.home")}/.steam/steam/steamapps/common/SteamVR/bin/vrpathreg.sh" - val existing = executeShellCommand(vrPathReg) - if (existing == null) { - AppLogger.install.warn("SteamVR driver installation failed") + val workingDir = System.getProperty("user.dir") + val steamVRLocation = try { + findAppLibraryLocation(STEAMVR_APPID).resolve("steamapps/common/SteamVR") + } catch (e: Exception) { + AppLogger.install.warn(e, "SteamVR driver installation failed (couldn't find SteamVR install location)") return } - if (existing.contains("slimevr")) { - AppLogger.install.info("SteamVR driver is already installed") + val pathRegPath = steamVRLocation.resolve("bin/vrpathreg.sh").toString() + + val (findExitCode, _) = executeShellCommand(pathRegPath, "finddriver", "slimevr") ?: run { + AppLogger.install.warn("SteamVR driver installation failed (failed to run vrpathreg finddriver)") return } - executeShellCommand(vrPathReg, "adddriver", "$path/$LINUX_STEAM_DRIVER_DIRECTORY") - if (executeShellCommand(vrPathReg)?.contains("slimevr") != true) { - AppLogger.install.warn("Failed to install SteamVR driver") + if (!shouldInstallDriver(findExitCode)) { + AppLogger.install.info("Skipping SteamVR driver installation (${getDriverInstallSkipReason(findExitCode)})") return } + + val (addExitCode, _) = executeShellCommand(pathRegPath, "adddriver", "$workingDir/$LINUX_STEAM_DRIVER_DIRECTORY") ?: run { + AppLogger.install.warn("SteamVR driver installation failed (failed to run vrpathreg adddriver)") + return + } + if (addExitCode != 0) { + AppLogger.install.warn("SteamVR driver installation failed (vrpathreg adddriver exited with code $addExitCode)") + return + } + AppLogger.install.info("SteamVR driver successfully installed") } diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/install/windows.kt b/server/desktop/src/main/java/dev/slimevr/desktop/install/windows.kt index 9c688bf37..e78e3f7c6 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/install/windows.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/install/windows.kt @@ -3,6 +3,8 @@ package dev.slimevr.desktop.install import com.sun.jna.platform.win32.Advapi32Util import com.sun.jna.platform.win32.WinReg import dev.slimevr.AppLogger +import kotlin.io.path.Path +import kotlin.io.path.exists private const val WINDOWS_STEAMVR_DRIVER_DIRECTORY = "slimevr-openvr-driver-win64" @@ -23,27 +25,40 @@ private suspend fun getKeyByPath(hkey: WinReg.HKEY, path: String): Map