2017-04-15 08:45:10 +00:00
|
|
|
|
using CommandLine;
|
2017-11-13 08:38:38 +00:00
|
|
|
|
using CommandLine.Text;
|
|
|
|
|
using Jackett.Common.Models.Config;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
using Jackett.Services;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
|
|
namespace Jackett.Updater
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
new Program().Run(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Run(string[] args)
|
|
|
|
|
{
|
2017-11-13 08:38:38 +00:00
|
|
|
|
Engine.BuildContainer(new RuntimeSettings()
|
|
|
|
|
{
|
|
|
|
|
CustomLogFileName = "updater.txt"
|
|
|
|
|
});
|
2017-04-15 08:45:10 +00:00
|
|
|
|
Engine.Logger.Info("Jackett Updater v" + GetCurrentVersion());
|
|
|
|
|
Engine.Logger.Info("Options \"" + string.Join("\" \"", args) + "\"");
|
|
|
|
|
try {
|
2017-11-13 08:38:38 +00:00
|
|
|
|
var optionsResult = Parser.Default.ParseArguments<UpdaterConsoleOptions>(args);
|
|
|
|
|
optionsResult.WithParsed(options =>
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
ProcessUpdate(options);
|
|
|
|
|
}
|
2017-11-13 08:38:38 +00:00
|
|
|
|
);
|
|
|
|
|
optionsResult.WithNotParsed(errors =>
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
2017-11-13 08:38:38 +00:00
|
|
|
|
Engine.Logger.Error(HelpText.AutoBuild(optionsResult));
|
2017-04-15 08:45:10 +00:00
|
|
|
|
Engine.Logger.Error("Failed to process update arguments!");
|
|
|
|
|
Console.ReadKey();
|
2017-11-13 08:38:38 +00:00
|
|
|
|
});
|
2017-04-15 08:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Error(e, "Exception applying update!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetCurrentVersion()
|
|
|
|
|
{
|
2017-11-13 08:38:38 +00:00
|
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
|
|
|
|
|
return fvi.FileVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void KillPids(int[] pids)
|
|
|
|
|
{
|
|
|
|
|
foreach (var pid in pids)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var proc = Process.GetProcessById(pid);
|
|
|
|
|
Engine.Logger.Info("Killing process " + proc.Id);
|
|
|
|
|
proc.Kill();
|
|
|
|
|
var exited = proc.WaitForExit(5000);
|
|
|
|
|
if (!exited)
|
|
|
|
|
Engine.Logger.Info("Process " + pid.ToString() + " didn't exit within 5 seconds");
|
2017-11-08 14:45:21 +00:00
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
|
}
|
2017-06-28 05:31:38 +00:00
|
|
|
|
catch (ArgumentException)
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Info("Process " + pid.ToString() + " is already dead");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Info("Error killing process " + pid.ToString());
|
|
|
|
|
Engine.Logger.Info(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessUpdate(UpdaterConsoleOptions options)
|
|
|
|
|
{
|
|
|
|
|
var updateLocation = GetUpdateLocation();
|
|
|
|
|
if(!(updateLocation.EndsWith("\\") || updateLocation.EndsWith("/")))
|
|
|
|
|
{
|
|
|
|
|
updateLocation += Path.DirectorySeparatorChar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pids = new int[] { };
|
|
|
|
|
if (options.KillPids != null)
|
|
|
|
|
{
|
|
|
|
|
var pidsStr = options.KillPids.Split(',').Where(pid => !string.IsNullOrWhiteSpace(pid)).ToArray();
|
|
|
|
|
pids = Array.ConvertAll(pidsStr, pid => int.Parse(pid));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var isWindows = System.Environment.OSVersion.Platform != PlatformID.Unix;
|
|
|
|
|
var trayRunning = false;
|
|
|
|
|
var trayProcesses = Process.GetProcessesByName("JackettTray");
|
|
|
|
|
if (isWindows)
|
|
|
|
|
{
|
|
|
|
|
if (trayProcesses.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var proc in trayProcesses)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Info("Killing tray process " + proc.Id);
|
|
|
|
|
proc.Kill();
|
|
|
|
|
trayRunning = true;
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// on unix we don't have to wait (we can overwrite files which are in use)
|
|
|
|
|
// On unix we kill the PIDs after the update so e.g. systemd can automatically restart the process
|
|
|
|
|
KillPids(pids);
|
|
|
|
|
}
|
|
|
|
|
Engine.Logger.Info("Finding files in: " + updateLocation);
|
|
|
|
|
var files = Directory.GetFiles(updateLocation, "*.*", SearchOption.AllDirectories);
|
|
|
|
|
foreach(var file in files)
|
|
|
|
|
{
|
|
|
|
|
var fileName = Path.GetFileName(file).ToLowerInvariant();
|
|
|
|
|
|
|
|
|
|
if (fileName.EndsWith(".zip") ||
|
|
|
|
|
fileName.EndsWith(".tar") ||
|
|
|
|
|
fileName.EndsWith(".gz"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
Engine.Logger.Info("Copying " + fileName);
|
|
|
|
|
var dest = Path.Combine(options.Path, file.Substring(updateLocation.Length));
|
|
|
|
|
var destDir = Path.GetDirectoryName(dest);
|
|
|
|
|
if (!Directory.Exists(destDir))
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Info("Creating directory " + destDir);
|
|
|
|
|
Directory.CreateDirectory(destDir);
|
|
|
|
|
}
|
|
|
|
|
File.Copy(file, dest, true);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delete old dirs
|
|
|
|
|
string[] oldDirs = new string[] { "Content/logos" };
|
|
|
|
|
|
|
|
|
|
foreach (var oldDir in oldDirs)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var deleteDir = Path.Combine(options.Path, oldDir);
|
|
|
|
|
if (Directory.Exists(deleteDir))
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Info("Deleting directory " + deleteDir);
|
|
|
|
|
Directory.Delete(deleteDir, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// delete old files
|
|
|
|
|
string[] oldFiles = new string[] {
|
|
|
|
|
"Content/css/jquery.dataTables.css",
|
|
|
|
|
"Content/css/jquery.dataTables_themeroller.css",
|
|
|
|
|
"Definitions/tspate.yml",
|
|
|
|
|
"Definitions/freakstrackingsystem.yml",
|
|
|
|
|
"Definitions/rarbg.yml",
|
|
|
|
|
"Definitions/t411.yml",
|
|
|
|
|
"Definitions/hdbc.yml", // renamed to hdbitscom
|
2017-08-11 11:45:49 +00:00
|
|
|
|
"Definitions/maniatorrent.yml",
|
2017-05-06 13:30:00 +00:00
|
|
|
|
"Definitions/nyaa.yml",
|
2017-06-06 17:06:30 +00:00
|
|
|
|
"Definitions/nachtwerk.yml",
|
2017-08-18 15:59:40 +00:00
|
|
|
|
"Definitions/leparadisdunet.yml",
|
2017-08-18 16:28:39 +00:00
|
|
|
|
"Definitions/qctorrent.yml",
|
2017-08-28 12:51:33 +00:00
|
|
|
|
"Definitions/dragonworld.yml",
|
2017-09-03 10:16:37 +00:00
|
|
|
|
"Definitions/hdclub.yml",
|
2017-09-11 13:10:54 +00:00
|
|
|
|
"Definitions/polishtracker.yml",
|
2017-09-15 15:08:33 +00:00
|
|
|
|
"Definitions/zetorrents.yml",
|
2017-09-22 06:04:52 +00:00
|
|
|
|
"Definitions/rapidetracker.yml",
|
2017-10-03 12:04:29 +00:00
|
|
|
|
"Definitions/isohunt.yml",
|
2017-10-31 21:05:54 +00:00
|
|
|
|
"Definitions/t411v2.yml",
|
2017-11-06 14:12:42 +00:00
|
|
|
|
"Definitions/bithq.yml",
|
2017-11-06 14:15:02 +00:00
|
|
|
|
"Definitions/blubits.yml",
|
2017-11-07 18:44:34 +00:00
|
|
|
|
"Definitions/torrentproject.yml",
|
2017-12-02 04:09:55 +00:00
|
|
|
|
"Definitions/torrentvault.yml",
|
2017-12-05 15:15:19 +00:00
|
|
|
|
"Definitions/apollo.yml", // migrated to C# gazelle base tracker
|
2018-01-03 18:51:00 +00:00
|
|
|
|
"Definitions/secretcinema.yml", // migrated to C# gazelle base tracker
|
2018-01-10 13:19:35 +00:00
|
|
|
|
"Definitions/utorrents.yml", // same as SzeneFZ now
|
2018-01-10 17:20:52 +00:00
|
|
|
|
"Definitions/ultrahdclub.yml",
|
2018-01-10 18:04:53 +00:00
|
|
|
|
"Definitions/infinityt.yml",
|
2018-01-31 18:43:53 +00:00
|
|
|
|
"Definitions/hachede-c.yml",
|
2018-02-13 22:49:42 +00:00
|
|
|
|
"Definitions/hd4Free.yml",
|
2018-02-21 18:11:48 +00:00
|
|
|
|
"Definitions/skytorrents.yml",
|
2018-03-05 17:51:53 +00:00
|
|
|
|
"Definitions/gormogon.yml",
|
2018-03-05 17:56:01 +00:00
|
|
|
|
"Definitions/czteam.yml",
|
2017-04-15 08:45:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (var oldFIle in oldFiles)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var deleteFile = Path.Combine(options.Path, oldFIle);
|
|
|
|
|
if (File.Exists(deleteFile))
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Info("Deleting file " + deleteFile);
|
|
|
|
|
File.Delete(deleteFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Engine.Logger.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// kill pids after the update on UNIX
|
|
|
|
|
if (!isWindows)
|
|
|
|
|
KillPids(pids);
|
|
|
|
|
|
|
|
|
|
if (options.NoRestart == false)
|
|
|
|
|
{
|
|
|
|
|
if (trayRunning)
|
|
|
|
|
{
|
|
|
|
|
var startInfo = new ProcessStartInfo()
|
|
|
|
|
{
|
|
|
|
|
Arguments = options.Args,
|
|
|
|
|
FileName = Path.Combine(options.Path, "JackettTray.exe"),
|
|
|
|
|
UseShellExecute = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Process.Start(startInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(string.Equals(options.Type, "JackettService.exe", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var serviceHelper = new ServiceConfigService(null, null);
|
|
|
|
|
if (serviceHelper.ServiceExists())
|
|
|
|
|
{
|
|
|
|
|
serviceHelper.Start();
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
var startInfo = new ProcessStartInfo()
|
|
|
|
|
{
|
|
|
|
|
Arguments = options.Args,
|
|
|
|
|
FileName = Path.Combine(options.Path, "JackettConsole.exe"),
|
|
|
|
|
UseShellExecute = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!isWindows)
|
|
|
|
|
{
|
|
|
|
|
startInfo.Arguments = startInfo.FileName + " " + startInfo.Arguments;
|
|
|
|
|
startInfo.FileName = "mono";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Engine.Logger.Info("Starting Jackett: " + startInfo.FileName + " " + startInfo.Arguments);
|
|
|
|
|
Process.Start(startInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetUpdateLocation()
|
|
|
|
|
{
|
|
|
|
|
var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase);
|
|
|
|
|
return new FileInfo(HttpUtility.UrlDecode(location.AbsolutePath)).DirectoryName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|