Skip to content

Commit

Permalink
fix:[close #209] User does not always have permissions for changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mirkobrombin committed Aug 26, 2023
1 parent 66614a8 commit 541dcb8
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 76 deletions.
29 changes: 15 additions & 14 deletions data/org.vanillaos.FirstSetup.policy
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">

<policyconfig>
<vendor>vanillaos</vendor>
<vendor_url>https://github.com/vanillaos/first-setup</vendor_url>
<icon_name>system-file-manager</icon_name>
<action id="org.freedesktop.policykit.pkexec.org.vanillaos.FirstSetup">
<description>Run First Setup as Administrator</description>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/vanilla-first-setup</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>

<action id="org.vanillaos.FirstSetup.exec">
<description>Run Vanilla OS First Setup</description>
<message>Run the Vanilla OS First Setup with privileges</message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/vanilla-first-setup-exec</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
</action>

</policyconfig>
8 changes: 8 additions & 0 deletions data/org.vanillaos.FirstSetup.rules
Original file line number Diff line number Diff line change
@@ -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;
}
});
6 changes: 3 additions & 3 deletions recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion vanilla_first_setup/defaults/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
12 changes: 10 additions & 2 deletions vanilla_first_setup/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')
Expand Down
35 changes: 22 additions & 13 deletions vanilla_first_setup/utils/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand All @@ -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 <<EOF > "+next_boot_script_path+"\n")
f.write("cat <<EOF > " + 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")
Expand All @@ -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 <<EOF > "+next_boot_autostart_path+"\n")
f.write("chmod +x " + next_boot_script_path + "\n")
f.write("cat <<EOF > " + 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")
Expand Down Expand Up @@ -128,15 +135,17 @@ 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
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)
43 changes: 43 additions & 0 deletions vanilla_first_setup/vanilla-first-setup-exec.in
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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))
45 changes: 2 additions & 43 deletions vanilla_first_setup/vanilla-first-setup.in
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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))
#!/bin/sh
pkexec vanilla-first-setup-exec "$@"

0 comments on commit 541dcb8

Please sign in to comment.