1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Linux - Added update script

I need this on my linux machine :)
This commit is contained in:
Diogo Trindade 2023-03-26 22:06:01 +01:00
parent e18ef766ca
commit 0c1160eb62
3 changed files with 103 additions and 0 deletions

View File

@ -29,6 +29,7 @@ public class ApplicationStateManager
Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested; Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
Core.Utilities.RestartRequested += UtilitiesOnRestartRequested; Core.Utilities.RestartRequested += UtilitiesOnRestartRequested;
Core.Utilities.UpdateRequested += UtilitiesOnUpdateRequested;
// On OS shutdown dispose the IOC container just so device providers get a chance to clean up // On OS shutdown dispose the IOC container just so device providers get a chance to clean up
if (Application.Current?.ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime) if (Application.Current?.ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime)
@ -138,4 +139,37 @@ public class ApplicationStateManager
//todo //todo
} }
private void UtilitiesOnUpdateRequested(object? sender, UpdateEventArgs e)
{
List<string> argsList = new(StartupArguments);
if (e.Silent && !argsList.Contains("--minimized"))
argsList.Add("--minimized");
// Retain startup arguments after update by providing them to the script
string script = Path.Combine(Constants.UpdatingFolder, "installing", "Scripts", "update.sh");
string source = $"\"{Path.Combine(Constants.UpdatingFolder, "installing")}\"";
string destination = $"\"{Constants.ApplicationFolder}\"";
string args = argsList.Any() ? $"\"'{string.Join(' ', argsList)}'\"" : "";
RunScriptWithOutputFile(script, $"{source} {destination} {args}", Path.Combine(Constants.DataFolder, "update-log.txt"));
// Lets try a graceful shutdown, PowerShell will kill if needed
if (Application.Current?.ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime)
Dispatcher.UIThread.Post(() => controlledApplicationLifetime.Shutdown());
}
private void RunScriptWithOutputFile(string script, string arguments, string outputFile)
{
// Use > for files that are bigger than 200kb to start fresh, otherwise use >> to append
string redirectSymbol = File.Exists(outputFile) && new FileInfo(outputFile).Length > 200000 ? ">" : ">>";
ProcessStartInfo info = new()
{
Arguments = $"\"{script}\" {arguments} {redirectSymbol} \"{outputFile}\"",
FileName = "/bin/bash",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
};
Process.Start(info);
}
} }

View File

@ -29,5 +29,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Icons/**" CopyToOutputDirectory="PreserveNewest" /> <Content Include="Icons/**" CopyToOutputDirectory="PreserveNewest" />
<Content Include="Scripts/**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,68 @@
#!/bin/bash
# This script is used to update Artemis on Linux.
# Arguments:
# $1 = sourceDirectory, the directory where the new files are located
# $2 = destinationDirectory, the directory where the old files are located
# $3 = artemisArgs, the arguments to pass to the Artemis executable
sourceDirectory=$1
destinationDirectory=$2
artemisArgs=$3
echo "sourceDirectory $sourceDirectory"
echo "destinationDirectory $destinationDirectory"
echo "artemisArgs $artemisArgs"
exit 0
# Wait for up to 10 seconds for the Artemis process to exit
i=0
while [ $i -le 10 ]
do
if ! pgrep -x "Artemis.UI.Linux" > /dev/null
then
break
fi
sleep 1
i=$((i+1))
done
# If the Artemis process is still running, kill it
if pgrep -x "Artemis.UI.Linux" > /dev/null
then
pkill -x "Artemis.UI.Linux"
fi
# Check if the destination directory exists
if [ ! -d "$destinationDirectory" ]
then
echo "Destination directory does not exist"
exit 1
fi
# Clear the destination directory but don't remove it
echo "Cleaning up old version where needed"
rm -rf "{$destinationDirectory:?}/"*
# Move the contents of the source directory to the destination directory
echo "Installing new files"
mv "$sourceDirectory"/* "$destinationDirectory"
# Remove the now empty source directory
rmdir "$sourceDirectory"
echo "Finished! Restarting Artemis"
sleep 1
# When finished, start Artemis again
# If the user has specified arguments, pass them to the executable
if [ -z "$artemisArgs" ]
then
"$1/Artemis.UI.Linux" &
else
"$1/Artemis.UI.Linux" "$artemisArgs" &
fi