示例#1
0
#pragma warning restore 1998

        public async Task Uninstall(IProgress <Tuple <int, string> > progress = null, bool dryRun = true)
        {
            // First, remove the desktop entry and "sqrl://" scheme handlers
            progress.Report(new Tuple <int, string>(0, $"Removing desktop entries and sqrl:// scheme handlers"));
            var desktopFile = Path.Combine(PathConf.ClientInstallPath, "sqrldev-sqrl.desktop");

            _shell.Term($"xdg-mime uninstall {desktopFile}", Output.Internal);
            _shell.Term($"xdg-desktop-menu uninstall sqrldev-sqrl.desktop", Output.Internal);
            _shell.Term($"update-desktop-database {SystemAndShellUtils.GetHomePath()}/.local/share/applications/", Output.Internal);

            // Run the inventory-based uninstaller
            await Uninstaller.Run(progress, dryRun);
        }
示例#2
0
        public override void Initialize()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ||
                RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                if (!SystemAndShellUtils.IsAdmin())
                {
                    bool nogo = true;

                    // If platform is Linux we can throw a hail mary and try to elevate the program by using the
                    // polkit protocol via pkexe, see: https://www.freedesktop.org/software/polkit/docs/0.105/pkexec.1.html
                    // In short, the pkexec application allows you to request authorization and impersonation rights
                    // for an application. In order for this to work, you need to have an application specific policy
                    // installed in the application (see Platform/Linux/Installer).

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        Log.Information("Launched on Linux without sudo, trying to re-launch using PolicyKit");
                        nogo = !SystemAndShellUtils.LaunchInstallerUsingPolKit(copyCurrentProcessExecutable: true);
                    }

                    if (nogo)
                    {
                        rootBail = true;
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }

            Log.Information($"Current executable path: {Process.GetCurrentProcess().MainModule.FileName}");
            AvaloniaXamlLoader.Load(this);

            // This is here only to be able to manually load a specific translation
            // during development by setting CurrentLocalization it to something
            // like "en-US" or "de-DE";
            LocalizationExtension loc = new LocalizationExtension();

            LocalizationExtension.CurrentLocalization = LocalizationExtension.DEFAULT_LOC;
        }
        /// <summary>
        /// Launches the freshly installed SQRL client app.
        /// </summary>
        private void LaunchSQRL()
        {
            Log.Information($"Launching client from installer");

            // On Linux, the installer is run as root, so we need to "downgrade"
            // the client launch to the "real" user account.
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                ShellConfigurator shell = new ShellConfigurator(BridgeSystem.Bash);
                string            user  = shell.Term("logname", Output.Hidden).stdout.Trim();
                SystemAndShellUtils.LaunchClientAsUser(_clientExePath, user);
                return;
            }

            var process = new Process();

            process.StartInfo.FileName         = _clientExePath;
            process.StartInfo.WorkingDirectory = Path.GetDirectoryName(_clientExePath);
            process.StartInfo.UseShellExecute  = true;
            process.Start();
        }
示例#4
0
#pragma warning disable 1998
        public async Task Install(string archiveFilePath, string installPath, string versionTag)
        {
            // The "async" in the delegate is needed, otherwise exceptions within
            // the delegate won't "bubble up" to the exception handlers upstream.
            await Task.Run(async() =>
            {
                Inventory.Instance.Load();
                Log.Information($"Installing on Linux to {installPath}");

                // Extract main installation archive
                Log.Information($"Extracting main installation archive");
                CommonUtils.ExtractZipFile(archiveFilePath, string.Empty, installPath);

                // Check if a database exists in the installation directory
                // (which is bad) and if it does, move it to user space.
                if (File.Exists(Path.Combine(installPath, PathConf.DBNAME)))
                {
                    Utils.MoveDb(Path.Combine(installPath, PathConf.DBNAME));
                }

                Inventory.Instance.AddDirectory(installPath);

                // Create icon, register sqrl:// scheme etc.
                Log.Information("Creating Linux desktop icon, application and registering SQRL invokation scheme");
                GithubHelper.DownloadFile(@"https://github.com/sqrldev/SQRLDotNetClient/raw/master/SQRLDotNetClientUI/Assets/SQRL_icon_normal_64.png",
                                          Path.Combine(installPath, "SQRL.png"));

                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"[Desktop Entry]");
                sb.AppendLine("Name=SQRL");
                sb.AppendLine("Type=Application");
                sb.AppendLine($"Icon={(Path.Combine(installPath, "SQRL.png"))}");
                sb.AppendLine($"Exec={GetClientExePath(installPath)} %u");
                sb.AppendLine("Categories=Internet");
                sb.AppendLine("Terminal=false");
                sb.AppendLine("MimeType=x-scheme-handler/sqrl");
                File.WriteAllText(Path.Combine(installPath, "sqrldev-sqrl.desktop"), sb.ToString());


                SystemAndShellUtils.Chmod(installPath, Recursive: true);

                SystemAndShellUtils.SetExecutableBit(GetClientExePath(installPath));
                SystemAndShellUtils.SetExecutableBit(Path.Combine(installPath, "sqrldev-sqrl.desktop"));
                SystemAndShellUtils.SetExecutableBit(Path.Combine(installPath, Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName)));
                _shell.Term($"xdg-desktop-menu install {Path.Combine(installPath, "sqrldev-sqrl.desktop")}", Output.Internal);
                _shell.Term($"gio mime x-scheme-handler/sqrl sqrldev-sqrl.desktop", Output.Internal);
                _shell.Term($"xdg-mime default sqrldev-sqrl.desktop x-scheme-handler/sqrl", Output.Internal);

                _shell.Term($"update-desktop-database {SystemAndShellUtils.GetHomePath()}/.local/share/applications/", Output.Internal);



                // Change owner of database dir/file to the actual user behind the "sudo"
                var user           = SystemAndShellUtils.GetCurrentUser();
                string chownDbFile = $"chown -R {user}:{user} {PathConf.ClientDBPath}";
                Log.Information($"Determined username for chown: \"{user}\"");
                Log.Information($"Running command: {chownDbFile}");
                _shell.Term(chownDbFile, Output.Internal);

                Log.Information("All is good up to this point, lets setup Linux for UAC (if we can)");


                // Creates the required file and system changes for SQRL to be available
                // ubiquitous throughout the system via a new environment variable SQRL_HOME
                // and the addition of this variable to the system PATH.
                // Note that the latter won't take effect until the user logs out or reboots.

                if (SystemAndShellUtils.IsPolKitAvailable())
                {
                    Log.Information("Creating SQRL_HOME environment variable and adding SQRL_HOME to PATH");
                    string sqrlvarsFile = "/etc/profile.d/sqrl-vars.sh";
                    using (StreamWriter sw = new StreamWriter(sqrlvarsFile))
                    {
                        sw.WriteLine($"export SQRL_HOME={installPath}");
                        sw.WriteLine("export PATH=$PATH:$SQRL_HOME");
                        sw.Close();
                    }
                    Inventory.Instance.AddFile(sqrlvarsFile);
                    Log.Information("Creating polkit rule for SQRL");
                    var assets = AvaloniaLocator.Current.GetService <IAssetLoader>();
                    string sqrlPolkitPolicyFile = Path.Combine("/usr/share/polkit-1/actions",
                                                               "org.freedesktop.policykit.SQRLPlatformAwareInstaller_linux.policy");
                    using (StreamWriter sw = new StreamWriter(sqrlPolkitPolicyFile))
                    {
                        string policyFile = "";
                        using (var stream = new StreamReader(assets.Open(new Uri("resm:SQRLPlatformAwareInstaller.Assets.SQRLPlatformAwareInstaller_linux.policy"))))
                        {
                            policyFile = stream.ReadToEnd();
                        }
                        policyFile = policyFile.Replace("INSTALLER_PATH", "/tmp/SQRLPlatformAwareInstaller_linux");
                        sw.Write(policyFile);
                        sw.Close();
                    }
                    _shell.Term("export SQRL_HOME={installPath}", Output.Internal);
                    _shell.Term("export PATH=$PATH:$SQRL_HOME", Output.Internal);
                    Inventory.Instance.AddFile(sqrlPolkitPolicyFile);
                }
                else
                {
                    Log.Warning("pkexec was not found, we can't automatically elevate permissions UAC style, user will have to do manually");
                }

                Inventory.Instance.Save();
            });
        }