Merge pull request #629 from tgstation/628-LinuxCompile

Modify LD_LIBRARY_PATH before invoke byond on Posix
This commit is contained in:
Jordan Brown
2018-09-13 10:16:13 -04:00
committed by GitHub
7 changed files with 39 additions and 10 deletions
@@ -13,11 +13,14 @@ namespace Tgstation.Server.Host.Components.Byond
/// <inheritdoc />
sealed class ByondManager : IByondManager
{
/// <summary>
/// The path to the BYOND bin folder
/// </summary>
public const string BinPath = "byond/bin";
const string VersionFileName = "Version.txt";
const string ActiveVersionFileName = "ActiveVersion.txt";
const string BinPath = "byond/bin";
/// <inheritdoc />
public Version ActiveVersion { get; private set; }
@@ -2,8 +2,10 @@
using System;
using System.Globalization;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host.Core;
using Tgstation.Server.Host.IO;
namespace Tgstation.Server.Host.Components.Byond
@@ -23,16 +25,21 @@ namespace Tgstation.Server.Host.Components.Byond
const string ByondCachePath = "~/.byond/cache";
/// <inheritdoc />
public string DreamDaemonName => "DreamDaemon";
public string DreamDaemonName => "DreamDaemon.sh";
/// <inheritdoc />
public string DreamMakerName => "DreamMaker";
public string DreamMakerName => "DreamMaker.sh";
/// <summary>
/// The <see cref="IIOManager"/> for the <see cref="PosixByondInstaller"/>
/// </summary>
readonly IIOManager ioManager;
/// <summary>
/// The <see cref="IPostWriteHandler"/> for the <see cref="PosixByondInstaller"/>
/// </summary>
readonly IPostWriteHandler postWriteHandler;
/// <summary>
/// The <see cref="ILogger"/> for the <see cref="PosixByondInstaller"/>
/// </summary>
@@ -42,10 +49,12 @@ namespace Tgstation.Server.Host.Components.Byond
/// Construct a <see cref="WindowsByondInstaller"/>
/// </summary>
/// <param name="ioManager">The value of <see cref="ioManager"/></param>
/// <param name="postWriteHandler">The value of <see cref="postWriteHandler"/></param>
/// <param name="logger">The value of <see cref="logger"/></param>
public PosixByondInstaller(IIOManager ioManager, ILogger<PosixByondInstaller> logger)
public PosixByondInstaller(IIOManager ioManager, IPostWriteHandler postWriteHandler, ILogger<PosixByondInstaller> logger)
{
this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
this.postWriteHandler = postWriteHandler ?? throw new ArgumentNullException(nameof(postWriteHandler));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
@@ -88,6 +97,24 @@ namespace Tgstation.Server.Host.Components.Byond
}
/// <inheritdoc />
public Task InstallByond(string path, Version version, CancellationToken cancellationToken) => Task.CompletedTask;
public Task InstallByond(string path, Version version, CancellationToken cancellationToken)
{
//write the scripts for running the ting
//need to add $ORIGIN to LD_LIBRARY_PATH
const string StandardScript = "#!/bin/sh\nexport LD_LIBRARY_PATH=\"\\$ORIGIN:$LD_LIBRARY_PATH\"\nBASEDIR=$(dirname \"$0\")\nexec \"$BASEDIR/{0}\" \"$@\"\n";
var dreamDaemonScript = String.Format(CultureInfo.InvariantCulture, StandardScript, "DreamDaemon");
var dreamMakerScript = String.Format(CultureInfo.InvariantCulture, StandardScript, "DreamMaker");
async Task WriteAndMakeExecutable(string fullPath, string script)
{
await ioManager.WriteAllBytes(fullPath, Encoding.ASCII.GetBytes(script), cancellationToken).ConfigureAwait(false);
postWriteHandler.HandleWrite(fullPath);
}
var basePath = ioManager.ConcatPath(path, ByondManager.BinPath);
return Task.WhenAll(WriteAndMakeExecutable(ioManager.ConcatPath(basePath, DreamDaemonName), dreamDaemonScript), WriteAndMakeExecutable(ioManager.ConcatPath(basePath, DreamMakerName), dreamMakerScript));
}
}
}
@@ -21,7 +21,6 @@ using System.Threading.Tasks;
using Tgstation.Server.Host.Components;
using Tgstation.Server.Host.Components.Byond;
using Tgstation.Server.Host.Components.Chat;
using Tgstation.Server.Host.Components.StaticFiles;
using Tgstation.Server.Host.Components.Watchdog;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Controllers;
@@ -1,4 +1,4 @@
namespace Tgstation.Server.Host.Components.StaticFiles
namespace Tgstation.Server.Host.Core
{
interface IPostWriteHandler
{
@@ -1,7 +1,7 @@
using Mono.Unix;
using Mono.Unix.Native;
namespace Tgstation.Server.Host.Components.StaticFiles
namespace Tgstation.Server.Host.Core
{
/// <summary>
/// <see cref="IPostWriteHandler"/> for POSIX systems
@@ -1,4 +1,4 @@
namespace Tgstation.Server.Host.Components.StaticFiles
namespace Tgstation.Server.Host.Core
{
/// <summary>
/// <see cref="IPostWriteHandler"/> for Windows systems