Skip to content

Commit

Permalink
Fixing non-Windows upgrade process
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmello committed Aug 27, 2024
1 parent 80929f7 commit d3f279d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ public UpgradeService(ILogger logger) : this(
{
}

public async Task TryUpgradeApp()
public async Task<bool> TryUpgradeApp()
{
try
{
if (!ShouldCheckForUpgrade())
return;
return false;

var currentAppVersion = appMetadata.GetAppVersion();

if (currentAppVersion is null)
return;
return false;

var latestRelease = await GetLatestRelease(currentAppVersion);

if (!TryGetDownloadAssetAndVersion(latestRelease, out var downloadUrl, out var latestVersion) || latestVersion <= currentAppVersion)
return;
return false;

var shouldUpdate = CheckIfUserWantsToUpdate(currentAppVersion, latestRelease);

if (!shouldUpdate)
return;
return false;

var (executablePath, appFolder) = appMetadata.GetExecutablePath();

Expand All @@ -66,14 +66,18 @@ public async Task TryUpgradeApp()
UpgradeApp(executablePath, archivePath, newFilePath);

console.MarkupLine("Upgrade complete! The changes will reflect next time you execute the application.\r\n");
console.MarkupLine("If you like this tool, consider giving it a :star: Star on GitHub, it's free and only takes 2 minutes!\r\n" +
console.MarkupLine("If you like this tool, consider giving it a Star:star: on GitHub, it's free and only takes 2 minutes!\r\n" +
"Link: https://github.com/ellosoft/aws-cred-mgr\r\n");

return true;
}
catch (Exception e)
{
_logger.Error(e, "Unable to upgrade app");
console.MarkupLine("[yellow]Unable to upgrade app, try again later or " +
"download the new version from https://github.com/ellosoft/aws-cred-mgr/releases [/]");
"download the new version from https://github.com/ellosoft/aws-cred-mgr/releases [/]");

return false;
}
}

Expand Down Expand Up @@ -128,6 +132,9 @@ private static void UpgradeApp(string executablePath, string archivePath, string
if (File.Exists(archivePath))
File.Delete(archivePath);

if (!OperatingSystem.IsWindows())
File.SetUnixFileMode(newFile, UnixFileMode.UserRead | UnixFileMode.UserExecute);

File.Move(executablePath, archivePath);
File.Move(newFile, executablePath);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Ellosoft.AwsCredentialsManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
var logger = LogRegistration.CreateNewLogger();

var upgradeService = new UpgradeService(logger);
await upgradeService.TryUpgradeApp();
var upgraded = await upgradeService.TryUpgradeApp();

if (upgraded)
return 0;

var services = new ServiceCollection()
.SetupLogging(logger)
Expand Down

0 comments on commit d3f279d

Please sign in to comment.