Skip to content

Commit

Permalink
Merge pull request #6 from Unifi-Tools/allow-restore
Browse files Browse the repository at this point in the history
Allow previous versions of the firmware.
  • Loading branch information
galvesribeiro authored Jun 1, 2021
2 parents 640627f + 7914288 commit ac22b36
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/UFiber.Configurator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
new Option<string>(
"--mac",
"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)
Expand All @@ -55,8 +58,8 @@ ScpClient GetSCPClient(string userName, string password, string host, int port =
}

rootCommand.Handler = CommandHandler
.Create<string, string, string, int, bool, string, string, string, string>(
(host, user, pw, port, dryRun, slid, vendor, serial, mac) =>
.Create<string, string, string, int, bool, string, string, string, string, string>(
(host, user, pw, port, dryRun, slid, vendor, serial, mac, fwToRestore) =>
{
if (string.IsNullOrWhiteSpace(host))
{
Expand Down Expand Up @@ -112,6 +115,33 @@ ScpClient GetSCPClient(string userName, string password, string host, int port =
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)));
Console.WriteLine("### Original Image ###");
Console.WriteLine(ram);
Expand Down

0 comments on commit ac22b36

Please sign in to comment.