|
|
|
@ -4,7 +4,6 @@ using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Net;
|
|
|
|
@ -108,8 +107,10 @@ namespace IoTDameon
|
|
|
|
|
if (!File.Exists(file))
|
|
|
|
|
{
|
|
|
|
|
var bytes = this._httpClientFactory.CreateClient().GetAsync($"{server}/{name}").Result.Content.ReadAsByteArrayAsync().Result;
|
|
|
|
|
using var fs = File.Create(file);
|
|
|
|
|
fs.Write(bytes);
|
|
|
|
|
using (var fs = File.Create(file))
|
|
|
|
|
{
|
|
|
|
|
fs.Write(bytes);
|
|
|
|
|
}
|
|
|
|
|
currentCheckSum = getCheckSum(file);
|
|
|
|
|
if (currentCheckSum != lastCheckSum)
|
|
|
|
|
{
|
|
|
|
@ -144,6 +145,10 @@ namespace IoTDameon
|
|
|
|
|
//备份要更新的程序
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(backupPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(backupPath, true);
|
|
|
|
|
}
|
|
|
|
|
Directory.Move(appPath, backupPath);
|
|
|
|
|
this._logger.LogInformation($"back up {appPath}");
|
|
|
|
|
}
|
|
|
|
@ -154,9 +159,12 @@ namespace IoTDameon
|
|
|
|
|
}
|
|
|
|
|
Directory.CreateDirectory(appPath);
|
|
|
|
|
this._logger.LogInformation($"mkdir {appPath}");
|
|
|
|
|
foreach (var item in Directory.GetFiles(backupPath,"*.db"))
|
|
|
|
|
foreach (var item in Directory.GetFiles(backupPath))
|
|
|
|
|
{
|
|
|
|
|
File.Copy(item, Path.Combine(appPath, Path.GetFileName(item)));
|
|
|
|
|
if (item.EndsWith(".db") || item == "appsettings.json")
|
|
|
|
|
{
|
|
|
|
|
File.Copy(item, Path.Combine(appPath, Path.GetFileName(item)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this._logger.LogInformation($"copy db files to {appPath}");
|
|
|
|
|
//更新程序
|
|
|
|
@ -176,8 +184,7 @@ namespace IoTDameon
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
|
var updateScript = Path.Combine(appPath, "update.sh");
|
|
|
|
|
var command = $"-c \"chmod 755 {updateScript}\"";
|
|
|
|
|
Console.WriteLine(command);
|
|
|
|
|
var command = $"chmod 755 {updateScript}";
|
|
|
|
|
Console.WriteLine(command.Bash());
|
|
|
|
|
Console.WriteLine(updateScript.Bash());
|
|
|
|
|
this._logger.LogInformation($"chmod and run {updateScript}");
|
|
|
|
@ -191,10 +198,14 @@ namespace IoTDameon
|
|
|
|
|
|
|
|
|
|
private string getCheckSum(string file)
|
|
|
|
|
{
|
|
|
|
|
using var sha = SHA512.Create();
|
|
|
|
|
using var fs = File.OpenRead(file);
|
|
|
|
|
var checksum = BitConverter.ToString(sha.ComputeHash(fs)).Replace("-", "").ToLower();
|
|
|
|
|
return checksum;
|
|
|
|
|
using (var sha = SHA512.Create())
|
|
|
|
|
{
|
|
|
|
|
using (var fs = File.OpenRead(file))
|
|
|
|
|
{
|
|
|
|
|
var checksum = BitConverter.ToString(sha.ComputeHash(fs)).Replace("-", "").ToLower();
|
|
|
|
|
return checksum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|