mirror of
https://github.com/Unifi-Tools/UFiber.Configurator.git
synced 2025-02-05 18:28:28 +00:00
Merge pull request #6 from Unifi-Tools/allow-restore
Allow previous versions of the firmware.
This commit is contained in:
commit
ac22b369b0
|
@ -38,6 +38,9 @@ var rootCommand = new RootCommand("Apply configuration changes to UFiber devices
|
||||||
new Option<string>(
|
new Option<string>(
|
||||||
"--mac",
|
"--mac",
|
||||||
"The desired MAC address to clone.", ArgumentArity.ZeroOrOne),
|
"The desired MAC address to clone.", ArgumentArity.ZeroOrOne),
|
||||||
|
new Option<string>(
|
||||||
|
"--restore",
|
||||||
|
"Restore a previous version of the firmware.", ArgumentArity.ZeroOrOne)
|
||||||
};
|
};
|
||||||
|
|
||||||
SshClient GetSSHClient(string userName, string password, string host, int port = 22)
|
SshClient GetSSHClient(string userName, string password, string host, int port = 22)
|
||||||
|
@ -55,8 +58,8 @@ ScpClient GetSCPClient(string userName, string password, string host, int port =
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCommand.Handler = CommandHandler
|
rootCommand.Handler = CommandHandler
|
||||||
.Create<string, string, string, int, bool, string, string, string, string>(
|
.Create<string, string, string, int, bool, string, string, string, string, string>(
|
||||||
(host, user, pw, port, dryRun, slid, vendor, serial, mac) =>
|
(host, user, pw, port, dryRun, slid, vendor, serial, mac, fwToRestore) =>
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(host))
|
if (string.IsNullOrWhiteSpace(host))
|
||||||
{
|
{
|
||||||
|
@ -112,6 +115,33 @@ rootCommand.Handler = CommandHandler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(fwToRestore))
|
||||||
|
{
|
||||||
|
const string targetFileToRestore = "/tmp/restore.bin";
|
||||||
|
Console.WriteLine("Uploading original file to the target UFiber device...");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
scp.Upload(new FileInfo(fwToRestore), targetFileToRestore);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Failure uploading original image file to the UFiber device. Error: {ex.Message}.");
|
||||||
|
Environment.ExitCode = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Console.WriteLine("Uploaded!");
|
||||||
|
Console.WriteLine("### Applying original file on the target UFiber device...");
|
||||||
|
cmd = ssh.RunCommand($"dd if={targetFileToRestore} of=/dev/mtdblock3 && rm {targetFileToRestore}");
|
||||||
|
if (cmd.ExitStatus != 0)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Failure to apply original image file. Error: {cmd.Error}");
|
||||||
|
Environment.ExitCode = cmd.ExitStatus;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Console.WriteLine("### Applied patch! Please reboot your UFiber device to load the new image.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var ram = new NVRAM(File.ReadAllBytes(Path.Combine(localDumps, imgName)));
|
var ram = new NVRAM(File.ReadAllBytes(Path.Combine(localDumps, imgName)));
|
||||||
Console.WriteLine("### Original Image ###");
|
Console.WriteLine("### Original Image ###");
|
||||||
Console.WriteLine(ram);
|
Console.WriteLine(ram);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user