Add auto update to linux and macos
This commit is contained in:
parent
952eee6d32
commit
dc7c03661d
26 changed files with 631 additions and 99 deletions
8
Source/LoadByOS/LinuxConfigApp/Libation.desktop
Normal file
8
Source/LoadByOS/LinuxConfigApp/Libation.desktop
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[Desktop Entry]
|
||||
Name=Libation
|
||||
Exec=libation
|
||||
Icon=libation
|
||||
Comment=Liberate your Audiobooks
|
||||
Terminal=false
|
||||
Type=Application
|
||||
MimeType=x-content/unix-software;
|
||||
|
|
@ -34,4 +34,28 @@
|
|||
<ProjectReference Include="..\..\AppScaffolding\AppScaffolding.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="glass-with-glow_256.svg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Libation.desktop">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,14 +1,73 @@
|
|||
using LibationFileManager;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace LinuxConfigApp
|
||||
{
|
||||
internal class LinuxInterop : IInteropFunctions
|
||||
{
|
||||
public LinuxInterop() { }
|
||||
//Different terminal apps possibly installed on a linux system
|
||||
// [0] console executable
|
||||
// [1] argument to set the concole's title
|
||||
// [2] argument to pass a command to be executed to the terminal
|
||||
static readonly string[][] consoleCommands =
|
||||
{
|
||||
new[] {"konsole", "--title", "-e"},
|
||||
new[] {"gnome-terminal", "--title", "--"},
|
||||
new[] {"mate-terminal", "--title", "-x"},
|
||||
new[] {"xterm", "-T", "-e"},
|
||||
};
|
||||
|
||||
public LinuxInterop() { }
|
||||
public LinuxInterop(params object[] values) { }
|
||||
|
||||
public void SetFolderIcon(string image, string directory) => throw new PlatformNotSupportedException();
|
||||
public void DeleteFolderIcon(string directory) => throw new PlatformNotSupportedException();
|
||||
public void CopyTextToClipboard(string text) => throw new PlatformNotSupportedException();
|
||||
}
|
||||
|
||||
//only run the audo updater is the current app was installed from the
|
||||
//.deb package. Try to detect this by checking if the symlink exists.
|
||||
public bool CanUpdate => Directory.Exists("/usr/bin/libation");
|
||||
public void InstallUpdate(string updateBundle)
|
||||
{
|
||||
RunAsRoot("apt", $"install '{updateBundle}'");
|
||||
}
|
||||
|
||||
public Process RunAsRoot(string exe, string args)
|
||||
{
|
||||
//cribbed this script from VirtualBox's guest additions installer.
|
||||
//It's designed to launch the system's gui superuser password
|
||||
//prompt across multiple distributions and desktop environments.
|
||||
const string runasroot = "/tmp/runasroot.sh";
|
||||
File.WriteAllBytes(runasroot, Properties.Resources.runasroot);
|
||||
|
||||
string command = $"{exe ?? ""} {args ?? ""}".Trim();
|
||||
|
||||
foreach (var console in consoleCommands)
|
||||
{
|
||||
ProcessStartInfo psi = new()
|
||||
{
|
||||
FileName = console[0],
|
||||
UseShellExecute = false,
|
||||
ArgumentList =
|
||||
{
|
||||
console[1],
|
||||
$"Running '{exe}' as root",
|
||||
console[2],
|
||||
"/bin/sh",
|
||||
runasroot,
|
||||
"Installing libation.deb",
|
||||
command,
|
||||
$"Please run '{command}' manually"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
return Process.Start(psi);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
73
Source/LoadByOS/LinuxConfigApp/Properties/Resources.Designer.cs
generated
Normal file
73
Source/LoadByOS/LinuxConfigApp/Properties/Resources.Designer.cs
generated
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace LinuxConfigApp.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LinuxConfigApp.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] runasroot {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("runasroot", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
124
Source/LoadByOS/LinuxConfigApp/Properties/Resources.resx
Normal file
124
Source/LoadByOS/LinuxConfigApp/Properties/Resources.resx
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="runasroot" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\runasroot.sh;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
||||
188
Source/LoadByOS/LinuxConfigApp/Resources/runasroot.sh
Normal file
188
Source/LoadByOS/LinuxConfigApp/Resources/runasroot.sh
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
#!/bin/sh
|
||||
# $Id: runasroot.sh 153224 2022-08-22 17:43:14Z klaus $
|
||||
## @file
|
||||
# VirtualBox privileged execution helper script for Linux and Solaris
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright (C) 2009-2022 Oracle and/or its affiliates.
|
||||
#
|
||||
# This file is part of VirtualBox base platform packages, as
|
||||
# available from https://www.virtualbox.org.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation, in version 3 of the
|
||||
# License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <https://www.gnu.org/licenses>.
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
|
||||
# Deal with differing "which" semantics
|
||||
mywhich() {
|
||||
which "$1" 2>/dev/null | grep -v "no $1"
|
||||
}
|
||||
|
||||
# Get the name and execute switch for a useful terminal emulator
|
||||
#
|
||||
# Sets $gxtpath to the emulator path or empty
|
||||
# Sets $gxttitle to the "title" switch for that emulator
|
||||
# Sets $gxtexec to the "execute" switch for that emulator
|
||||
# May clobber $gtx*
|
||||
# Calls mywhich
|
||||
getxterm() {
|
||||
# gnome-terminal uses -e differently to other emulators
|
||||
for gxti in "konsole --title -e" "gnome-terminal --title -x" "xterm -T -e"; do
|
||||
set $gxti
|
||||
gxtpath="`mywhich $1`"
|
||||
case "$gxtpath" in ?*)
|
||||
gxttitle=$2
|
||||
gxtexec=$3
|
||||
return
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Quotes its argument by inserting '\' in front of every character save
|
||||
# for 'A-Za-z0-9/'. Prints the result to stdout.
|
||||
quotify() {
|
||||
echo "$1" | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
|
||||
}
|
||||
|
||||
ostype=`uname -s`
|
||||
if test "$ostype" != "Linux" && test "$ostype" != "SunOS" ; then
|
||||
echo "Linux/Solaris not detected."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HAS_TERMINAL=""
|
||||
case "$1" in "--has-terminal")
|
||||
shift
|
||||
HAS_TERMINAL="yes"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$#" in "2"|"3")
|
||||
;;
|
||||
*)
|
||||
echo "Usage: `basename $0` DESCRIPTION COMMAND [ADVICE]" >&2
|
||||
echo >&2
|
||||
echo "Attempt to execute COMMAND with root privileges, displaying DESCRIPTION if" >&2
|
||||
echo "possible and displaying ADVICE if possible if no su(1)-like tool is available." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
DESCRIPTION=$1
|
||||
COMMAND=$2
|
||||
ADVICE=$3
|
||||
PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/X11/bin
|
||||
|
||||
case "$ostype" in SunOS)
|
||||
PATH=$PATH:/usr/sfw/bin:/usr/gnu/bin:/usr/xpg4/bin:/usr/xpg6/bin:/usr/openwin/bin:/usr/ucb
|
||||
GKSU_SWITCHES="-au root"
|
||||
;;
|
||||
*)
|
||||
GKSU_SWITCHES=""
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$HAS_TERMINAL" in "")
|
||||
case "$DISPLAY" in ?*)
|
||||
KDESUDO="`mywhich kdesudo`"
|
||||
case "$KDESUDO" in ?*)
|
||||
eval "`quotify "$KDESUDO"` --comment `quotify "$DESCRIPTION"` -- $COMMAND"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
|
||||
KDESU="`mywhich kdesu`"
|
||||
case "$KDESU" in ?*)
|
||||
"$KDESU" -c "$COMMAND"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
|
||||
GKSU="`mywhich gksu`"
|
||||
case "$GKSU" in ?*)
|
||||
# Older gksu does not grok --description nor '--' and multiple args.
|
||||
# @todo which versions do?
|
||||
# "$GKSU" --description "$DESCRIPTION" -- "$@"
|
||||
# Note that $GKSU_SWITCHES is NOT quoted in the following
|
||||
"$GKSU" $GKSU_SWITCHES "$COMMAND"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac # $DISPLAY
|
||||
;;
|
||||
esac # ! $HAS_TERMINAL
|
||||
|
||||
# pkexec may work for ssh console sessions as well if the right agents
|
||||
# are installed. However it is very generic and does not allow for any
|
||||
# custom messages. Thus it comes after gksu.
|
||||
## @todo should we insist on either a display or a terminal?
|
||||
# case "$DISPLAY$HAS_TERMINAL" in ?*)
|
||||
PKEXEC="`mywhich pkexec`"
|
||||
case "$PKEXEC" in ?*)
|
||||
eval "\"$PKEXEC\" $COMMAND"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
# ;;S
|
||||
#esac
|
||||
|
||||
case "$HAS_TERMINAL" in ?*)
|
||||
USE_SUDO=
|
||||
grep -q Ubuntu /etc/lsb-release 2>/dev/null && USE_SUDO=true
|
||||
# On Ubuntu we need sudo instead of su. Assume this works, and is only
|
||||
# needed for Ubuntu until proven wrong.
|
||||
case $USE_SUDO in true)
|
||||
SUDO_COMMAND="`quotify "$SUDO"` -- $COMMAND"
|
||||
eval "$SUDO_COMMAND"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
|
||||
SU="`mywhich su`"
|
||||
case "$SU" in ?*)
|
||||
"$SU" - root -c "$COMMAND"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
# The ultimate fallback is running 'su -' within an xterm. We use the
|
||||
# title of the xterm to tell what is going on.
|
||||
case "$DISPLAY" in ?*)
|
||||
SU="`mywhich su`"
|
||||
case "$SU" in ?*)
|
||||
getxterm
|
||||
case "$gxtpath" in ?*)
|
||||
"$gxtpath" "$gxttitle" "$DESCRIPTION - su" "$gxtexec" su - root -c "$COMMAND"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
esac # $DISPLAY
|
||||
|
||||
# Failure...
|
||||
case "$DISPLAY" in ?*)
|
||||
echo "Unable to locate 'pkexec', 'gksu' or 'su+xterm'. $ADVICE" >&2
|
||||
;;
|
||||
*)
|
||||
echo "Unable to locate 'pkexec'. $ADVICE" >&2
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 1
|
||||
22
Source/LoadByOS/LinuxConfigApp/glass-with-glow_256.svg
Normal file
22
Source/LoadByOS/LinuxConfigApp/glass-with-glow_256.svg
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="256.000000pt" height="256.000000pt" viewBox="0 0 256.000000 256.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
|
||||
<g transform="translate(0.000000,256.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M681 2513 c-57 -66 -116 -190 -148 -309 -25 -92 -27 -113 -27 -314
|
||||
-1 -237 10 -307 74 -468 94 -233 283 -387 542 -440 l78 -17 0 -402 0 -403
|
||||
-215 0 c-216 0 -216 0 -240 -25 -33 -32 -33 -78 0 -110 l24 -25 511 0 511 0
|
||||
24 25 c16 15 25 36 25 55 0 19 -9 40 -25 55 -24 25 -24 25 -240 25 l-215 0 0
|
||||
403 0 402 78 17 c259 53 448 207 542 440 64 161 75 231 74 468 0 201 -2 222
|
||||
-27 314 -32 119 -91 243 -148 309 l-41 47 -558 0 -558 0 -41 -47z m1115 -159
|
||||
c84 -143 124 -364 104 -575 -21 -226 -85 -385 -196 -489 -115 -107 -255 -160
|
||||
-424 -160 -237 0 -435 114 -529 303 -136 274 -127 696 20 934 l21 33 488 0
|
||||
489 0 27 -46z"/>
|
||||
<path d="M735 1828 c28 -375 165 -559 452 -606 83 -14 103 -14 186 0 289 47
|
||||
422 228 452 611 l7 87 -552 0 -552 0 7 -92z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
31
Source/LoadByOS/MacOSConfigApp/Info.plist
Normal file
31
Source/LoadByOS/MacOSConfigApp/Info.plist
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>Libation</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Libation</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.libation.macos</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<true/>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>libation.icns</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>VERSION_STRING</string>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<false/>
|
||||
<key>com.apple.security.cs.allow-jit</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.disable-library-validation</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.disable-executable-page-protection</key>
|
||||
<true/>
|
||||
<key>com.apple.security.automation.apple-events</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -34,4 +34,13 @@
|
|||
<ProjectReference Include="..\..\AppScaffolding\AppScaffolding.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Info.plist">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="libation.icns">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,14 +1,78 @@
|
|||
using LibationFileManager;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace MacOSConfigApp
|
||||
{
|
||||
internal class MacOSInterop : IInteropFunctions
|
||||
{
|
||||
public MacOSInterop() { }
|
||||
{
|
||||
private const string AppPath = "/Applications/Libation.app";
|
||||
public MacOSInterop() { }
|
||||
public MacOSInterop(params object[] values) { }
|
||||
|
||||
public void SetFolderIcon(string image, string directory) => throw new PlatformNotSupportedException();
|
||||
public void SetFolderIcon(string image, string directory) => throw new PlatformNotSupportedException();
|
||||
public void DeleteFolderIcon(string directory) => throw new PlatformNotSupportedException();
|
||||
public void CopyTextToClipboard(string text) => throw new PlatformNotSupportedException();
|
||||
}
|
||||
|
||||
//I haven't figured out how to find the app bundle's directory from within
|
||||
//the running process, so don't update unless it's "installed" in /Applications
|
||||
public bool CanUpdate => Directory.Exists(AppPath);
|
||||
|
||||
public void InstallUpdate(string updateBundle)
|
||||
{
|
||||
Serilog.Log.Information($"Extracting update bundle to {AppPath}");
|
||||
|
||||
//tar wil overwrite existing without elevated privileges
|
||||
Process.Start("tar", $"-xzf \"{updateBundle}\" -C \"/Applications\"").WaitForExit();
|
||||
|
||||
//For now, it seems like this step is unnecessary. We can overwrite and
|
||||
//run Libation without needing to re-add the exception. This is insurance.
|
||||
RunAsRoot(null, $"""
|
||||
sudo spctl --master-disable
|
||||
sudo spctl --add --label 'Libation' {AppPath}
|
||||
open {AppPath}
|
||||
sudo spctl --master-enable
|
||||
""");
|
||||
}
|
||||
|
||||
//Using osascript -e '[script]' works from the terminal, but I haven't figured
|
||||
//out the syntax for it to work from create_process, so write to stdin instead.
|
||||
public Process RunAsRoot(string _, string command)
|
||||
{
|
||||
const string osascript = "osascript";
|
||||
var fullCommand = $"do shell script \"{command}\" with administrator privileges";
|
||||
|
||||
var psi = new ProcessStartInfo()
|
||||
{
|
||||
FileName = osascript,
|
||||
UseShellExecute = false,
|
||||
Arguments = "-",
|
||||
RedirectStandardError= true,
|
||||
RedirectStandardOutput= true,
|
||||
RedirectStandardInput= true,
|
||||
};
|
||||
|
||||
Serilog.Log.Logger.Information($"running {osascript} as root: {{script}}", fullCommand);
|
||||
|
||||
var proc = Process.Start(psi);
|
||||
proc.ErrorDataReceived += Proc_ErrorDataReceived;
|
||||
proc.OutputDataReceived += Proc_OutputDataReceived;
|
||||
proc.BeginErrorReadLine();
|
||||
proc.BeginOutputReadLine();
|
||||
proc.StandardInput.WriteLine(fullCommand);
|
||||
proc.StandardInput.Close();
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
private void Proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (e.Data != null)
|
||||
Serilog.Log.Logger.Information("stderr: {data}", e.Data);
|
||||
}
|
||||
|
||||
private void Proc_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (e.Data!= null)
|
||||
Serilog.Log.Logger.Information("stderr: {data}", e.Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
Source/LoadByOS/MacOSConfigApp/libation.icns
Normal file
BIN
Source/LoadByOS/MacOSConfigApp/libation.icns
Normal file
Binary file not shown.
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -35,8 +36,31 @@ namespace WindowsConfigApp
|
|||
|
||||
public void DeleteFolderIcon(string directory)
|
||||
=> new DirectoryInfo(directory)?.DeleteIcon();
|
||||
public bool CanUpdate => true;
|
||||
public void InstallUpdate(string updateBundle)
|
||||
{
|
||||
var thisExe = Environment.ProcessPath;
|
||||
var thisDir = Path.GetDirectoryName(thisExe);
|
||||
var zipExtractor = Path.Combine(Path.GetTempPath(), "ZipExtractor.exe");
|
||||
|
||||
public void CopyTextToClipboard(string text)
|
||||
=> Clipboard.SetText(text);
|
||||
File.Copy("ZipExtractor.exe", zipExtractor, overwrite: true);
|
||||
|
||||
RunAsRoot(zipExtractor, $"--input \"{updateBundle}\" --output \"{thisDir}\" --executable \"{thisExe}\"");
|
||||
}
|
||||
|
||||
public Process RunAsRoot(string exe, string args)
|
||||
{
|
||||
var psi = new ProcessStartInfo()
|
||||
{
|
||||
FileName = exe,
|
||||
UseShellExecute = true,
|
||||
Verb = "runas",
|
||||
WindowStyle = ProcessWindowStyle.Normal,
|
||||
CreateNoWindow = true,
|
||||
Arguments = args
|
||||
};
|
||||
|
||||
return Process.Start(psi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,4 +40,10 @@
|
|||
<ProjectReference Include="..\..\AppScaffolding\AppScaffolding.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="ZipExtractor.exe">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
BIN
Source/LoadByOS/WindowsConfigApp/ZipExtractor.exe
Normal file
BIN
Source/LoadByOS/WindowsConfigApp/ZipExtractor.exe
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue