tgstation-server 6.12.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;
8
12
14{
19 {
23 const string DreamDaemonExecutableName = "DreamDaemon";
24
28 const string DreamMakerExecutableName = "DreamMaker";
29
33 const string ShellScriptExtension = ".sh";
34
36 protected override string PathToUserFolder { get; }
37
40
42 protected override string ByondRevisionsUrlTemplate => "https://www.byond.com/download/build/{0}/{0}.{1}_byond_linux.zip";
43
48
58 IIOManager ioManager,
60 ILogger<PosixByondInstaller> logger)
61 : base(ioManager, logger, fileDownloader)
62 {
63 this.postWriteHandler = postWriteHandler ?? throw new ArgumentNullException(nameof(postWriteHandler));
64
67 Environment.GetFolderPath(
68 Environment.SpecialFolder.UserProfile,
69 Environment.SpecialFolderOption.DoNotVerify),
70 "./.byond/cache"));
71 }
72
74 public override ValueTask Install(EngineVersion version, string path, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
75 {
76 CheckVersionValidity(version);
77 ArgumentNullException.ThrowIfNull(path);
78
79 // write the scripts for running the ting
80 // need to add $ORIGIN to LD_LIBRARY_PATH
81 const string StandardScript = "#!/bin/sh\nexport LD_LIBRARY_PATH=\"\\$ORIGIN:$LD_LIBRARY_PATH\"\nBASEDIR=$(dirname \"$0\")\nexec \"$BASEDIR/{0}\" \"$@\"\n";
82
83 var dreamDaemonScript = String.Format(CultureInfo.InvariantCulture, StandardScript, DreamDaemonExecutableName);
84 var dreamMakerScript = String.Format(CultureInfo.InvariantCulture, StandardScript, DreamMakerExecutableName);
85
86 async ValueTask WriteAndMakeExecutable(string pathToScript, string script)
87 {
88 Logger.LogTrace("Writing script {path}:{newLine}{scriptContents}", pathToScript, Environment.NewLine, script);
89 await IOManager.WriteAllBytes(pathToScript, Encoding.ASCII.GetBytes(script), cancellationToken);
91 }
92
93 var basePath = IOManager.ConcatPath(path, ByondBinPath);
94
95 var ddTask = WriteAndMakeExecutable(
96 IOManager.ConcatPath(basePath, GetDreamDaemonName(version.Version!, out _)),
97 dreamDaemonScript);
98
99 var dmTask = WriteAndMakeExecutable(
101 dreamMakerScript);
102
103 var task = ValueTaskExtensions.WhenAll(
104 ddTask,
105 dmTask);
106
109
110 return task;
111 }
112
114 public override ValueTask UpgradeInstallation(EngineVersion version, string path, CancellationToken cancellationToken)
115 {
116 CheckVersionValidity(version);
117 ArgumentNullException.ThrowIfNull(path);
118
119 return ValueTask.CompletedTask;
120 }
121
123 public override ValueTask TrustDmbPath(EngineVersion version, string fullDmbPath, CancellationToken cancellationToken)
124 {
125 ArgumentNullException.ThrowIfNull(version);
126 ArgumentNullException.ThrowIfNull(fullDmbPath);
127
128 Logger.LogTrace("No need to trust .dmb path \"{path}\" on POSIX", fullDmbPath);
129 return ValueTask.CompletedTask;
130 }
131
133 protected override string GetDreamDaemonName(Version byondVersion, out bool supportsCli)
134 {
135 supportsCli = true;
137 }
138 }
139}
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.
readonly IPostWriteHandler postWriteHandler
The IPostWriteHandler for the PosixByondInstaller.
PosixByondInstaller(IPostWriteHandler postWriteHandler, IIOManager ioManager, IFileDownloader fileDownloader, ILogger< PosixByondInstaller > logger)
Initializes a new instance of the PosixByondInstaller class.
const string DreamMakerExecutableName
The name of the DreamMaker binary file.
override ValueTask Install(EngineVersion version, string path, bool deploymentPipelineProcesses, CancellationToken cancellationToken)
Does actions necessary to get an extracted installation working.A ValueTask representing the running ...
const string ShellScriptExtension
File extension for shell scripts.
override string GetDreamDaemonName(Version byondVersion, out bool supportsCli)
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:13
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.