From 2d0ed6f01e29933ec88dcd5091b43419dba67662 Mon Sep 17 00:00:00 2001 From: Muhammad Salman Date: Sat, 14 Oct 2023 23:41:19 +0500 Subject: [PATCH 1/8] fix:[#213] Rerun setup commands until all packages have been installed --- recipe.json | 115 ++++++++++++++++------- vanilla_first_setup/defaults/hostname.py | 1 + vanilla_first_setup/defaults/theme.py | 2 +- vanilla_first_setup/defaults/user.py | 1 + vanilla_first_setup/utils/parser.py | 5 +- vanilla_first_setup/utils/processor.py | 12 ++- vanilla_first_setup/window.py | 3 +- 7 files changed, 99 insertions(+), 40 deletions(-) diff --git a/recipe.json b/recipe.json index f0b377af..3298dd9c 100644 --- a/recipe.json +++ b/recipe.json @@ -92,6 +92,10 @@ "commands": [ "abroot pkg add flatpak gnome-software-plugin-flatpak", "!nextBoot !noRoot flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo" + ], + "tests": [ + "flatpak", + "gnome-software-plugin-flatpak" ] }, { @@ -99,6 +103,9 @@ "type": "command", "commands": [ "abroot pkg add fuse3 libfuse3-3" + ], + "tests": [ + "fuse3" ] } ] @@ -303,167 +310,200 @@ { "if" : "Calculator", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Calculator"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Calculator"], + "tests": [] }, { "if" : "Calendar", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Calendar"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Calendar"], + "tests": [] }, { "if" : "Characters", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Characters"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Characters"], + "tests": [] }, { "if" : "Clocks", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.clocks"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.clocks"], + "tests": [] }, { "if" : "Connections", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Connections"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Connections"], + "tests": [] }, { "if" : "Contacts", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Contacts"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Contacts"], + "tests": [] }, { "if" : "Disk Usage Analyzer", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.baobab"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.baobab"], + "tests": [] }, { "if": "Document Scanner", "type": "command", - "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.SimpleScan"] + "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.SimpleScan"], + "tests": [] }, { "if" : "Document Viewer", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Evince"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Evince"], + "tests": [] }, { "if": "Extension Manager", "type": "command", - "commands": ["!nextBoot !noRoot flatpak install -y com.mattjakeman.ExtensionManager"] + "commands": ["!nextBoot !noRoot flatpak install -y com.mattjakeman.ExtensionManager"], + "tests": [] }, { "if" : "File Roller", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.FileRoller"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.FileRoller"], + "tests": [] }, { "if" : "Fonts", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.font-viewer"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.font-viewer"], + "tests": [] }, { "if" : "Image Viewer", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Loupe"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Loupe"], + "tests": [] }, { "if" : "Logs", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Logs"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Logs"], + "tests": [] }, { "if" : "Maps", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Maps"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Maps"], + "tests": [] }, { "if" : "Music", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Music"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Music"], + "tests": [] }, { "if": "Photos", "type": "command", - "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.Photos"] + "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.Photos"], + "tests": [] }, { "if" : "Snapshot", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Snapshot"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Snapshot"], + "tests": [] }, { "if" : "Text Editor", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.TextEditor"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.TextEditor"], + "tests": [] }, { "if" : "Weather", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Weather"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Weather"], + "tests": [] }, { "if": "Videos", "type": "command", - "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.Totem"] + "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.Totem"], + "tests": [] }, { "if" : "Web", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Epiphany"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Epiphany"], + "tests": [] }, { "if" : "LibreOffice", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.libreoffice.LibreOffice"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.libreoffice.LibreOffice"], + "tests": [] }, { "if" : "Bottles", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y com.usebottles.bottles"] + "commands" : ["!nextBoot !noRoot flatpak install -y com.usebottles.bottles"], + "tests": [] }, { "if" : "Heroic Games Launcher", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y com.heroicgameslauncher.hgl"] + "commands" : ["!nextBoot !noRoot flatpak install -y com.heroicgameslauncher.hgl"], + "tests": [] }, { "if" : "Lutris", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y net.lutris.Lutris"] + "commands" : ["!nextBoot !noRoot flatpak install -y net.lutris.Lutris"], + "tests": [] }, { "if" : "Boxes", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Boxes"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Boxes"], + "tests": [] }, { "if" : "Déjà Dup Backups", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.DejaDup"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.DejaDup"], + "tests": [] }, { "if" : "Flatseal", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y com.github.tchx84.Flatseal"] + "commands" : ["!nextBoot !noRoot flatpak install -y com.github.tchx84.Flatseal"], + "tests": [] }, { "if" : "Metadata Cleaner", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y fr.romainvigier.MetadataCleaner"] + "commands" : ["!nextBoot !noRoot flatpak install -y fr.romainvigier.MetadataCleaner"], + "tests": [] }, { "if" : "Rnote", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y com.github.flxzt.rnote"] + "commands" : ["!nextBoot !noRoot flatpak install -y com.github.flxzt.rnote"], + "tests": [] }, { "if" : "Shortwave", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y de.haeckerfelix.Shortwave"] + "commands" : ["!nextBoot !noRoot flatpak install -y de.haeckerfelix.Shortwave"], + "tests": [] }, { "if" : "Sound Recorder", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.SoundRecorder"] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.SoundRecorder"], + "tests": [] } ] }, @@ -487,7 +527,8 @@ { "if": "timeshift", "type": "command", - "commands": ["abroot pkg add timeshift"] + "commands": ["abroot pkg add timeshift"], + "tests": ["timeshift"] } ] }, @@ -514,7 +555,8 @@ { "if": "vm", "type": "command", - "commands": ["abroot pkg add open-vm-tools open-vm-tools-desktop"] + "commands": ["abroot pkg add open-vm-tools open-vm-tools-desktop"], + "tests": ["open-vm-tools", "open-vm-tools-desktop"] } ] }, @@ -538,7 +580,8 @@ { "if": "codecs", "type": "command", - "commands": ["abroot pkg add libavcodec-extra gstreamer1.0-libav gstreamer1.0-plugins-ugly gstreamer1.0-vaapi libavcodec-extra unrar"] + "commands": ["abroot pkg add libavcodec-extra gstreamer1.0-libav gstreamer1.0-plugins-ugly gstreamer1.0-vaapi libavcodec-extra unrar"], + "tests": [] } ] } diff --git a/vanilla_first_setup/defaults/hostname.py b/vanilla_first_setup/defaults/hostname.py index 6a54bcd5..3407e524 100644 --- a/vanilla_first_setup/defaults/hostname.py +++ b/vanilla_first_setup/defaults/hostname.py @@ -55,6 +55,7 @@ def get_finals(self): "if": "setHostname", "type": "command", "commands": ["hostnamectl set-hostname " + self.hostname], + "tests": [] } ], } diff --git a/vanilla_first_setup/defaults/theme.py b/vanilla_first_setup/defaults/theme.py index 404c6103..791bf710 100644 --- a/vanilla_first_setup/defaults/theme.py +++ b/vanilla_first_setup/defaults/theme.py @@ -74,5 +74,5 @@ def get_finals(self): return { "vars": {"setTheme": True}, - "funcs": [{"if": "setTheme", "type": "command", "commands": cmds}], + "funcs": [{"if": "setTheme", "type": "command", "commands": cmds, "tests": []}], } diff --git a/vanilla_first_setup/defaults/user.py b/vanilla_first_setup/defaults/user.py index 4c0a832b..c269f932 100644 --- a/vanilla_first_setup/defaults/user.py +++ b/vanilla_first_setup/defaults/user.py @@ -73,6 +73,7 @@ def get_finals(self): f'echo "{self.username}:{self.password_entry.get_text()}" | chpasswd', f"usermod -a -G sudo,adm,lpadmin {self.username}", ], + "tests": [] } ], } diff --git a/vanilla_first_setup/utils/parser.py b/vanilla_first_setup/utils/parser.py index 89fb8157..d9673370 100644 --- a/vanilla_first_setup/utils/parser.py +++ b/vanilla_first_setup/utils/parser.py @@ -29,6 +29,7 @@ def parse(finals): warps = [] all_vars = [] exposed_vars = {} + tests = [] for final in finals: if len(final) == 0: @@ -84,6 +85,8 @@ def parse(finals): for k, v in exposed_vars.items(): cmd = cmd.replace(f"exposed::{k}", v) commands.append(cmd) + for test in _func["tests"]: + tests.append(test) # set-up warps if any for warp in warps: @@ -98,4 +101,4 @@ def parse(finals): if _if in all_vars: commands += _func["commands"] - return commands + return (commands, tests) diff --git a/vanilla_first_setup/utils/processor.py b/vanilla_first_setup/utils/processor.py index 5cbb8deb..393e638e 100644 --- a/vanilla_first_setup/utils/processor.py +++ b/vanilla_first_setup/utils/processor.py @@ -25,7 +25,7 @@ class Processor: @staticmethod - def get_setup_commands(log_path, pre_run, post_run, commands): + def get_setup_commands(log_path, pre_run, post_run, commands, tests): commands = pre_run + commands + post_run out_run = "" next_boot = [] @@ -108,6 +108,14 @@ def get_setup_commands(log_path, pre_run, post_run, commands): f.write(f"echo 'X-GNOME-Autostart-enabled=true' >> {next_boot_autostart_path}\n") # fmt: on + f.write("while ") + for test in tests: + f.write(f"! type {test} >/dev/null 2>&1") + f.write(" || ") + f.write("false\n") + + f.write("do\n") + for command in commands: if command.startswith("!nextBoot"): continue @@ -134,6 +142,8 @@ def get_setup_commands(log_path, pre_run, post_run, commands): # commit changes f.write(f"{abroot_bin} pkg apply\n") + f.write("done\n") + # create the done file f.write("if [ $? -eq 0 ]; then\n") f.write(f"touch {done_file}\n") diff --git a/vanilla_first_setup/window.py b/vanilla_first_setup/window.py index 21db7367..51822ede 100644 --- a/vanilla_first_setup/window.py +++ b/vanilla_first_setup/window.py @@ -167,7 +167,7 @@ def __on_page_changed(self, *args): # this parses the finals to compatible commands, by replacing the # placeholders with the actual values and generating shell commands - commands = Parser.parse(finals) + (commands, tests) = Parser.parse(finals) # process the commands res = Processor.get_setup_commands( @@ -175,6 +175,7 @@ def __on_page_changed(self, *args): self.recipe.get("pre_run", []), self.recipe.get("post_run"), commands, + tests ) self.__view_progress.start(res, Processor.hide_first_setup, self.__user) From 6197fff984224140c6747cc8e2afe511bad37ed2 Mon Sep 17 00:00:00 2001 From: Muhammad Salman Date: Sun, 15 Oct 2023 11:56:30 +0500 Subject: [PATCH 2/8] Remove erroneous tests --- recipe.json | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/recipe.json b/recipe.json index 3298dd9c..c4618ad3 100644 --- a/recipe.json +++ b/recipe.json @@ -94,8 +94,7 @@ "!nextBoot !noRoot flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo" ], "tests": [ - "flatpak", - "gnome-software-plugin-flatpak" + "flatpak" ] }, { @@ -104,9 +103,7 @@ "commands": [ "abroot pkg add fuse3 libfuse3-3" ], - "tests": [ - "fuse3" - ] + "tests": [] } ] }, @@ -556,7 +553,7 @@ "if": "vm", "type": "command", "commands": ["abroot pkg add open-vm-tools open-vm-tools-desktop"], - "tests": ["open-vm-tools", "open-vm-tools-desktop"] + "tests": [] } ] }, From 73400dc9c3a5bb74ab43b19f8aa811ee0fac2f9a Mon Sep 17 00:00:00 2001 From: Muhammad Salman Date: Wed, 18 Oct 2023 17:28:40 +0500 Subject: [PATCH 3/8] Changed the testing system Now it will use a JSON file called tests.json. The tests (and which options have to be selected for those tests) will be stored in that file. The old system did not work for a few reasons: 1. It used commands to verify that the package was installed but most package did not have binary files installed. Instead it now checks for the file being present. 2. It used to check for the commands being present during the same boot that they were installed in. Instead it now checks on the next boot. The tests run when First Setup starts and if it's the next boot the tests run to check if the files installed by the packages are present. If they are, it proceeds with the next boot. if they are not, it run the first boot again (meaning the packages are installed again) --- debian/vanilla-first-setup.install | 1 + vanilla_first_setup/utils/tests.py | 50 ++++++++++++++++++++++++++++++ vanilla_first_setup/window.py | 16 +++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 vanilla_first_setup/utils/tests.py diff --git a/debian/vanilla-first-setup.install b/debian/vanilla-first-setup.install index 057aa5ce..dc3b81d6 100644 --- a/debian/vanilla-first-setup.install +++ b/debian/vanilla-first-setup.install @@ -1,4 +1,5 @@ recipe.json usr/share/org.vanillaos.FirstSetup/ +tests.json usr/share/org.vanillaos.FirstSetup/ __first_setup_reset_session usr/bin/ __first_setup_cleanup usr/bin/ first-setup.txt etc/vanilla/ diff --git a/vanilla_first_setup/utils/tests.py b/vanilla_first_setup/utils/tests.py new file mode 100644 index 00000000..f45183ba --- /dev/null +++ b/vanilla_first_setup/utils/tests.py @@ -0,0 +1,50 @@ +# tests.py +# +# +# 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 json + + +class Tests: + + def __init__(self): + self.__selected_tests = [""] + self.__tests = {} + self.__tests_path = "/usr/share/org.vanillaos.FirstSetup/tests.json" + self.__selected_tests_path = "/home/$REAL_USER/.local/share/selected_tests.json" + + def add_test(self, test): + self.__selected_tests.append(test) + + def test(self): + for i, v in self.__tests["current"]: + if i in self.__selected_tests: + for j in v: + if not os.path.isfile(j): + return False + return True + + def load(self): + with open(self.__tests_path, 'r') as f: + self.__tests = json.load(f) + with open(self.__selected_tests_path, 'r') as f: + self.__selected_tests = json.load(f) + + def write(self): + with open(self.__selected_tests_path, 'w') as f: + json.dump(self.__selected_tests, f) + + def remove(self): + os.remove(self.__selected_tests_path) diff --git a/vanilla_first_setup/window.py b/vanilla_first_setup/window.py index 51822ede..72d09bd5 100644 --- a/vanilla_first_setup/window.py +++ b/vanilla_first_setup/window.py @@ -22,6 +22,7 @@ from vanilla_first_setup.utils.builder import Builder from vanilla_first_setup.utils.parser import Parser from vanilla_first_setup.utils.processor import Processor +from vanilla_first_setup.utils.tests import Tests from vanilla_first_setup.views.progress import VanillaProgress from vanilla_first_setup.views.done import VanillaDone @@ -55,13 +56,26 @@ def __init__(self, post_script: str, user: str, new_user: bool = False, **kwargs # True/False = managed result self.__last_result = None + # Create and run the tests to make sure the previous run installed + # all the packages properly + if self.__init_mode == 1: + self.__tests = Tests() + self.__tests.load() + self.__tests_succeeded = self.__tests.test() + else: + # Set them to false anyway if it's the first boot + self.__tests_succeeded = False + # if a post_script is provided, we are in the post setup # so we can skip the builder and just run the post script # in the Vte terminal - if post_script: + if post_script and self.__tests_succeeded: # set the initialization mode to 1 self.__init_mode = 1 + # delete the tests file + self.__tests.remove() + # system views self.__view_done = VanillaDone( self, From 9240b93511572f63e611e67a6e24651dc0122534 Mon Sep 17 00:00:00 2001 From: Muhammad Salman Date: Wed, 18 Oct 2023 17:43:18 +0500 Subject: [PATCH 4/8] Remove all changes of the first commit Forgot to do that in the last commit --- recipe.json | 111 ++++++++----------------- vanilla_first_setup/defaults/theme.py | 2 +- vanilla_first_setup/defaults/user.py | 3 +- vanilla_first_setup/utils/parser.py | 4 +- vanilla_first_setup/utils/processor.py | 12 +-- vanilla_first_setup/window.py | 5 +- 6 files changed, 42 insertions(+), 95 deletions(-) diff --git a/recipe.json b/recipe.json index c4618ad3..2ad3c631 100644 --- a/recipe.json +++ b/recipe.json @@ -92,9 +92,6 @@ "commands": [ "abroot pkg add flatpak gnome-software-plugin-flatpak", "!nextBoot !noRoot flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo" - ], - "tests": [ - "flatpak" ] }, { @@ -102,8 +99,7 @@ "type": "command", "commands": [ "abroot pkg add fuse3 libfuse3-3" - ], - "tests": [] + ] } ] }, @@ -307,200 +303,167 @@ { "if" : "Calculator", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Calculator"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Calculator"] }, { "if" : "Calendar", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Calendar"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Calendar"] }, { "if" : "Characters", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Characters"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Characters"] }, { "if" : "Clocks", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.clocks"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.clocks"] }, { "if" : "Connections", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Connections"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Connections"] }, { "if" : "Contacts", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Contacts"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Contacts"] }, { "if" : "Disk Usage Analyzer", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.baobab"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.baobab"] }, { "if": "Document Scanner", "type": "command", - "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.SimpleScan"], - "tests": [] + "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.SimpleScan"] }, { "if" : "Document Viewer", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Evince"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Evince"] }, { "if": "Extension Manager", "type": "command", - "commands": ["!nextBoot !noRoot flatpak install -y com.mattjakeman.ExtensionManager"], - "tests": [] + "commands": ["!nextBoot !noRoot flatpak install -y com.mattjakeman.ExtensionManager"] }, { "if" : "File Roller", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.FileRoller"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.FileRoller"] }, { "if" : "Fonts", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.font-viewer"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.font-viewer"] }, { "if" : "Image Viewer", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Loupe"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Loupe"] }, { "if" : "Logs", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Logs"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Logs"] }, { "if" : "Maps", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Maps"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Maps"] }, { "if" : "Music", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Music"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Music"] }, { "if": "Photos", "type": "command", - "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.Photos"], - "tests": [] + "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.Photos"] }, { "if" : "Snapshot", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Snapshot"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Snapshot"] }, { "if" : "Text Editor", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.TextEditor"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.TextEditor"] }, { "if" : "Weather", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Weather"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Weather"] }, { "if": "Videos", "type": "command", - "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.Totem"], - "tests": [] + "commands": ["!nextBoot !noRoot flatpak install -y org.gnome.Totem"] }, { "if" : "Web", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Epiphany"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Epiphany"] }, { "if" : "LibreOffice", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.libreoffice.LibreOffice"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.libreoffice.LibreOffice"] }, { "if" : "Bottles", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y com.usebottles.bottles"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y com.usebottles.bottles"] }, { "if" : "Heroic Games Launcher", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y com.heroicgameslauncher.hgl"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y com.heroicgameslauncher.hgl"] }, { "if" : "Lutris", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y net.lutris.Lutris"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y net.lutris.Lutris"] }, { "if" : "Boxes", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Boxes"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.Boxes"] }, { "if" : "Déjà Dup Backups", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.DejaDup"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.DejaDup"] }, { "if" : "Flatseal", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y com.github.tchx84.Flatseal"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y com.github.tchx84.Flatseal"] }, { "if" : "Metadata Cleaner", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y fr.romainvigier.MetadataCleaner"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y fr.romainvigier.MetadataCleaner"] }, { "if" : "Rnote", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y com.github.flxzt.rnote"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y com.github.flxzt.rnote"] }, { "if" : "Shortwave", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y de.haeckerfelix.Shortwave"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y de.haeckerfelix.Shortwave"] }, { "if" : "Sound Recorder", "type" : "command", - "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.SoundRecorder"], - "tests": [] + "commands" : ["!nextBoot !noRoot flatpak install -y org.gnome.SoundRecorder"] } ] }, @@ -552,8 +515,7 @@ { "if": "vm", "type": "command", - "commands": ["abroot pkg add open-vm-tools open-vm-tools-desktop"], - "tests": [] + "commands": ["abroot pkg add open-vm-tools open-vm-tools-desktop"] } ] }, @@ -577,8 +539,7 @@ { "if": "codecs", "type": "command", - "commands": ["abroot pkg add libavcodec-extra gstreamer1.0-libav gstreamer1.0-plugins-ugly gstreamer1.0-vaapi libavcodec-extra unrar"], - "tests": [] + "commands": ["abroot pkg add libavcodec-extra gstreamer1.0-libav gstreamer1.0-plugins-ugly gstreamer1.0-vaapi libavcodec-extra unrar"] } ] } diff --git a/vanilla_first_setup/defaults/theme.py b/vanilla_first_setup/defaults/theme.py index 791bf710..404c6103 100644 --- a/vanilla_first_setup/defaults/theme.py +++ b/vanilla_first_setup/defaults/theme.py @@ -74,5 +74,5 @@ def get_finals(self): return { "vars": {"setTheme": True}, - "funcs": [{"if": "setTheme", "type": "command", "commands": cmds, "tests": []}], + "funcs": [{"if": "setTheme", "type": "command", "commands": cmds}], } diff --git a/vanilla_first_setup/defaults/user.py b/vanilla_first_setup/defaults/user.py index c269f932..e2b9023a 100644 --- a/vanilla_first_setup/defaults/user.py +++ b/vanilla_first_setup/defaults/user.py @@ -72,8 +72,7 @@ def get_finals(self): f'adduser --quiet --disabled-password --shell /bin/bash --gecos "{self.fullname}" {self.username}', f'echo "{self.username}:{self.password_entry.get_text()}" | chpasswd', f"usermod -a -G sudo,adm,lpadmin {self.username}", - ], - "tests": [] + ] } ], } diff --git a/vanilla_first_setup/utils/parser.py b/vanilla_first_setup/utils/parser.py index d9673370..5bcf67e9 100644 --- a/vanilla_first_setup/utils/parser.py +++ b/vanilla_first_setup/utils/parser.py @@ -85,8 +85,6 @@ def parse(finals): for k, v in exposed_vars.items(): cmd = cmd.replace(f"exposed::{k}", v) commands.append(cmd) - for test in _func["tests"]: - tests.append(test) # set-up warps if any for warp in warps: @@ -101,4 +99,4 @@ def parse(finals): if _if in all_vars: commands += _func["commands"] - return (commands, tests) + return commands diff --git a/vanilla_first_setup/utils/processor.py b/vanilla_first_setup/utils/processor.py index 393e638e..5cbb8deb 100644 --- a/vanilla_first_setup/utils/processor.py +++ b/vanilla_first_setup/utils/processor.py @@ -25,7 +25,7 @@ class Processor: @staticmethod - def get_setup_commands(log_path, pre_run, post_run, commands, tests): + def get_setup_commands(log_path, pre_run, post_run, commands): commands = pre_run + commands + post_run out_run = "" next_boot = [] @@ -108,14 +108,6 @@ def get_setup_commands(log_path, pre_run, post_run, commands, tests): f.write(f"echo 'X-GNOME-Autostart-enabled=true' >> {next_boot_autostart_path}\n") # fmt: on - f.write("while ") - for test in tests: - f.write(f"! type {test} >/dev/null 2>&1") - f.write(" || ") - f.write("false\n") - - f.write("do\n") - for command in commands: if command.startswith("!nextBoot"): continue @@ -142,8 +134,6 @@ def get_setup_commands(log_path, pre_run, post_run, commands, tests): # commit changes f.write(f"{abroot_bin} pkg apply\n") - f.write("done\n") - # create the done file f.write("if [ $? -eq 0 ]; then\n") f.write(f"touch {done_file}\n") diff --git a/vanilla_first_setup/window.py b/vanilla_first_setup/window.py index 72d09bd5..bf277ea0 100644 --- a/vanilla_first_setup/window.py +++ b/vanilla_first_setup/window.py @@ -181,15 +181,14 @@ def __on_page_changed(self, *args): # this parses the finals to compatible commands, by replacing the # placeholders with the actual values and generating shell commands - (commands, tests) = Parser.parse(finals) + commands = Parser.parse(finals) # process the commands res = Processor.get_setup_commands( self.recipe.get("log_file", "/tmp/vanilla_first_setup.log"), self.recipe.get("pre_run", []), self.recipe.get("post_run"), - commands, - tests + commands ) self.__view_progress.start(res, Processor.hide_first_setup, self.__user) From 63831bf82a7bfdfc65ad22827c964e5e8699b98a Mon Sep 17 00:00:00 2001 From: Muhammad Salman Date: Wed, 18 Oct 2023 18:00:01 +0500 Subject: [PATCH 5/8] Add a dialog to explain the last run failed --- vanilla_first_setup/window.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/vanilla_first_setup/window.py b/vanilla_first_setup/window.py index bf277ea0..1d50c985 100644 --- a/vanilla_first_setup/window.py +++ b/vanilla_first_setup/window.py @@ -28,6 +28,8 @@ from vanilla_first_setup.views.done import VanillaDone from vanilla_first_setup.views.post_script import VanillaPostScript +from dialog import VanillaDialog + @Gtk.Template(resource_path="/org/vanillaos/FirstSetup/gtk/window.ui") class VanillaWindow(Adw.ApplicationWindow): @@ -61,15 +63,19 @@ def __init__(self, post_script: str, user: str, new_user: bool = False, **kwargs if self.__init_mode == 1: self.__tests = Tests() self.__tests.load() - self.__tests_succeeded = self.__tests.test() + + # 2 = succeeded + # 1 = did not succeed + # 0 = did not test + self.__tests_succeeded = 2 if self.__tests.test() else 1 + post_script = 0 if self.__tests_succeeded == 1 else 1 else: - # Set them to false anyway if it's the first boot - self.__tests_succeeded = False + self.__tests_succeeded = 0 # if a post_script is provided, we are in the post setup # so we can skip the builder and just run the post script # in the Vte terminal - if post_script and self.__tests_succeeded: + if post_script: # set the initialization mode to 1 self.__init_mode = 1 @@ -109,6 +115,9 @@ def __init__(self, post_script: str, user: str, new_user: bool = False, **kwargs # connect system signals self.__connect_signals() + if self.__tests_succeeded == 1: + dialog = VanillaDialog(self, "Previous setup failed", "The packages you installed in the previous boot of First Setup could not be installed. Therefore, you will have to go through the First Setup again.") + def __build_post_script_ui(self, post_script): self.__view_post_script = VanillaPostScript(self, post_script) From 5208563ac147c9785714fb2f2debc7f353406c59 Mon Sep 17 00:00:00 2001 From: Muhammad Salman Date: Wed, 18 Oct 2023 18:04:14 +0500 Subject: [PATCH 6/8] Add test conditions based on which options have been selected --- tests.json | 9 +++++++++ vanilla_first_setup/utils/parser.py | 5 +++-- vanilla_first_setup/window.py | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests.json diff --git a/tests.json b/tests.json new file mode 100644 index 00000000..656ca698 --- /dev/null +++ b/tests.json @@ -0,0 +1,9 @@ +{ + "current": { + "flatpak": ["/usr/bin/flatpak", "/usr/lib/x86_64-linux-gnu/gnome-software/plugins-20/libgs_plugin_flatpak.so"], + "appimage": ["/bin/fusermount", "/lib/x86_64-linux-gnu/libfuse3.so.3"], + "timeshift": ["/usr/bin/timeshift"], + "vm": ["/usr/bin/vmtoolsd", "/usr/bin/vmware-user"], + "codecs": ["/usr/share/doc/libavcodec-extra/copyright", "/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstlibav.so", "/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgsta52dec.so", "/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstvaapi.so", "/usr/bin/unrar-nonfree"] + } +} diff --git a/vanilla_first_setup/utils/parser.py b/vanilla_first_setup/utils/parser.py index 5bcf67e9..864982e1 100644 --- a/vanilla_first_setup/utils/parser.py +++ b/vanilla_first_setup/utils/parser.py @@ -24,12 +24,11 @@ class Parser: supported_types = ["command"] @staticmethod - def parse(finals): + def parse(finals, tests): commands = [] warps = [] all_vars = [] exposed_vars = {} - tests = [] for final in finals: if len(final) == 0: @@ -86,6 +85,8 @@ def parse(finals): cmd = cmd.replace(f"exposed::{k}", v) commands.append(cmd) + tests.append(_condition) + # set-up warps if any for warp in warps: _vars = warp["vars"] diff --git a/vanilla_first_setup/window.py b/vanilla_first_setup/window.py index 1d50c985..36042873 100644 --- a/vanilla_first_setup/window.py +++ b/vanilla_first_setup/window.py @@ -190,7 +190,7 @@ def __on_page_changed(self, *args): # this parses the finals to compatible commands, by replacing the # placeholders with the actual values and generating shell commands - commands = Parser.parse(finals) + commands = Parser.parse(finals, self.__tests) # process the commands res = Processor.get_setup_commands( @@ -200,6 +200,7 @@ def __on_page_changed(self, *args): commands ) + self.__tests.write() self.__view_progress.start(res, Processor.hide_first_setup, self.__user) def set_installation_result(self, result, terminal): From 03df26e069f5d3b5fd21c113b1a58e54ab87878b Mon Sep 17 00:00:00 2001 From: Muhammad Salman <73386616+muhdsalm@users.noreply.github.com> Date: Thu, 19 Oct 2023 15:56:39 +0500 Subject: [PATCH 7/8] Use os.gentenv for variables Co-authored-by: axtloss --- vanilla_first_setup/utils/tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vanilla_first_setup/utils/tests.py b/vanilla_first_setup/utils/tests.py index f45183ba..eb4382ce 100644 --- a/vanilla_first_setup/utils/tests.py +++ b/vanilla_first_setup/utils/tests.py @@ -24,6 +24,7 @@ def __init__(self): self.__tests = {} self.__tests_path = "/usr/share/org.vanillaos.FirstSetup/tests.json" self.__selected_tests_path = "/home/$REAL_USER/.local/share/selected_tests.json" + self.__selected_tests_path = "/home/{}/.local/share/selected_tests.json".format(os.getenv("REAL_USER")) def add_test(self, test): self.__selected_tests.append(test) From db68ede0ef20eb62b875a1659ca7c1d4f70c9d1c Mon Sep 17 00:00:00 2001 From: Muhammad Salman Date: Thu, 19 Oct 2023 16:02:11 +0500 Subject: [PATCH 8/8] Change the tests succeeded numbers to match exit codes --- vanilla_first_setup/window.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vanilla_first_setup/window.py b/vanilla_first_setup/window.py index 36042873..13370ccd 100644 --- a/vanilla_first_setup/window.py +++ b/vanilla_first_setup/window.py @@ -64,13 +64,13 @@ def __init__(self, post_script: str, user: str, new_user: bool = False, **kwargs self.__tests = Tests() self.__tests.load() - # 2 = succeeded + # 0 = succeeded # 1 = did not succeed - # 0 = did not test - self.__tests_succeeded = 2 if self.__tests.test() else 1 + # -1 = did not test + self.__tests_succeeded = 0 if self.__tests.test() else 1 post_script = 0 if self.__tests_succeeded == 1 else 1 else: - self.__tests_succeeded = 0 + self.__tests_succeeded = -1 # if a post_script is provided, we are in the post setup # so we can skip the builder and just run the post script