From 541dcb84de83b722435648b5ba5606655f9a4448 Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Sat, 26 Aug 2023 08:18:14 +0200 Subject: [PATCH] fix:[close #209] User does not always have permissions for changes tested both on bare metal and vm, first setup does not prompt for the password. Side note: since this update will not be in the ISO immediately, the processor will replace it with the one in upstream. Be sure to replace it again on a tty before logging in again, otherwise it will ask for a password. --- data/org.vanillaos.FirstSetup.policy | 29 ++++++------ data/org.vanillaos.FirstSetup.rules | 8 ++++ recipe.json | 6 +-- vanilla_first_setup/defaults/theme.py | 2 +- vanilla_first_setup/meson.build | 12 ++++- vanilla_first_setup/utils/processor.py | 35 +++++++++------ .../vanilla-first-setup-exec.in | 43 ++++++++++++++++++ vanilla_first_setup/vanilla-first-setup.in | 45 +------------------ 8 files changed, 104 insertions(+), 76 deletions(-) create mode 100644 data/org.vanillaos.FirstSetup.rules create mode 100644 vanilla_first_setup/vanilla-first-setup-exec.in diff --git a/data/org.vanillaos.FirstSetup.policy b/data/org.vanillaos.FirstSetup.policy index c98319c3..9d94c979 100644 --- a/data/org.vanillaos.FirstSetup.policy +++ b/data/org.vanillaos.FirstSetup.policy @@ -1,19 +1,20 @@ + "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> + - vanillaos - https://github.com/vanillaos/first-setup - system-file-manager - - Run First Setup as Administrator - - auth_admin - auth_admin - auth_admin - - /usr/bin/vanilla-first-setup - true - + + + Run Vanilla OS First Setup + Run the Vanilla OS First Setup with privileges + + no + no + auth_admin_keep + + /usr/bin/vanilla-first-setup-exec + TRUE + + \ No newline at end of file diff --git a/data/org.vanillaos.FirstSetup.rules b/data/org.vanillaos.FirstSetup.rules new file mode 100644 index 00000000..6bf2c3f0 --- /dev/null +++ b/data/org.vanillaos.FirstSetup.rules @@ -0,0 +1,8 @@ +polkit.addRule(function(action, subject) { + if (action.id == "org.vanillaos.FirstSetup.exec") + { + polkit.log("action=" + action); + polkit.log("subject=" + subject); + return polkit.Result.YES; + } +}); \ No newline at end of file diff --git a/recipe.json b/recipe.json index 612b217b..1a8652be 100644 --- a/recipe.json +++ b/recipe.json @@ -4,9 +4,9 @@ "distro_logo": "org.vanillaos.FirstSetup-flower", "pre_run": [], "post_run": [ - "pkexec /etc/vanilla-first-setup/first_setup_post", - "pkexec abroot pkg apply", - "!nextBoot pkexec /etc/vanilla-first-setup/first_setup_post_boot" + "/etc/vanilla-first-setup/first_setup_post", + "abroot pkg apply", + "!nextBoot /etc/vanilla-first-setup/first_setup_post_boot" ], "tour": { "get-involved": { diff --git a/vanilla_first_setup/defaults/theme.py b/vanilla_first_setup/defaults/theme.py index f2e79f7c..2f8189c5 100644 --- a/vanilla_first_setup/defaults/theme.py +++ b/vanilla_first_setup/defaults/theme.py @@ -54,7 +54,7 @@ def __set_theme(self, widget, theme: str): self.__theme = theme def get_finals(self): - gs_cmd = "!nextBoot pkexec gsettings set %s %s %s" + gs_cmd = "!nextBoot gsettings set %s %s %s" cmds = [] if self.__theme == "dark": diff --git a/vanilla_first_setup/meson.build b/vanilla_first_setup/meson.build index a1d9c003..09379490 100644 --- a/vanilla_first_setup/meson.build +++ b/vanilla_first_setup/meson.build @@ -18,8 +18,8 @@ conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir'))) conf.set('pkgdatadir', pkgdatadir) configure_file( - input: 'vanilla-first-setup.in', - output: 'vanilla-first-setup', + input: 'vanilla-first-setup-exec.in', + output: 'vanilla-first-setup-exec', install_mode: 'rwxr-xr-x', configuration: conf, install: true, @@ -35,6 +35,14 @@ configure_file( install_dir: get_option('bindir') ) +configure_file( + input: 'vanilla-first-setup.in', + output: 'vanilla-first-setup', + configuration: conf, + install: true, + install_dir: get_option('bindir') +) + subdir('utils') subdir('defaults') subdir('layouts') diff --git a/vanilla_first_setup/utils/processor.py b/vanilla_first_setup/utils/processor.py index 9bc29703..620f2252 100644 --- a/vanilla_first_setup/utils/processor.py +++ b/vanilla_first_setup/utils/processor.py @@ -24,19 +24,21 @@ class Processor: - @staticmethod def get_setup_commands(log_path, pre_run, post_run, commands): commands = pre_run + commands + post_run out_run = "" next_boot = [] - next_boot_script_path = os.path.expanduser("/etc/org.vanillaos.FirstSetup.nextBoot") - next_boot_autostart_path = os.path.expanduser("/etc/xdg/autostart/org.vanillaos.FirstSetup.nextBoot.desktop") + next_boot_script_path = os.path.expanduser( + "/etc/org.vanillaos.FirstSetup.nextBoot" + ) + next_boot_autostart_path = os.path.expanduser( + "/etc/xdg/autostart/org.vanillaos.FirstSetup.nextBoot.desktop" + ) done_file = "/etc/vanilla-first-setup-done" abroot_bin = shutil.which("abroot") - logger.info("processing the following commands: \n%s" % - '\n'.join(commands)) + logger.info("processing the following commands: \n%s" % "\n".join(commands)) # Collect all the commands that should be run at the next boot for command in commands: @@ -46,7 +48,7 @@ def get_setup_commands(log_path, pre_run, post_run, commands): # generating a temporary file to store all the commands so we can # run them all at once - with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: + with tempfile.NamedTemporaryFile(mode="w", delete=False) as f: f.write("#!/bin/sh\n") f.write("# This file was created by FirstSetup\n") f.write("# Do not edit this file manually\n\n") @@ -66,13 +68,15 @@ def get_setup_commands(log_path, pre_run, post_run, commands): # nextBoot commands are collected in /etc/org.vanillaos.FirstSetup.nextBoot # and executed at the next boot by a desktop entry if len(next_boot) > 0: - f.write("cat < "+next_boot_script_path+"\n") + f.write("cat < " + next_boot_script_path + "\n") f.write("#!/bin/sh\n") f.write("# This file was created by FirstSetup\n") f.write("# Do not edit this file manually\n\n") for command in next_boot: f.write(f"{command}\n") - f.write("cat <<2EOF > ~/.local/share/applications/org.vanillaos.FirstSetup.desktop\n") + f.write( + "cat <<2EOF > ~/.local/share/applications/org.vanillaos.FirstSetup.desktop\n" + ) f.write("[Desktop Entry]\n") f.write("Name=FirstSetup\n") f.write("Comment=FirstSetup\n") @@ -83,12 +87,15 @@ def get_setup_commands(log_path, pre_run, post_run, commands): f.write("2EOF\n") f.write("EOF\n") - f.write("chmod +x "+next_boot_script_path+"\n") - f.write("cat < "+next_boot_autostart_path+"\n") + f.write("chmod +x " + next_boot_script_path + "\n") + f.write("cat < " + next_boot_autostart_path + "\n") f.write("[Desktop Entry]\n") f.write("Name=FirstSetup Next Boot\n") f.write("Comment=Run FirstSetup commands at the next boot\n") - f.write("Exec=vanilla-first-setup --run-post-script 'sh %s'\n" % next_boot_script_path) + f.write( + "Exec=vanilla-first-setup --run-post-script 'sh %s'\n" + % next_boot_script_path + ) f.write("Terminal=false\n") f.write("Type=Application\n") f.write("X-GNOME-Autostart-enabled=true\n") @@ -128,7 +135,7 @@ def get_setup_commands(log_path, pre_run, post_run, commands): # setting the file executable os.chmod(f.name, 0o755) - cmd = ["pkexec", "sh", f.name] + cmd = ["sh", f.name] return cmd @staticmethod @@ -136,7 +143,9 @@ def hide_first_setup(user: str = None): if user is None: user = os.environ.get("USER") - autostart_file = "/home/%s/.config/autostart/org.vanillaos.FirstSetup.desktop" % user + autostart_file = ( + "/home/%s/.config/autostart/org.vanillaos.FirstSetup.desktop" % user + ) if os.path.exists(autostart_file): os.remove(autostart_file) diff --git a/vanilla_first_setup/vanilla-first-setup-exec.in b/vanilla_first_setup/vanilla-first-setup-exec.in new file mode 100644 index 00000000..09902a95 --- /dev/null +++ b/vanilla_first_setup/vanilla-first-setup-exec.in @@ -0,0 +1,43 @@ +#!@PYTHON@ + +# vanilla-first-setup.in +# +# Copyright 2022 mirkobrombin +# +# 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 Foundationat 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 . + +import os +import sys +import signal +import locale +import gettext + +VERSION = '@VERSION@' +pkgdatadir = '@pkgdatadir@' +localedir = '@localedir@' + +sys.path.insert(1, pkgdatadir) +signal.signal(signal.SIGINT, signal.SIG_DFL) +locale.bindtextdomain('vanilla_first_setup', localedir) +locale.textdomain('vanilla_first_setup') +gettext.install('vanilla_first_setup', localedir) + +if __name__ == '__main__': + import gi + + from gi.repository import Gio + resource = Gio.Resource.load(os.path.join(pkgdatadir, 'vanilla-first-setup.gresource')) + resource._register() + + from vanilla_first_setup import main + sys.exit(main.main(VERSION)) \ No newline at end of file diff --git a/vanilla_first_setup/vanilla-first-setup.in b/vanilla_first_setup/vanilla-first-setup.in index 09902a95..3b7520af 100644 --- a/vanilla_first_setup/vanilla-first-setup.in +++ b/vanilla_first_setup/vanilla-first-setup.in @@ -1,43 +1,2 @@ -#!@PYTHON@ - -# vanilla-first-setup.in -# -# Copyright 2022 mirkobrombin -# -# 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 Foundationat 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 . - -import os -import sys -import signal -import locale -import gettext - -VERSION = '@VERSION@' -pkgdatadir = '@pkgdatadir@' -localedir = '@localedir@' - -sys.path.insert(1, pkgdatadir) -signal.signal(signal.SIGINT, signal.SIG_DFL) -locale.bindtextdomain('vanilla_first_setup', localedir) -locale.textdomain('vanilla_first_setup') -gettext.install('vanilla_first_setup', localedir) - -if __name__ == '__main__': - import gi - - from gi.repository import Gio - resource = Gio.Resource.load(os.path.join(pkgdatadir, 'vanilla-first-setup.gresource')) - resource._register() - - from vanilla_first_setup import main - sys.exit(main.main(VERSION)) \ No newline at end of file +#!/bin/sh +pkexec vanilla-first-setup-exec "$@" \ No newline at end of file