mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-23 21:16:52 +01:00
PlatformIdentifier now performs compatibility checks
This commit is contained in:
@@ -14,5 +14,10 @@
|
||||
/// The extension of executable script files for the system
|
||||
/// </summary>
|
||||
string ScriptFileExtension { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Check if the system is capable of running tgstation-server.
|
||||
/// </summary>
|
||||
void CheckCompatibility();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// <inheritdoc />
|
||||
public string ScriptFileExtension { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ISystemIdentityFactory"/> for the <see cref="PlatformIdentifier"/>.
|
||||
/// </summary>
|
||||
readonly ISystemIdentityFactory systemIdentityFactory;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ILogger"/> for the <see cref="PlatformIdentifier"/>.
|
||||
/// </summary>
|
||||
readonly ILogger<PlatformIdentifier> logger;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="PlatformIdentifier"/>
|
||||
/// </summary>
|
||||
public PlatformIdentifier()
|
||||
/// <param name="systemIdentityFactory">The value of <see cref="ISystemIdentityFactory"/>.</param>
|
||||
/// <param name="logger">The value of <see cref="logger"/>.</param>
|
||||
public PlatformIdentifier(ISystemIdentityFactory systemIdentityFactory, ILogger<PlatformIdentifier> 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";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user