From c28df963322a5a0f54612ffae6499ad2cb9a838e Mon Sep 17 00:00:00 2001 From: flightlevel Date: Sun, 3 Mar 2019 15:01:07 +1100 Subject: [PATCH] Build updater for .NET Core macOS --- build.cake | 19 +++++---- src/Jackett.Common/Services/UpdateService.cs | 43 +++++++++++++------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/build.cake b/build.cake index dc1e334a7..32db9803d 100644 --- a/build.cake +++ b/build.cake @@ -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); diff --git a/src/Jackett.Common/Services/UpdateService.cs b/src/Jackett.Common/Services/UpdateService.cs index 38f7e7b17..a01d781da 100644 --- a/src/Jackett.Common/Services/UpdateService.cs +++ b/src/Jackett.Common/Services/UpdateService.cs @@ -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 {