From 4327b6cf70fd4cd89090584b111c13a710192d8e Mon Sep 17 00:00:00 2001 From: axtloss Date: Sat, 8 Apr 2023 12:03:03 +0200 Subject: [PATCH 1/3] Move user specific configuration into main script --- vanilla_first_setup/defaults/user.py | 4 +- vanilla_first_setup/utils/processor.py | 58 +++++++++++--------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/vanilla_first_setup/defaults/user.py b/vanilla_first_setup/defaults/user.py index ff18e23..8c78b15 100644 --- a/vanilla_first_setup/defaults/user.py +++ b/vanilla_first_setup/defaults/user.py @@ -64,11 +64,11 @@ class VanillaDefaultUser(Adw.Bin): def get_finals(self): return { "vars": { - "create": True + "createUser": True }, "funcs": [ { - "if": "create", + "if": "createUser", "type": "command", "commands": [ f"adduser --quiet --disabled-password --shell /bin/bash --gecos \"{self.fullname}\" {self.username}", diff --git a/vanilla_first_setup/utils/processor.py b/vanilla_first_setup/utils/processor.py index 75ed618..b3b817e 100644 --- a/vanilla_first_setup/utils/processor.py +++ b/vanilla_first_setup/utils/processor.py @@ -31,50 +31,20 @@ class Processor: commands = pre_run + commands + post_run out_run = "" next_boot = [] - next_boot_script_path = os.path.expanduser("~/.local/org.vanillaos.FirstSetup.nextBoot") - next_boot_autostart_path = os.path.expanduser("~/.config/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)) - # nextBoot commands are collected in ~/.local/org.vanillaos.FirstSetup.nextBoot - # and executed at the next boot by a desktop entry + # Collect all the commands that should be run at the next boot for command in commands: if command.startswith("!nextBoot"): next_boot.append(command.replace("!nextBoot", "")) continue - if len(next_boot) > 0: - with open(next_boot_script_path, "w") 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") - - for command in next_boot: - f.write(f"{command}\n") - - f.write(f"rm -f {next_boot_script_path}\n") - f.write(f"rm -f {next_boot_autostart_path}\n") - f.flush() - f.close() - - # setting the file executable - os.chmod(next_boot_script_path, 0o755) - - # creating the desktop entry - with open(next_boot_autostart_path, "w") as f: - 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("Terminal=false\n") - f.write("Type=Application\n") - f.write("X-GNOME-Autostart-enabled=true\n") - f.flush() - f.close() - # 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: @@ -94,6 +64,28 @@ class Processor: f.write("exit 1\n") f.write("fi\n") + # 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("#!/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("EOF\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("Terminal=false\n") + f.write("Type=Application\n") + f.write("X-GNOME-Autostart-enabled=true\n") + f.write("EOF\n") + for command in commands: if command.startswith("!nextBoot"): continue From 8ce173a7cd444c9331e7a13627101d6f40a17bcf Mon Sep 17 00:00:00 2001 From: axtloss Date: Sat, 8 Apr 2023 12:06:46 +0200 Subject: [PATCH 2/3] Remove autostart file creation --- vanilla_first_setup/utils/processor.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/vanilla_first_setup/utils/processor.py b/vanilla_first_setup/utils/processor.py index b3b817e..e5d23f9 100644 --- a/vanilla_first_setup/utils/processor.py +++ b/vanilla_first_setup/utils/processor.py @@ -127,19 +127,7 @@ class Processor: if user is None: user = os.environ.get("USER") - desktop_file = "/home/%s/.local/share/applications/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) - - with open(desktop_file, "w+") as f: - f.write("[Desktop Entry]\n") - f.write("Name=FirstSetup\n") - f.write("Comment=FirstSetup\n") - f.write("Exec=vanilla-first-setup\n") - f.write("Terminal=false\n") - f.write("Type=Application\n") - f.write("NoDisplay=true\n") - f.flush() - f.close() From 6954e05e5db453ba42ac66872771ea363bcd3373 Mon Sep 17 00:00:00 2001 From: axtloss Date: Sat, 8 Apr 2023 14:18:09 +0200 Subject: [PATCH 3/3] Add desktop file to hide first-setup from gnome-shell --- vanilla_first_setup/utils/processor.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vanilla_first_setup/utils/processor.py b/vanilla_first_setup/utils/processor.py index e5d23f9..4a66f3f 100644 --- a/vanilla_first_setup/utils/processor.py +++ b/vanilla_first_setup/utils/processor.py @@ -73,6 +73,15 @@ class Processor: 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") + f.write("[Desktop Entry]\n") + f.write("Name=FirstSetup\n") + f.write("Comment=FirstSetup\n") + f.write("Exec=vanilla-first-setup\n") + f.write("Terminal=false\n") + f.write("Type=Application\n") + f.write("NoDisplay=true\n") + f.write("2EOF\n") f.write("EOF\n") f.write("chmod +x "+next_boot_script_path+"\n")