tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
PosixByondInstaller.cs
Go to the documentation of this file.
1using System;
2using System.Globalization;
3using System.Text;
4using System.Threading;
5using System.Threading.Tasks;
6
7using Microsoft.Extensions.Logging;
8using Microsoft.Extensions.Options;
9
14
16{
21 {
25 const string DreamDaemonExecutableName = "DreamDaemon";
26
30 const string DreamMakerExecutableName = "DreamMaker";
31
35 const string ShellScriptExtension = ".sh";
36
38 protected override string PathToUserFolder { get; }
39
42
44 protected override string OSMarkerTemplate => "Linux";
45
50
61 IIOManager ioManager,
63 IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions,
64 ILogger<PosixByondInstaller> logger)
65 : base(ioManager, logger, fileDownloader, generalConfigurationOptions)
66 {
67 this.postWriteHandler = postWriteHandler ?? throw new ArgumentNullException(nameof(postWriteHandler));
68
71 Environment.GetFolderPath(
72 Environment.SpecialFolder.UserProfile,
73 Environment.SpecialFolderOption.DoNotVerify),
74 "./.byond/cache"));
75 }
76
78 public override ValueTask UpgradeInstallation(EngineVersion version, string path, CancellationToken cancellationToken)
79 {
80 CheckVersionValidity(version);
81 ArgumentNullException.ThrowIfNull(path);
82
83 return ValueTask.CompletedTask;
84 }
85
87 public override ValueTask TrustDmbPath(EngineVersion version, string fullDmbPath, CancellationToken cancellationToken)
88 {
89 ArgumentNullException.ThrowIfNull(version);
90 ArgumentNullException.ThrowIfNull(fullDmbPath);
91
92 Logger.LogTrace("No need to trust .dmb path \"{path}\" on POSIX", fullDmbPath);
93 return ValueTask.CompletedTask;
94 }
95
97 protected override ValueTask InstallImpl(EngineVersion version, string path, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
98 {
99 // write the scripts for running the ting
100 // need to add $ORIGIN to LD_LIBRARY_PATH
101 const string StandardScript = "#!/bin/sh\nexport LD_LIBRARY_PATH=\"\\$ORIGIN:$LD_LIBRARY_PATH\"\nBASEDIR=$(dirname \"$0\")\nexec \"$BASEDIR/{0}\" \"$@\"\n";
102
103 var dreamDaemonScript = String.Format(CultureInfo.InvariantCulture, StandardScript, DreamDaemonExecutableName);
104 var dreamMakerScript = String.Format(CultureInfo.InvariantCulture, StandardScript, DreamMakerExecutableName);
105
106 async ValueTask WriteAndMakeExecutable(string pathToScript, string script)
107 {
108 Logger.LogTrace("Writing script {path}:{newLine}{scriptContents}", pathToScript, Environment.NewLine, script);
109 await IOManager.WriteAllBytes(pathToScript, Encoding.ASCII.GetBytes(script), cancellationToken);
111 }
112
113 var basePath = IOManager.ConcatPath(path, ByondBinPath);
114
115 var ddTask = WriteAndMakeExecutable(
116 IOManager.ConcatPath(basePath, GetDreamDaemonName(version.Version!, out _)),
117 dreamDaemonScript);
118
119 var dmTask = WriteAndMakeExecutable(
121 dreamMakerScript);
122
123 var task = ValueTaskExtensions.WhenAll(
124 ddTask,
125 dmTask);
126
129
130 return task;
131 }
132
134 protected override string GetDreamDaemonName(Version byondVersion, out bool supportsCli)
135 {
136 supportsCli = true;
138 }
139 }
140}
Information about an engine installation.
Version? Version
The System.Version of the engine. Currently only valid when Engine is EngineType.Byond.
Extension methods for the ValueTask and ValueTask<TResult> classes.
static async ValueTask WhenAll(IEnumerable< ValueTask > tasks)
Fully await a given list of tasks .
Base implementation of IEngineInstaller for EngineType.Byond.
readonly IFileDownloader fileDownloader
The IFileDownloader for the ByondInstallerBase.
const string ByondBinPath
The path to the BYOND bin folder.
void CheckVersionValidity(EngineVersion version)
Check that a given version is of type EngineType.Byond.
IIOManager IOManager
Gets the IIOManager for the EngineInstallerBase.
ILogger< EngineInstallerBase > Logger
Gets the ILogger for the EngineInstallerBase.
override ValueTask TrustDmbPath(EngineVersion version, string fullDmbPath, CancellationToken cancellationToken)
Add a given fullDmbPath to the trusted DMBs list in BYOND's config.A ValueTask representing the runn...
const string DreamDaemonExecutableName
The name of the DreamDaemon binary file.
override ValueTask InstallImpl(EngineVersion version, string path, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
readonly IPostWriteHandler postWriteHandler
The IPostWriteHandler for the PosixByondInstaller.
const string DreamMakerExecutableName
The name of the DreamMaker binary file.
const string ShellScriptExtension
File extension for shell scripts.
override string GetDreamDaemonName(Version byondVersion, out bool supportsCli)
PosixByondInstaller(IPostWriteHandler postWriteHandler, IIOManager ioManager, IFileDownloader fileDownloader, IOptionsMonitor< GeneralConfiguration > generalConfigurationOptions, ILogger< PosixByondInstaller > logger)
Initializes a new instance of the PosixByondInstaller class.
override ValueTask UpgradeInstallation(EngineVersion version, string path, CancellationToken cancellationToken)
Does actions necessary to get upgrade a version installed by a previous version of TGS....
Interface for using filesystems.
Definition IIOManager.cs:14
string ResolvePath()
Retrieve the full path of the current working directory.
string ConcatPath(params string[] paths)
Combines an array of strings into a path.
ValueTask WriteAllBytes(string path, byte[] contents, CancellationToken cancellationToken)
Writes some contents to a file at path overwriting previous content.
Handles changing file modes/permissions after writing.
void HandleWrite(string filePath)
For handling system specific necessities after a write.