Skip to content

Commit 22c0aa0

Browse files
committed
Fix updating appimage on Linux via self-created bash script
1 parent 3d76f0e commit 22c0aa0

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

StabilityMatrix.Avalonia/ViewModels/Dialogs/UpdateViewModel.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,51 @@ await updateHelper.DownloadUpdate(
162162
);
163163
}
164164

165+
// Handle Linux AppImage update
166+
if (Compat.IsLinux && Environment.GetEnvironmentVariable("APPIMAGE") is { } appImage)
167+
{
168+
var updateScriptPath = UpdateHelper.UpdateFolder.JoinFile("update_script.sh").FullPath;
169+
var newAppImage = UpdateHelper.ExecutablePath.FullPath;
170+
171+
var scriptContent = $"""
172+
#!/bin/bash
173+
PID={Environment.ProcessId}
174+
NEW_APPIMAGE="{newAppImage.Replace("\"", "\\\"")}"
175+
OLD_APPIMAGE="{appImage.Replace("\"", "\\\"")}"
176+
177+
# Wait for the process to exit
178+
while kill -0 "$PID" 2>/dev/null; do
179+
sleep 0.5
180+
done
181+
182+
# Move the new AppImage over the old one
183+
mv -f "$NEW_APPIMAGE" "$OLD_APPIMAGE"
184+
chmod +x "$OLD_APPIMAGE"
185+
186+
# Launch the new AppImage
187+
"$OLD_APPIMAGE" &
188+
""";
189+
await File.WriteAllTextAsync(updateScriptPath, scriptContent);
190+
191+
File.SetUnixFileMode(
192+
updateScriptPath,
193+
UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute
194+
);
195+
196+
System.Diagnostics.Process.Start(
197+
new System.Diagnostics.ProcessStartInfo
198+
{
199+
FileName = "/bin/bash",
200+
Arguments = updateScriptPath,
201+
UseShellExecute = false,
202+
CreateNoWindow = true,
203+
}
204+
);
205+
206+
App.Shutdown();
207+
return;
208+
}
209+
165210
// Set current version for update messages
166211
settingsManager.Transaction(
167212
s => s.UpdatingFromVersion = Compat.AppVersion,

0 commit comments

Comments
 (0)