Skip to content

Commit 84f5085

Browse files
committed
Refactor AppImage update script execution to improve environment variable handling and error messaging
1 parent 4c4a10f commit 84f5085

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

StabilityMatrix.Avalonia/ViewModels/Dialogs/UpdateViewModel.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,9 @@ await updateHelper.DownloadUpdate(
170170
var updateScriptPath = UpdateHelper.UpdateFolder.JoinFile("update_script.sh").FullPath;
171171
var newAppImage = UpdateHelper.ExecutablePath.FullPath;
172172

173-
var scriptContent = $"""
173+
var scriptContent = """
174174
#!/bin/bash
175-
PID={Environment.ProcessId}
176-
NEW_APPIMAGE="{newAppImage.Replace("\"", "\\\"")}"
177-
OLD_APPIMAGE="{appImage.Replace("\"", "\\\"")}"
175+
set -e
178176
179177
# Wait for the process to exit
180178
while kill -0 "$PID" 2>/dev/null; do
@@ -196,15 +194,19 @@ sleep 0.5
196194
UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute
197195
);
198196

199-
System.Diagnostics.Process.Start(
200-
new System.Diagnostics.ProcessStartInfo
201-
{
202-
FileName = "/usr/bin/env",
203-
Arguments = $"bash \"{updateScriptPath}\"",
204-
UseShellExecute = false,
205-
CreateNoWindow = true,
206-
}
207-
);
197+
var startInfo = new System.Diagnostics.ProcessStartInfo
198+
{
199+
FileName = "/usr/bin/env",
200+
Arguments = $"bash \"{updateScriptPath}\"",
201+
UseShellExecute = false,
202+
CreateNoWindow = true,
203+
};
204+
205+
startInfo.EnvironmentVariables["PID"] = Environment.ProcessId.ToString();
206+
startInfo.EnvironmentVariables["NEW_APPIMAGE"] = newAppImage;
207+
startInfo.EnvironmentVariables["OLD_APPIMAGE"] = appImage;
208+
209+
System.Diagnostics.Process.Start(startInfo);
208210

209211
App.Shutdown();
210212
return;
@@ -214,7 +216,7 @@ sleep 0.5
214216
logger.LogError(ex, "Failed to execute AppImage update script");
215217

216218
var dialog = DialogHelper.CreateMarkdownDialog(
217-
"AppImage update script failed. \nCould not replace old AppImage with new version. Please check directory permissions. \nFalling back to standard update process. User intervention required: After program closes, \nplease move the new AppImage extracted in the '.StabilityMatrixUpdate' hidden directory to the old AppImage overwriting it. \n\nClose this dialog to continue with standard update process.",
219+
"AppImage update script failed. \nCould not replace old AppImage with new version. Please check directory permissions. \nFalling back to standard update process. User intervention required: \nAfter program closes, \nplease move the new AppImage extracted in the '.StabilityMatrixUpdate' hidden directory to the old AppImage overwriting it. \n\nClose this dialog to continue with standard update process.",
218220
Resources.Label_UnexpectedErrorOccurred
219221
);
220222

0 commit comments

Comments
 (0)