1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2024-12-28 02:39:26 +00:00

Build updater for .NET Core macOS

This commit is contained in:
flightlevel 2019-03-03 15:01:07 +11:00
parent 88c6c4af6e
commit c28df96332
2 changed files with 39 additions and 23 deletions

View file

@ -14,9 +14,11 @@ var configuration = Argument("configuration", "Debug");
// Define directories.
var workingDir = MakeAbsolute(Directory("./"));
var artifactsDirName = "Artifacts";
var testResultsDirName = "TestResults";
var netCoreFramework = "netcoreapp2.2";
string artifactsDirName = "Artifacts";
string testResultsDirName = "TestResults";
string netCoreFramework = "netcoreapp2.2";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string updaterProjectPath = "./src/Jackett.Updater/Jackett.Updater.csproj";
//////////////////////////////////////////////////////////////////////
// TASKS
@ -89,7 +91,6 @@ Task("Package-Windows-Full-Framework")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = "./BuildOutput/net461/win7-x86/Jackett";
DotNetCorePublish(serverProjectPath, "net461", "win7-x86", buildOutputPath);
@ -119,7 +120,6 @@ Task("Package-Mono-Full-Framework")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = "./BuildOutput/net461/linux-x64/Jackett";
DotNetCorePublish(serverProjectPath, "net461", "linux-x64", buildOutputPath);
@ -154,11 +154,15 @@ Task("Package-DotNetCore-macOS")
.Does(() =>
{
string runtimeId = "osx-x64";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett";
string updaterOutputPath = buildOutputPath + "/Updater";
DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath);
DotNetCorePublish(updaterProjectPath, netCoreFramework, runtimeId, updaterOutputPath);
CopyFiles(updaterOutputPath + "/JackettUpdater*", buildOutputPath);
DeleteDirectory(updaterOutputPath, recursive:true);
CopyFileToDirectory("./install_service_macos", buildOutputPath);
Gzip($"./BuildOutput/{netCoreFramework}/{runtimeId}", $"./{artifactsDirName}", "Jackett", "Experimental.Jackett.Binaries.macOS.tar.gz");
@ -169,7 +173,6 @@ Task("Package-DotNetCore-LinuxAMD64")
.Does(() =>
{
string runtimeId = "linux-x64";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett";
DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath);
@ -185,7 +188,6 @@ Task("Package-DotNetCore-LinuxARM32")
.Does(() =>
{
string runtimeId = "linux-arm";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett";
DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath);
@ -201,7 +203,6 @@ Task("Package-DotNetCore-LinuxARM64")
.Does(() =>
{
string runtimeId = "linux-arm64";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett";
DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath);

View file

@ -30,16 +30,20 @@ namespace Jackett.Common.Services
IConfigurationService configService;
ManualResetEvent locker = new ManualResetEvent(false);
ITrayLockService lockService;
IProcessService processService;
IServiceConfigService windowsService;
private ServerConfig serverConfig;
bool forceupdatecheck = false;
Variants.JackettVariant variant = Variants.JackettVariant.NotFound;
public UpdateService(Logger l, WebClient c, IConfigurationService cfg, ITrayLockService ls, ServerConfig sc)
public UpdateService(Logger l, WebClient c, IConfigurationService cfg, ITrayLockService ls, IProcessService ps, IServiceConfigService ws, ServerConfig sc)
{
logger = l;
client = c;
configService = cfg;
lockService = ls;
processService = ps;
windowsService = ws;
serverConfig = sc;
}
@ -117,7 +121,6 @@ namespace Jackett.Common.Services
try
{
var response = await client.GetString(new WebRequest()
{
Url = "https://api.github.com/repos/Jackett/Jackett/releases",
@ -147,12 +150,14 @@ namespace Jackett.Common.Services
logger.Info($"New release found. Current: {currentVersion} New: {latestRelease.Name}");
try
{
var tempDir = await DownloadRelease(latestRelease.Assets, isWindows, latestRelease.Name);
var tempDir = await DownloadRelease(latestRelease.Assets, isWindows, latestRelease.Name);
// Copy updater
var installDir = Path.GetDirectoryName(ExePath());
var updaterPath = Path.Combine(tempDir, "Jackett", "JackettUpdater.exe");
var updaterPath = GetUpdaterPath(tempDir);
if (updaterPath != null)
{
StartUpdate(updaterPath, installDir, isWindows, serverConfig.RuntimeSettings.NoRestart, trayIsRunning);
}
}
catch (Exception e)
{
@ -178,6 +183,19 @@ namespace Jackett.Common.Services
}
}
private string GetUpdaterPath(string tempDirectory)
{
if (variant == Variants.JackettVariant.CoreMacOs || variant == Variants.JackettVariant.CoreLinuxAmd64 ||
variant == Variants.JackettVariant.CoreLinuxArm32 || variant == Variants.JackettVariant.CoreLinuxArm64)
{
return Path.Combine(tempDirectory, "Jackett", "JackettUpdater");
}
else
{
return Path.Combine(tempDirectory, "Jackett", "JackettUpdater.exe");
}
}
private string GetCurrentVersion()
{
var assembly = Assembly.GetExecutingAssembly();
@ -284,9 +302,6 @@ namespace Jackett.Common.Services
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayIsRunning)
{
string appType = "Console";
//DI once off Owin
IProcessService processService = new ProcessService(logger);
IServiceConfigService windowsService = new WindowsServiceConfigService(processService, logger);
if (isWindows && windowsService.ServiceExists() && windowsService.ServiceRunning())
{
@ -294,19 +309,14 @@ namespace Jackett.Common.Services
}
var exe = Path.GetFileName(ExePath());
var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(a => a.Contains(" ") ? "\"" +a + "\"" : a )).Replace("\"", "\\\"");
var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(a => a.Contains(" ") ? "\"" + a + "\"" : a )).Replace("\"", "\\\"");
var startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
// Note: add a leading space to the --Args argument to avoid parsing as arguments
if (isWindows)
{
startInfo.Arguments = $"--Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
startInfo.FileName = Path.Combine(updaterExePath);
}
else
if (variant == Variants.JackettVariant.Mono)
{
// Wrap mono
args = exe + " " + args;
@ -315,6 +325,11 @@ namespace Jackett.Common.Services
startInfo.Arguments = $"{Path.Combine(updaterExePath)} --Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
startInfo.FileName = "mono";
}
else
{
startInfo.Arguments = $"--Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
startInfo.FileName = Path.Combine(updaterExePath);
}
try
{