Add TShock.Installer to download dotnet runtime
This will include a new ./TShock.Installer executable that will be for users without the dotnet runtime. This program will download the dotnet runtime, extract it, and then run ./TShock.Server for them using the downloaded runtime. Note: only tested on osx, likely a no-go for linux/windows until more testing occurs.
This commit is contained in:
parent
5d84192624
commit
45a378b0f0
4 changed files with 136 additions and 0 deletions
9
.github/workflows/ci-otapi3.yml
vendored
9
.github/workflows/ci-otapi3.yml
vendored
|
|
@ -36,6 +36,11 @@ jobs:
|
||||||
- name: Install msgfmt
|
- name: Install msgfmt
|
||||||
run: sudo apt-get install -y gettext
|
run: sudo apt-get install -y gettext
|
||||||
|
|
||||||
|
- name: Produce installer
|
||||||
|
run: |
|
||||||
|
cd TShockInstaller
|
||||||
|
dotnet publish -r ${{ matrix.arch }} -f net6.0 -c Release -p:PublishSingleFile=true --self-contained true
|
||||||
|
|
||||||
- name: Produce build
|
- name: Produce build
|
||||||
run: |
|
run: |
|
||||||
cd TShockLauncher
|
cd TShockLauncher
|
||||||
|
|
@ -46,6 +51,10 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
chmod +x TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/TShock.Server
|
chmod +x TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/TShock.Server
|
||||||
|
|
||||||
|
- name: Copy installer
|
||||||
|
run: |
|
||||||
|
cp TShockInstaller/bin/Release/net6.0/${{ matrix.arch }}/publish/* TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/
|
||||||
|
|
||||||
# preserve file perms: https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files
|
# preserve file perms: https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files
|
||||||
- name: Tarball artifact (non-Windows)
|
- name: Tarball artifact (non-Windows)
|
||||||
if: ${{ matrix.arch != 'win-x64' }}
|
if: ${{ matrix.arch != 'win-x64' }}
|
||||||
|
|
|
||||||
18
TShock.sln
18
TShock.sln
|
|
@ -26,6 +26,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TShockLauncher", "TShockLau
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TShockLauncher.Tests", "TShockLauncher.Tests\TShockLauncher.Tests.csproj", "{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TShockLauncher.Tests", "TShockLauncher.Tests\TShockLauncher.Tests.csproj", "{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockInstaller", "TShockInstaller\TShockInstaller.csproj", "{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
@ -102,6 +104,22 @@ Global
|
||||||
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x64.Build.0 = Release|Any CPU
|
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x86.ActiveCfg = Release|Any CPU
|
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x86.Build.0 = Release|Any CPU
|
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
||||||
93
TShockInstaller/Program.cs
Normal file
93
TShockInstaller/Program.cs
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using ICSharpCode.SharpZipLib.GZip;
|
||||||
|
using ICSharpCode.SharpZipLib.Tar;
|
||||||
|
|
||||||
|
Console.WriteLine($"TShock Installer {typeof(Program).GetType().Assembly.GetName().Version}.");
|
||||||
|
|
||||||
|
// reference: https://github.com/dotnet/install-scripts/blob/main/src/dotnet-install.sh
|
||||||
|
// ./dotnet-install.sh -verbose -version 6.0.11 --runtime dotnet
|
||||||
|
|
||||||
|
Console.WriteLine("Determining dotnet runtime url...");
|
||||||
|
|
||||||
|
string? url = null;
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
url = "https://dotnetcli.azureedge.net/dotnet/Runtime/6.0.11/dotnet-runtime-6.0.11-osx-x64.tar.gz";
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
url = "https://dotnetcli.azureedge.net/dotnet/Runtime/6.0.11/dotnet-runtime-6.0.11-win-x64.zip";
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
url = "https://dotnetcli.azureedge.net/dotnet/Runtime/6.0.11/dotnet-runtime-6.0.11-linux-x64.tar.gz";
|
||||||
|
|
||||||
|
if(url is null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unable to determine .net runtime to install. " +
|
||||||
|
"Refer to https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script " +
|
||||||
|
"and install using --install-dir dotnet, so that the dotnet folder is beside TShock.Server.dll");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Using url: " + url);
|
||||||
|
|
||||||
|
var filename = url.Split('/').Last();
|
||||||
|
var is_targz = filename.EndsWith(".tar.gz");
|
||||||
|
|
||||||
|
var download_info = new FileInfo(filename);
|
||||||
|
if (!download_info.Exists) // todo hash check
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Downloading: {filename}...");
|
||||||
|
|
||||||
|
using var client = new HttpClient();
|
||||||
|
using var resp = await client.GetStreamAsync(url);
|
||||||
|
using var fs = new FileStream(filename, FileMode.Create);
|
||||||
|
await resp.CopyToAsync(fs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Using existing download on disk: " + filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dotnet_path = Path.Combine("dotnet", "dotnet" + (is_targz ? "" : ".exe"));
|
||||||
|
var tshock_path = "TShock.Server" + (is_targz ? "" : ".exe");
|
||||||
|
|
||||||
|
if (!File.Exists(dotnet_path))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Extracting to ./dotnet/");
|
||||||
|
if (is_targz)
|
||||||
|
{
|
||||||
|
using var srm_dotnet_file = File.OpenRead(filename);
|
||||||
|
using var srm_gzip = new GZipInputStream(srm_dotnet_file);
|
||||||
|
|
||||||
|
using var tar_archive = TarArchive.CreateInputTarArchive(srm_gzip, System.Text.Encoding.UTF8);
|
||||||
|
tar_archive.ExtractContents("dotnet");
|
||||||
|
|
||||||
|
[DllImport("libc", SetLastError = true)]
|
||||||
|
static extern int chmod(string pathname, int mode);
|
||||||
|
|
||||||
|
chmod(dotnet_path, 755);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ZipFile.ExtractToDirectory(filename, "dotnet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Extract skipped, existing found at: {dotnet_path}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var dotnet_root = System.IO.Path.GetFullPath("dotnet");
|
||||||
|
Console.WriteLine($"To be able to run {tshock_path} yourself set the environment variable DOTNET_ROOT={dotnet_root}");
|
||||||
|
|
||||||
|
Environment.SetEnvironmentVariable("DOTNET_ROOT", dotnet_root);
|
||||||
|
|
||||||
|
Console.WriteLine($"Extracted, launching: {tshock_path}");
|
||||||
|
var proc = new Process();
|
||||||
|
proc.StartInfo = new()
|
||||||
|
{
|
||||||
|
FileName = tshock_path,
|
||||||
|
};
|
||||||
|
foreach (var arg in args)
|
||||||
|
proc.StartInfo.ArgumentList.Add(arg);
|
||||||
|
proc.Start();
|
||||||
|
await proc.WaitForExitAsync();
|
||||||
16
TShockInstaller/TShockInstaller.csproj
Normal file
16
TShockInstaller/TShockInstaller.csproj
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<Version>5.0.0</Version>
|
||||||
|
<PublishTrimmed>true</PublishTrimmed>
|
||||||
|
<AssemblyName>TShock.Installer</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="SharpZipLib" Version="1.4.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue