Former-commit-id: d729686e79d9a1ece73cbc8c5b1d02c96d9d88f6
Former-commit-id: 819aa48a9395c5597ede7d8bfea6da7572bcfbc6
TSXN
wanggang 5 years ago
parent dfeb93b937
commit 95e47d949b

@ -16,6 +16,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\upload\" />
<Folder Include="wwwroot\upload\" />
</ItemGroup>
</Project>

@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace IoTDameon
@ -7,24 +8,26 @@ namespace IoTDameon
{
public static string Bash(this string cmd)
{
var fileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "powershell" : "/bin/bash";
var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)?"powershell": "/bin/bash",
FileName = fileName,
Arguments = $"-c \"{escapedArgs}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
Console.WriteLine($"# {fileName} {escapedArgs}");
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
process.Refresh();
process.Close();
return result;
}
}

@ -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;
}
}
}
}
}

@ -1,4 +1,4 @@
using System.Reflection;
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.20082702")]
[assembly: AssemblyInformationalVersion("1.0.0.20082703")]

@ -1,2 +1,2 @@
chmod 755 ~/publish/apps/IoTNode/IoTNode
chmod 755 ~/publish/apps/IoTNode/wwwroot/ffmpeg-linux-arm64
chmod 755 /root/publish/apps/IoTNode/IoTNode
chmod 755 /root/publish/apps/IoTNode/wwwroot/ffmpeg-linux-arm64
Loading…
Cancel
Save