1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2024-12-29 11:17:22 +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. // Define directories.
var workingDir = MakeAbsolute(Directory("./")); var workingDir = MakeAbsolute(Directory("./"));
var artifactsDirName = "Artifacts"; string artifactsDirName = "Artifacts";
var testResultsDirName = "TestResults"; string testResultsDirName = "TestResults";
var netCoreFramework = "netcoreapp2.2"; string netCoreFramework = "netcoreapp2.2";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string updaterProjectPath = "./src/Jackett.Updater/Jackett.Updater.csproj";
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// TASKS // TASKS
@ -89,7 +91,6 @@ Task("Package-Windows-Full-Framework")
.IsDependentOn("Run-Unit-Tests") .IsDependentOn("Run-Unit-Tests")
.Does(() => .Does(() =>
{ {
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = "./BuildOutput/net461/win7-x86/Jackett"; string buildOutputPath = "./BuildOutput/net461/win7-x86/Jackett";
DotNetCorePublish(serverProjectPath, "net461", "win7-x86", buildOutputPath); DotNetCorePublish(serverProjectPath, "net461", "win7-x86", buildOutputPath);
@ -119,7 +120,6 @@ Task("Package-Mono-Full-Framework")
.IsDependentOn("Run-Unit-Tests") .IsDependentOn("Run-Unit-Tests")
.Does(() => .Does(() =>
{ {
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = "./BuildOutput/net461/linux-x64/Jackett"; string buildOutputPath = "./BuildOutput/net461/linux-x64/Jackett";
DotNetCorePublish(serverProjectPath, "net461", "linux-x64", buildOutputPath); DotNetCorePublish(serverProjectPath, "net461", "linux-x64", buildOutputPath);
@ -154,11 +154,15 @@ Task("Package-DotNetCore-macOS")
.Does(() => .Does(() =>
{ {
string runtimeId = "osx-x64"; string runtimeId = "osx-x64";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett"; string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett";
string updaterOutputPath = buildOutputPath + "/Updater";
DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath); DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath);
DotNetCorePublish(updaterProjectPath, netCoreFramework, runtimeId, updaterOutputPath);
CopyFiles(updaterOutputPath + "/JackettUpdater*", buildOutputPath);
DeleteDirectory(updaterOutputPath, recursive:true);
CopyFileToDirectory("./install_service_macos", buildOutputPath); CopyFileToDirectory("./install_service_macos", buildOutputPath);
Gzip($"./BuildOutput/{netCoreFramework}/{runtimeId}", $"./{artifactsDirName}", "Jackett", "Experimental.Jackett.Binaries.macOS.tar.gz"); Gzip($"./BuildOutput/{netCoreFramework}/{runtimeId}", $"./{artifactsDirName}", "Jackett", "Experimental.Jackett.Binaries.macOS.tar.gz");
@ -169,7 +173,6 @@ Task("Package-DotNetCore-LinuxAMD64")
.Does(() => .Does(() =>
{ {
string runtimeId = "linux-x64"; string runtimeId = "linux-x64";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett"; string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett";
DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath); DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath);
@ -185,7 +188,6 @@ Task("Package-DotNetCore-LinuxARM32")
.Does(() => .Does(() =>
{ {
string runtimeId = "linux-arm"; string runtimeId = "linux-arm";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett"; string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett";
DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath); DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath);
@ -201,7 +203,6 @@ Task("Package-DotNetCore-LinuxARM64")
.Does(() => .Does(() =>
{ {
string runtimeId = "linux-arm64"; string runtimeId = "linux-arm64";
string serverProjectPath = "./src/Jackett.Server/Jackett.Server.csproj";
string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett"; string buildOutputPath = $"./BuildOutput/{netCoreFramework}/{runtimeId}/Jackett";
DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath); DotNetCorePublish(serverProjectPath, netCoreFramework, runtimeId, buildOutputPath);

View file

@ -30,16 +30,20 @@ namespace Jackett.Common.Services
IConfigurationService configService; IConfigurationService configService;
ManualResetEvent locker = new ManualResetEvent(false); ManualResetEvent locker = new ManualResetEvent(false);
ITrayLockService lockService; ITrayLockService lockService;
IProcessService processService;
IServiceConfigService windowsService;
private ServerConfig serverConfig; private ServerConfig serverConfig;
bool forceupdatecheck = false; bool forceupdatecheck = false;
Variants.JackettVariant variant = Variants.JackettVariant.NotFound; 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; logger = l;
client = c; client = c;
configService = cfg; configService = cfg;
lockService = ls; lockService = ls;
processService = ps;
windowsService = ws;
serverConfig = sc; serverConfig = sc;
} }
@ -117,7 +121,6 @@ namespace Jackett.Common.Services
try try
{ {
var response = await client.GetString(new WebRequest() var response = await client.GetString(new WebRequest()
{ {
Url = "https://api.github.com/repos/Jackett/Jackett/releases", Url = "https://api.github.com/repos/Jackett/Jackett/releases",
@ -150,10 +153,12 @@ namespace Jackett.Common.Services
var tempDir = await DownloadRelease(latestRelease.Assets, isWindows, latestRelease.Name); var tempDir = await DownloadRelease(latestRelease.Assets, isWindows, latestRelease.Name);
// Copy updater // Copy updater
var installDir = Path.GetDirectoryName(ExePath()); var installDir = Path.GetDirectoryName(ExePath());
var updaterPath = Path.Combine(tempDir, "Jackett", "JackettUpdater.exe"); var updaterPath = GetUpdaterPath(tempDir);
if (updaterPath != null) if (updaterPath != null)
{
StartUpdate(updaterPath, installDir, isWindows, serverConfig.RuntimeSettings.NoRestart, trayIsRunning); StartUpdate(updaterPath, installDir, isWindows, serverConfig.RuntimeSettings.NoRestart, trayIsRunning);
} }
}
catch (Exception e) catch (Exception e)
{ {
logger.Error(e, "Error performing update."); logger.Error(e, "Error performing update.");
@ -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() private string GetCurrentVersion()
{ {
var assembly = Assembly.GetExecutingAssembly(); 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) private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayIsRunning)
{ {
string appType = "Console"; string appType = "Console";
//DI once off Owin
IProcessService processService = new ProcessService(logger);
IServiceConfigService windowsService = new WindowsServiceConfigService(processService, logger);
if (isWindows && windowsService.ServiceExists() && windowsService.ServiceRunning()) if (isWindows && windowsService.ServiceExists() && windowsService.ServiceRunning())
{ {
@ -294,19 +309,14 @@ namespace Jackett.Common.Services
} }
var exe = Path.GetFileName(ExePath()); 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(); var startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false; startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true; startInfo.CreateNoWindow = true;
// Note: add a leading space to the --Args argument to avoid parsing as arguments // Note: add a leading space to the --Args argument to avoid parsing as arguments
if (isWindows) if (variant == Variants.JackettVariant.Mono)
{
startInfo.Arguments = $"--Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
startInfo.FileName = Path.Combine(updaterExePath);
}
else
{ {
// Wrap mono // Wrap mono
args = exe + " " + args; args = exe + " " + args;
@ -315,6 +325,11 @@ namespace Jackett.Common.Services
startInfo.Arguments = $"{Path.Combine(updaterExePath)} --Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\""; startInfo.Arguments = $"{Path.Combine(updaterExePath)} --Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
startInfo.FileName = "mono"; startInfo.FileName = "mono";
} }
else
{
startInfo.Arguments = $"--Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\"";
startInfo.FileName = Path.Combine(updaterExePath);
}
try try
{ {