diff --git a/src/Tgstation.Server.Host/System/IPlatformIdentifier.cs b/src/Tgstation.Server.Host/System/IPlatformIdentifier.cs index 2036796994..b42b0a8a19 100644 --- a/src/Tgstation.Server.Host/System/IPlatformIdentifier.cs +++ b/src/Tgstation.Server.Host/System/IPlatformIdentifier.cs @@ -14,5 +14,10 @@ /// The extension of executable script files for the system /// string ScriptFileExtension { get; } + + /// + /// Check if the system is capable of running tgstation-server. + /// + void CheckCompatibility(); } } diff --git a/src/Tgstation.Server.Host/System/PlatformIdentifier.cs b/src/Tgstation.Server.Host/System/PlatformIdentifier.cs index c2ec1382aa..e0fe08363d 100644 --- a/src/Tgstation.Server.Host/System/PlatformIdentifier.cs +++ b/src/Tgstation.Server.Host/System/PlatformIdentifier.cs @@ -1,4 +1,8 @@ -using System.Runtime.InteropServices; +using LibGit2Sharp; +using Microsoft.Extensions.Logging; +using System; +using System.Runtime.InteropServices; +using Tgstation.Server.Host.Security; namespace Tgstation.Server.Host.System { @@ -11,13 +15,46 @@ namespace Tgstation.Server.Host.System /// public string ScriptFileExtension { get; } + /// + /// The for the . + /// + readonly ISystemIdentityFactory systemIdentityFactory; + + /// + /// The for the . + /// + readonly ILogger logger; + /// /// Construct a /// - public PlatformIdentifier() + /// The value of . + /// The value of . + public PlatformIdentifier(ISystemIdentityFactory systemIdentityFactory, ILogger logger) { + this.systemIdentityFactory = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory)); + this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); + IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); ScriptFileExtension = IsWindows ? "bat" : "sh"; } + + /// + public void CheckCompatibility() + { + try + { + new Repository().Dispose(); + } + catch + { + logger.LogCritical("Unable to initialize libgit2! This is a common problem on POSIX installations. Try using Docker."); + throw; + } + + using var systemIdentity = systemIdentityFactory.GetCurrent(); + if (!systemIdentity.CanCreateSymlinks) + throw new InvalidOperationException("The user running tgstation-server cannot create symlinks! Please try running as an administrative user!"); + } } }